X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FPreferencesTest.java;h=7327abc3fda0dd02d76e558e6537838693dcc784;hp=c79e6ee6fd2e62562e4055219c7c7623863d2dbb;hb=c2c32dca6279ad6f9af68cf2cf4870d56e7c2ff9;hpb=3233fad6a7cf276d13286f3ab7b5836fcabcf668
diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
index c79e6ee..7327abc 100644
--- a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
+++ b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java
@@ -1,255 +1,330 @@
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.Matchers.any;
+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.never;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-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 com.google.common.eventbus.EventBus;
-import org.junit.Before;
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 EventBus eventBus = mock(EventBus.class);
- private final Preferences preferences = new Preferences(eventBus, 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 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