X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FPreferencesTest.java;h=fdae222e90eb296a84db1dc116c3b52d9cda23fc;hp=cd9130deea4a0199fd4a15564d148b5ede20986c;hb=be9b08105333cb78ecef49ffbc4841dd62781bce;hpb=3bd3f8f4ce30c73c8a15817673cec22f36a5f9da
diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
index cd9130d..fdae222 100644
--- a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
+++ b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
@@ -1,228 +1,319 @@
package net.pterodactylus.sone.core;
import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS;
+import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO;
+import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentCaptor.forClass;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import net.pterodactylus.sone.core.Options.Option;
+import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
+import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
+import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
-import org.junit.Before;
+import com.google.common.eventbus.EventBus;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
/**
* Unit test for {@link Preferences}.
- *
- * @author David âBombeâ Roden
*/
public class PreferencesTest {
- private static final int INTEGER_VALUE = 1;
- private static final String STRING_VALUE = "string-value";
- private final Options options = mock(Options.class);
- private final Preferences preferences = new Preferences(options);
- private final Option integerOption = when(mock(Option.class).get()).thenReturn(INTEGER_VALUE).getMock();
- private final Option booleanOption = when(mock(Option.class).get()).thenReturn(true).getMock();
- private final Option stringOption = when(mock(Option.class).get()).thenReturn(STRING_VALUE).getMock();
+ private final EventBus eventBus = mock(EventBus.class);
+ private final Preferences preferences = new Preferences(eventBus);
- @Before
- public void setupOptions() {
- when(integerOption.validate(INTEGER_VALUE)).thenReturn(true);
- when(options.getIntegerOption("InsertionDelay")).thenReturn(integerOption);
- when(options.getIntegerOption("PostsPerPage")).thenReturn(integerOption);
- when(options.getIntegerOption("ImagesPerPage")).thenReturn(integerOption);
- when(options.getIntegerOption("CharactersPerPost")).thenReturn(integerOption);
- when(options.getIntegerOption("PostCutOffLength")).thenReturn(integerOption);
- when(options.getBooleanOption("RequireFullAccess")).thenReturn(booleanOption);
- when(options.getIntegerOption("PositiveTrust")).thenReturn(integerOption);
- when(options.getIntegerOption("NegativeTrust")).thenReturn(integerOption);
- when(options.getStringOption("TrustComment")).thenReturn(stringOption);
- when(options.getBooleanOption("ActivateFcpInterface")).thenReturn(booleanOption);
- when(options.getIntegerOption("FcpFullAccessRequired")).thenReturn(integerOption);
+ @Test
+ public void preferencesRetainInsertionDelay() {
+ preferences.setInsertionDelay(15);
+ assertThat(preferences.getInsertionDelay(), is(15));
}
@Test
- public void testGettingInsertionDelay() {
- assertThat(preferences.getInsertionDelay(), is(INTEGER_VALUE));
- verify(integerOption).get();
+ public void preferencesSendsEventOnSettingInsertionDelay() {
+ preferences.setInsertionDelay(15);
+ ArgumentCaptor