Use new method to create test values everywhere.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 25 Nov 2014 20:33:52 +0000 (21:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 25 Nov 2014 20:39:46 +0000 (21:39 +0100)
src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java
src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java
src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

index e30048b..7bbfae8 100644 (file)
@@ -88,9 +88,9 @@ public class ConfigurationSoneParserTest {
 
        private void setupEmptyProfile() {
                when(configuration.getStringValue(anyString())).thenReturn(
-                               new TestValue<String>(null));
+                               TestValue.<String>from(null));
                when(configuration.getIntValue(anyString())).thenReturn(
-                               new TestValue<Integer>(null));
+                               TestValue.<Integer>from(null));
        }
 
        @Test
@@ -128,12 +128,12 @@ public class ConfigurationSoneParserTest {
 
        private void setupString(String nodeName, String value) {
                when(configuration.getStringValue(eq(nodeName))).thenReturn(
-                               new TestValue<String>(value));
+                               TestValue.from(value));
        }
 
        private void setupInteger(String nodeName, Integer value) {
                when(configuration.getIntValue(eq(nodeName))).thenReturn(
-                               new TestValue<Integer>(value));
+                               TestValue.from(value));
        }
 
        @Test
@@ -180,7 +180,7 @@ public class ConfigurationSoneParserTest {
 
        private void setupLong(String nodeName, Long value) {
                when(configuration.getLongValue(eq(nodeName))).thenReturn(
-                               new TestValue<Long>(value));
+                               TestValue.from(value));
        }
 
        @Test(expected = InvalidPostFound.class)
index 88745df..e12fe93 100644 (file)
@@ -38,20 +38,20 @@ public class PreferencesLoaderTest {
                setupIntValue("PositiveTrust", 50);
                setupIntValue("NegativeTrust", -50);
                when(configuration.getStringValue("Option/TrustComment")).thenReturn(
-                               new TestValue<String>("Trusted"));
+                               TestValue.from("Trusted"));
                setupBooleanValue("ActivateFcpInterface", true);
                setupIntValue("FcpFullAccessRequired", 1);
        }
 
        private void setupIntValue(String optionName, int value) {
                when(configuration.getIntValue("Option/" + optionName)).thenReturn(
-                               new TestValue<Integer>(value));
+                               TestValue.from(value));
        }
 
        private void setupBooleanValue(String optionName, boolean value) {
                when(configuration.getBooleanValue(
                                "Option/" + optionName)).thenReturn(
-                               new TestValue<Boolean>(value));
+                               TestValue.from(value));
        }
 
        @Test
index 55b66ee..47e26b7 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Set;
 import net.pterodactylus.sone.TestValue;
 import net.pterodactylus.util.config.Configuration;
 import net.pterodactylus.util.config.ConfigurationException;
+import net.pterodactylus.util.config.Value;
 
 import org.junit.Test;
 
