+++ /dev/null
-package net.pterodactylus.sone.core;
-
-import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import net.pterodactylus.sone.test.TestValue;
-import net.pterodactylus.util.config.Configuration;
-
-import com.google.common.eventbus.EventBus;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit test for {@link PreferencesLoader}.
- */
-public class PreferencesLoaderTest {
-
- private final EventBus eventBus = mock(EventBus.class);
- private final Preferences preferences = new Preferences(eventBus);
- private final Configuration configuration = mock(Configuration.class);
- private final PreferencesLoader preferencesLoader =
- new PreferencesLoader(preferences);
-
- @Before
- public void setupConfiguration() {
- setupIntValue("InsertionDelay", 15);
- setupIntValue("PostsPerPage", 25);
- setupIntValue("ImagesPerPage", 12);
- setupIntValue("CharactersPerPost", 150);
- setupIntValue("PostCutOffLength", 300);
- setupBooleanValue("RequireFullAccess", true);
- setupBooleanValue("ActivateFcpInterface", true);
- setupIntValue("FcpFullAccessRequired", 1);
- }
-
- private void setupIntValue(String optionName, int value) {
- when(configuration.getIntValue("Option/" + optionName)).thenReturn(
- TestValue.from(value));
- }
-
- private void setupBooleanValue(String optionName, boolean value) {
- when(configuration.getBooleanValue(
- "Option/" + optionName)).thenReturn(
- TestValue.from(value));
- }
-
- @Test
- public void configurationIsLoadedCorrectly() {
- setupConfiguration();
- preferencesLoader.loadFrom(configuration);
- assertThat(preferences.getInsertionDelay(), is(15));
- assertThat(preferences.getPostsPerPage(), is(25));
- assertThat(preferences.getImagesPerPage(), is(12));
- assertThat(preferences.getCharactersPerPost(), is(150));
- assertThat(preferences.getPostCutOffLength(), is(300));
- assertThat(preferences.getRequireFullAccess(), is(true));
- assertThat(preferences.getFcpInterfaceActive(), is(true));
- assertThat(preferences.getFcpFullAccessRequired(), is(WRITING));
- }
-
- @Test
- public void configurationIsLoadedCorrectlyWithCutOffLengthMinusOne() {
- setupConfiguration();
- setupIntValue("PostCutOffLength", -1);
- preferencesLoader.loadFrom(configuration);
- assertThat(preferences.getPostCutOffLength(), not(is(-1)));
- }
-
-}
--- /dev/null
+package net.pterodactylus.sone.core
+
+import com.google.common.eventbus.*
+import net.pterodactylus.sone.fcp.FcpInterface.*
+import net.pterodactylus.util.config.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+
+/**
+ * Unit test for [PreferencesLoader].
+ */
+class PreferencesLoaderTest {
+
+ @Suppress("UnstableApiUsage")
+ private val eventBus = EventBus()
+ private val preferences = Preferences(eventBus)
+ private val configuration = Configuration(MapConfigurationBackend())
+ private val preferencesLoader = PreferencesLoader(preferences)
+
+ @Before
+ fun setupConfiguration() {
+ setupIntValue("InsertionDelay", 15)
+ setupIntValue("PostsPerPage", 25)
+ setupIntValue("ImagesPerPage", 12)
+ setupIntValue("CharactersPerPost", 150)
+ setupIntValue("PostCutOffLength", 300)
+ setupBooleanValue("RequireFullAccess", true)
+ setupBooleanValue("ActivateFcpInterface", true)
+ setupIntValue("FcpFullAccessRequired", 1)
+ }
+
+ private fun setupIntValue(optionName: String, value: Int) {
+ configuration.getIntValue("Option/$optionName").value = value
+ }
+
+ private fun setupBooleanValue(optionName: String, value: Boolean) {
+ configuration.getBooleanValue("Option/$optionName").value = value
+ }
+
+ @Test
+ fun `configuration is loaded correctly`() {
+ preferencesLoader.loadFrom(configuration)
+ assertThat(preferences.insertionDelay, equalTo(15))
+ assertThat(preferences.postsPerPage, equalTo(25))
+ assertThat(preferences.imagesPerPage, equalTo(12))
+ assertThat(preferences.charactersPerPost, equalTo(150))
+ assertThat(preferences.postCutOffLength, equalTo(300))
+ assertThat(preferences.requireFullAccess, equalTo(true))
+ assertThat(preferences.fcpInterfaceActive, equalTo(true))
+ assertThat(preferences.fcpFullAccessRequired, equalTo(FullAccessRequired.WRITING))
+ }
+
+ @Test
+ fun `configuration is loaded correctly with cut off length minus one`() {
+ setupIntValue("PostCutOffLength", -1)
+ preferencesLoader.loadFrom(configuration)
+ assertThat(preferences.postCutOffLength, not(equalTo(-1)))
+ }
+
+}