From: David ‘Bombe’ Roden Date: Mon, 8 Sep 2014 16:59:31 +0000 (+0200) Subject: Move liked post IDs parsing to new configuration parser. X-Git-Tag: 0.9-rc1^2~3^2~142 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8d257d649b372ca1a240a8e26ce33205c7019d0d;p=Sone.git Move liked post IDs parsing to new configuration parser. --- diff --git a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java index 01d3221..3cb3b68 100644 --- a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java @@ -136,6 +136,20 @@ public class ConfigurationSoneParser { return replies; } + public Set parseLikedPostIds() { + Set likedPostIds = new HashSet(); + while (true) { + String likedPostId = + getString("/Likes/Post/" + likedPostIds.size() + "/ID", + null); + if (likedPostId == null) { + break; + } + likedPostIds.add(likedPostId); + } + return likedPostIds; + } + public static class InvalidPostFound extends RuntimeException { } public static class InvalidPostReplyFound extends RuntimeException { } diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 1541066..5dd1eb6 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1132,14 +1132,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } /* load post likes. */ - Set likedPostIds = new HashSet(); - while (true) { - String likedPostId = configuration.getStringValue(sonePrefix + "/Likes/Post/" + likedPostIds.size() + "/ID").getValue(null); - if (likedPostId == null) { - break; - } - likedPostIds.add(likedPostId); - } + Set likedPostIds = + configurationSoneParser.parseLikedPostIds(); /* load reply likes. */ Set likedReplyIds = new HashSet(); diff --git a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java index 4e9e863..8ab729b 100644 --- a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostFound; @@ -269,6 +270,21 @@ public class ConfigurationSoneParserTest { setupPostReply("0", "R0", "P0", 1000L, null); } + @Test + public void likedPostIdsParsedCorrectly() { + setupLikedPostIds(); + Set likedPostIds = + configurationSoneParser.parseLikedPostIds(); + assertThat(likedPostIds, containsInAnyOrder("P1", "P2", "P3")); + } + + private void setupLikedPostIds() { + setupString("Sone/1/Likes/Post/0/ID", "P1"); + setupString("Sone/1/Likes/Post/1/ID", "P2"); + setupString("Sone/1/Likes/Post/2/ID", "P3"); + setupString("Sone/1/Likes/Post/3/ID", null); + } + private static class TestValue implements Value { private final AtomicReference value = new AtomicReference();