🎨 Replace PreferencesLoaderTest with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Nov 2019 09:47:07 +0000 (10:47 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Nov 2019 17:27:03 +0000 (18:27 +0100)
src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/core/PreferencesLoaderTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java
deleted file mode 100644 (file)
index 72831fc..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-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)));
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/core/PreferencesLoaderTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/PreferencesLoaderTest.kt
new file mode 100644 (file)
index 0000000..0cd7e6d
--- /dev/null
@@ -0,0 +1,61 @@
+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)))
+       }
+
+}