From: David ‘Bombe’ Roden Date: Mon, 8 Sep 2014 17:05:07 +0000 (+0200) Subject: Move liked post reply IDs to new configuration parser. X-Git-Tag: 0.9-rc1^2~3^2~140 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a4694502195ee6190d66236386d6813aa0b6f852;p=Sone.git Move liked post reply IDs 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 4f80e08..1491f87 100644 --- a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java @@ -149,6 +149,19 @@ public class ConfigurationSoneParser { return likedPostIds; } + public Set parseLikedPostReplyIds() { + Set likedPostReplyIds = new HashSet(); + while (true) { + String likedReplyId = getString( + "/Likes/Reply/" + likedPostReplyIds.size() + "/ID", null); + if (likedReplyId == null) { + break; + } + likedPostReplyIds.add(likedReplyId); + } + return likedPostReplyIds; + } + 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 5dd1eb6..a6d46c2 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1136,14 +1136,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, configurationSoneParser.parseLikedPostIds(); /* load reply likes. */ - Set likedReplyIds = new HashSet(); - while (true) { - String likedReplyId = configuration.getStringValue(sonePrefix + "/Likes/Reply/" + likedReplyIds.size() + "/ID").getValue(null); - if (likedReplyId == null) { - break; - } - likedReplyIds.add(likedReplyId); - } + Set likedReplyIds = + configurationSoneParser.parseLikedPostReplyIds(); /* load friends. */ Set friends = 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 8ab729b..93253c4 100644 --- a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java @@ -285,6 +285,21 @@ public class ConfigurationSoneParserTest { setupString("Sone/1/Likes/Post/3/ID", null); } + @Test + public void likedPostReplyIdsAreParsedCorrectly() { + setupLikedPostReplyIds(); + Set likedPostReplyIds = + configurationSoneParser.parseLikedPostReplyIds(); + assertThat(likedPostReplyIds, containsInAnyOrder("R1", "R2", "R3")); + } + + private void setupLikedPostReplyIds() { + setupString("Sone/1/Likes/Reply/0/ID", "R1"); + setupString("Sone/1/Likes/Reply/1/ID", "R2"); + setupString("Sone/1/Likes/Reply/2/ID", "R3"); + setupString("Sone/1/Likes/Reply/3/ID", null); + } + private static class TestValue implements Value { private final AtomicReference value = new AtomicReference();