From 1a3f2a00bb5180470db1515e646615dff2744e39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 25 Nov 2014 21:33:52 +0100 Subject: [PATCH] Use new method to create test values everywhere. --- .../sone/core/ConfigurationSoneParserTest.java | 10 +++--- .../sone/core/PreferencesLoaderTest.java | 6 ++-- .../database/memory/ConfigurationLoaderTest.java | 41 ++++++++++------------ .../sone/database/memory/MemoryDatabaseTest.java | 8 ++--- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java index e30048b..7bbfae8 100644 --- a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java @@ -88,9 +88,9 @@ public class ConfigurationSoneParserTest { private void setupEmptyProfile() { when(configuration.getStringValue(anyString())).thenReturn( - new TestValue(null)); + TestValue.from(null)); when(configuration.getIntValue(anyString())).thenReturn( - new TestValue(null)); + TestValue.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(value)); + TestValue.from(value)); } private void setupInteger(String nodeName, Integer value) { when(configuration.getIntValue(eq(nodeName))).thenReturn( - new TestValue(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(value)); + TestValue.from(value)); } @Test(expected = InvalidPostFound.class) diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java index 88745df..e12fe93 100644 --- a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java @@ -38,20 +38,20 @@ public class PreferencesLoaderTest { setupIntValue("PositiveTrust", 50); setupIntValue("NegativeTrust", -50); when(configuration.getStringValue("Option/TrustComment")).thenReturn( - new TestValue("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(value)); + TestValue.from(value)); } private void setupBooleanValue(String optionName, boolean value) { when(configuration.getBooleanValue( "Option/" + optionName)).thenReturn( - new TestValue(value)); + TestValue.from(value)); } @Test diff --git a/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java b/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java index 55b66ee..47e26b7 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java @@ -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("Post2")); + .thenReturn(TestValue.from("Post2")); when(configuration.getStringValue("KnownPosts/1/ID")) - .thenReturn(new TestValue("Post1")); + .thenReturn(TestValue.from("Post1")); when(configuration.getStringValue("KnownPosts/2/ID")) - .thenReturn(new TestValue(null)); + .thenReturn(TestValue.from(null)); Set 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("PostReply2")); + .thenReturn(TestValue.from("PostReply2")); when(configuration.getStringValue("KnownReplies/1/ID")) - .thenReturn(new TestValue("PostReply1")); + .thenReturn(TestValue.from("PostReply1")); when(configuration.getStringValue("KnownReplies/2/ID")) - .thenReturn(new TestValue(null)); + .thenReturn(TestValue.from(null)); Set 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("Post2")); + .thenReturn(TestValue.from("Post2")); when(configuration.getStringValue("Bookmarks/Post/1/ID")) - .thenReturn(new TestValue("Post1")); + .thenReturn(TestValue.from("Post1")); when(configuration.getStringValue("Bookmarks/Post/2/ID")) - .thenReturn(new TestValue(null)); + .thenReturn(TestValue.from(null)); Set knownPosts = configurationLoader.loadBookmarkedPosts(); assertThat(knownPosts, containsInAnyOrder("Post1", "Post2")); } @Test public void loaderCanSaveBookmarkedPosts() throws ConfigurationException { - final TestValue post1 = new TestValue(null); - final TestValue post2 = new TestValue(null); - final TestValue post3 = new TestValue(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 originalPosts = - new HashSet(asList("Post1", "Post2")); + final Value post1 = TestValue.from(null); + final Value post2 = TestValue.from(null); + final Value post3 = TestValue.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 originalPosts = new HashSet(asList("Post1", "Post2")); configurationLoader.saveBookmarkedPosts(originalPosts); - HashSet extractedPosts = new HashSet( - asList(post1.getValue(), post2.getValue())); + HashSet extractedPosts = + new HashSet(asList(post1.getValue(), post2.getValue())); assertThat(extractedPosts, containsInAnyOrder("Post1", "Post2")); assertThat(post3.getValue(), nullValue()); } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index f7b07a2..ac23a81 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -278,11 +278,11 @@ public class MemoryDatabaseTest { private void initializeFriends() { when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/0/ID")).thenReturn( - new TestValue("Friend1")); + TestValue.from("Friend1")); when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/1/ID")).thenReturn( - new TestValue("Friend2")); + TestValue.from("Friend2")); when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/2/ID")).thenReturn( - new TestValue(null)); + TestValue.from(null)); } @Test @@ -332,7 +332,7 @@ public class MemoryDatabaseTest { when(configuration.getStringValue(anyString())).thenAnswer(new Answer>() { @Override public Value answer(InvocationOnMock invocation) throws Throwable { - Value stringValue = new TestValue(null); + Value stringValue = TestValue.from(null); configurationValues.put((String) invocation.getArguments()[0], stringValue); return stringValue; } -- 2.7.4