1 package net.pterodactylus.sone.core;
3 import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
4 import static org.hamcrest.MatcherAssert.assertThat;
5 import static org.hamcrest.Matchers.is;
6 import static org.hamcrest.Matchers.not;
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
10 import net.pterodactylus.sone.test.TestValue;
11 import net.pterodactylus.util.config.Configuration;
13 import com.google.common.eventbus.EventBus;
14 import org.junit.Before;
15 import org.junit.Test;
18 * Unit test for {@link PreferencesLoader}.
20 public class PreferencesLoaderTest {
22 private final EventBus eventBus = mock(EventBus.class);
23 private final Preferences preferences = new Preferences(eventBus);
24 private final Configuration configuration = mock(Configuration.class);
25 private final PreferencesLoader preferencesLoader =
26 new PreferencesLoader(preferences);
29 public void setupConfiguration() {
30 setupIntValue("InsertionDelay", 15);
31 setupIntValue("PostsPerPage", 25);
32 setupIntValue("ImagesPerPage", 12);
33 setupIntValue("CharactersPerPost", 150);
34 setupIntValue("PostCutOffLength", 300);
35 setupBooleanValue("RequireFullAccess", true);
36 setupIntValue("PositiveTrust", 50);
37 setupIntValue("NegativeTrust", -50);
38 when(configuration.getStringValue("Option/TrustComment")).thenReturn(
39 TestValue.from("Trusted"));
40 setupBooleanValue("ActivateFcpInterface", true);
41 setupIntValue("FcpFullAccessRequired", 1);
44 private void setupIntValue(String optionName, int value) {
45 when(configuration.getIntValue("Option/" + optionName)).thenReturn(
46 TestValue.from(value));
49 private void setupBooleanValue(String optionName, boolean value) {
50 when(configuration.getBooleanValue(
51 "Option/" + optionName)).thenReturn(
52 TestValue.from(value));
56 public void configurationIsLoadedCorrectly() {
58 preferencesLoader.loadFrom(configuration);
59 assertThat(preferences.getInsertionDelay(), is(15));
60 assertThat(preferences.getPostsPerPage(), is(25));
61 assertThat(preferences.getImagesPerPage(), is(12));
62 assertThat(preferences.getCharactersPerPost(), is(150));
63 assertThat(preferences.getPostCutOffLength(), is(300));
64 assertThat(preferences.getRequireFullAccess(), is(true));
65 assertThat(preferences.getPositiveTrust(), is(50));
66 assertThat(preferences.getNegativeTrust(), is(-50));
67 assertThat(preferences.getTrustComment(), is("Trusted"));
68 assertThat(preferences.getFcpInterfaceActive(), is(true));
69 assertThat(preferences.getFcpFullAccessRequired(), is(WRITING));
73 public void configurationIsLoadedCorrectlyWithCutOffLengthMinusOne() {
75 setupIntValue("PostCutOffLength", -1);
76 preferencesLoader.loadFrom(configuration);
77 assertThat(preferences.getPostCutOffLength(), not(is(-1)));