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.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 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
22 public class PreferencesLoaderTest {
24 private final EventBus eventBus = mock(EventBus.class);
25 private final Preferences preferences = new Preferences(eventBus);
26 private final Configuration configuration = mock(Configuration.class);
27 private final PreferencesLoader preferencesLoader =
28 new PreferencesLoader(preferences);
31 public void setupConfiguration() {
32 setupIntValue("InsertionDelay", 15);
33 setupIntValue("PostsPerPage", 25);
34 setupIntValue("ImagesPerPage", 12);
35 setupIntValue("CharactersPerPost", 150);
36 setupIntValue("PostCutOffLength", 300);
37 setupBooleanValue("RequireFullAccess", true);
38 setupIntValue("PositiveTrust", 50);
39 setupIntValue("NegativeTrust", -50);
40 when(configuration.getStringValue("Option/TrustComment")).thenReturn(
41 TestValue.from("Trusted"));
42 setupBooleanValue("ActivateFcpInterface", true);
43 setupIntValue("FcpFullAccessRequired", 1);
46 private void setupIntValue(String optionName, int value) {
47 when(configuration.getIntValue("Option/" + optionName)).thenReturn(
48 TestValue.from(value));
51 private void setupBooleanValue(String optionName, boolean value) {
52 when(configuration.getBooleanValue(
53 "Option/" + optionName)).thenReturn(
54 TestValue.from(value));
58 public void configurationIsLoadedCorrectly() {
60 preferencesLoader.loadFrom(configuration);
61 assertThat(preferences.getInsertionDelay(), is(15));
62 assertThat(preferences.getPostsPerPage(), is(25));
63 assertThat(preferences.getImagesPerPage(), is(12));
64 assertThat(preferences.getCharactersPerPost(), is(150));
65 assertThat(preferences.getPostCutOffLength(), is(300));
66 assertThat(preferences.isRequireFullAccess(), is(true));
67 assertThat(preferences.getPositiveTrust(), is(50));
68 assertThat(preferences.getNegativeTrust(), is(-50));
69 assertThat(preferences.getTrustComment(), is("Trusted"));
70 assertThat(preferences.isFcpInterfaceActive(), is(true));
71 assertThat(preferences.getFcpFullAccessRequired(), is(WRITING));
75 public void configurationIsLoadedCorrectlyWithCutOffLengthMinusOne() {
77 setupIntValue("PostCutOffLength", -1);
78 preferencesLoader.loadFrom(configuration);
79 assertThat(preferences.getPostCutOffLength(), not(is(-1)));