@@ -30,11 +31,11 @@ public class ConfigurationLoaderTest {
        @Test
        public void loaderCanLoadKnownPosts() {
                when(configuration.getStringValue("KnownPosts/0/ID"))
-                               .thenReturn(new TestValue<String>("Post2"));
+                               .thenReturn(TestValue.from("Post2"));
                when(configuration.getStringValue("KnownPosts/1/ID"))
-                               .thenReturn(new TestValue<String>("Post1"));
+                               .thenReturn(TestValue.from("Post1"));
                when(configuration.getStringValue("KnownPosts/2/ID"))
-                               .thenReturn(new TestValue<String>(null));
+                               .thenReturn(TestValue.<String>from(null));
                Set<String> knownPosts = configurationLoader.loadKnownPosts();
                assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
        }
@@ -42,11 +43,11 @@ public class ConfigurationLoaderTest {
        @Test
        public void loaderCanLoadKnownPostReplies() {
                when(configuration.getStringValue("KnownReplies/0/ID"))
-                               .thenReturn(new TestValue<String>("PostReply2"));
+                               .thenReturn(TestValue.from("PostReply2"));
                when(configuration.getStringValue("KnownReplies/1/ID"))
-                               .thenReturn(new TestValue<String>("PostReply1"));
+                               .thenReturn(TestValue.from("PostReply1"));
                when(configuration.getStringValue("KnownReplies/2/ID"))
-                               .thenReturn(new TestValue<String>(null));
+                               .thenReturn(TestValue.<String>from(null));
                Set<String> knownPosts = configurationLoader.loadKnownPostReplies();
                assertThat(knownPosts,
                                containsInAnyOrder("PostReply1", "PostReply2"));
@@ -55,31 +56,27 @@ public class ConfigurationLoaderTest {
        @Test
        public void loaderCanLoadBookmarkedPosts() {
                when(configuration.getStringValue("Bookmarks/Post/0/ID"))
-                               .thenReturn(new TestValue<String>("Post2"));
+                               .thenReturn(TestValue.from("Post2"));
                when(configuration.getStringValue("Bookmarks/Post/1/ID"))
-                               .thenReturn(new TestValue<String>("Post1"));
+                               .thenReturn(TestValue.from("Post1"));
                when(configuration.getStringValue("Bookmarks/Post/2/ID"))
-                               .thenReturn(new TestValue<String>(null));
+                               .thenReturn(TestValue.<String>from(null));
                Set<String> knownPosts = configurationLoader.loadBookmarkedPosts();
                assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
        }
 
        @Test
        public void loaderCanSaveBookmarkedPosts() throws ConfigurationException {
-               final TestValue<String> post1 = new TestValue<String>(null);
-               final TestValue<String> post2 = new TestValue<String>(null);
-               final TestValue<String> post3 = new TestValue<String>(null);
-               when(configuration.getStringValue("Bookmarks/Post/0/ID"))
-                               .thenReturn(post1);
-               when(configuration.getStringValue("Bookmarks/Post/1/ID"))
-                               .thenReturn(post2);
-               when(configuration.getStringValue("Bookmarks/Post/2/ID"))
-                               .thenReturn(post3);
-               HashSet<String> originalPosts =
-                               new HashSet<String>(asList("Post1", "Post2"));
+               final Value<String> post1 = TestValue.<String>from(null);
+               final Value<String> post2 = TestValue.<String>from(null);
+               final Value<String> post3 = TestValue.<String>from(null);
+               when(configuration.getStringValue("Bookmarks/Post/0/ID")).thenReturn(post1);
+               when(configuration.getStringValue("Bookmarks/Post/1/ID")).thenReturn(post2);
+               when(configuration.getStringValue("Bookmarks/Post/2/ID")).thenReturn(post3);
+               HashSet<String> originalPosts = new HashSet<String>(asList("Post1", "Post2"));
                configurationLoader.saveBookmarkedPosts(originalPosts);
-               HashSet<String> extractedPosts = new HashSet<String>(
-                               asList(post1.getValue(), post2.getValue()));
+               HashSet<String> extractedPosts =
+                               new HashSet<String>(asList(post1.getValue(), post2.getValue()));
                assertThat(extractedPosts, containsInAnyOrder("Post1", "Post2"));
                assertThat(post3.getValue(), nullValue());
        }
index f7b07a2..ac23a81 100644 (file)
@@ -278,11 +278,11 @@ public class MemoryDatabaseTest {
 
        private void initializeFriends() {
                when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/0/ID")).thenReturn(
-                               new TestValue<String>("Friend1"));
+                               TestValue.from("Friend1"));
                when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/1/ID")).thenReturn(
-                               new TestValue<String>("Friend2"));
+                               TestValue.from("Friend2"));
                when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/2/ID")).thenReturn(
-                               new TestValue<String>(null));
+                               TestValue.<String>from(null));
        }
 
        @Test
@@ -332,7 +332,7 @@ public class MemoryDatabaseTest {
                when(configuration.getStringValue(anyString())).thenAnswer(new Answer<Value<String>>() {
                        @Override
                        public Value<String> answer(InvocationOnMock invocation) throws Throwable {
-                               Value<String> stringValue = new TestValue(null);
+                               Value<String> stringValue = TestValue.from(null);
                                configurationValues.put((String) invocation.getArguments()[0], stringValue);
                                return stringValue;
                        }