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 setupBooleanValue("ActivateFcpInterface", true);
37 setupIntValue("FcpFullAccessRequired", 1);
40 private void setupIntValue(String optionName, int value) {
41 when(configuration.getIntValue("Option/" + optionName)).thenReturn(
42 TestValue.from(value));
45 private void setupBooleanValue(String optionName, boolean value) {
46 when(configuration.getBooleanValue(
47 "Option/" + optionName)).thenReturn(
48 TestValue.from(value));
52 public void configurationIsLoadedCorrectly() {
54 preferencesLoader.loadFrom(configuration);
55 assertThat(preferences.getInsertionDelay(), is(15));
56 assertThat(preferences.getPostsPerPage(), is(25));
57 assertThat(preferences.getImagesPerPage(), is(12));
58 assertThat(preferences.getCharactersPerPost(), is(150));
59 assertThat(preferences.getPostCutOffLength(), is(300));
60 assertThat(preferences.getRequireFullAccess(), is(true));
61 assertThat(preferences.getFcpInterfaceActive(), is(true));
62 assertThat(preferences.getFcpFullAccessRequired(), is(WRITING));
66 public void configurationIsLoadedCorrectlyWithCutOffLengthMinusOne() {
68 setupIntValue("PostCutOffLength", -1);
69 preferencesLoader.loadFrom(configuration);
70 assertThat(preferences.getPostCutOffLength(), not(is(-1)));