Move liked post reply IDs to new configuration parser.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 8 Sep 2014 17:05:07 +0000 (19:05 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 8 Sep 2014 17:05:27 +0000 (19:05 +0200)
src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java
src/main/java/net/pterodactylus/sone/core/Core.java
src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java

index 4f80e08..1491f87 100644 (file)
@@ -149,6 +149,19 @@ public class ConfigurationSoneParser {
                return likedPostIds;
        }
 
+       public Set<String> parseLikedPostReplyIds() {
+               Set<String> likedPostReplyIds = new HashSet<String>();
+               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 { }
index 5dd1eb6..a6d46c2 100644 (file)
@@ -1136,14 +1136,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                configurationSoneParser.parseLikedPostIds();
 
                /* load reply likes. */
-               Set<String> likedReplyIds = new HashSet<String>();
-               while (true) {
-                       String likedReplyId = configuration.getStringValue(sonePrefix + "/Likes/Reply/" + likedReplyIds.size() + "/ID").getValue(null);
-                       if (likedReplyId == null) {
-                               break;
-                       }
-                       likedReplyIds.add(likedReplyId);
-               }
+               Set<String> likedReplyIds =
+                               configurationSoneParser.parseLikedPostReplyIds();
 
                /* load friends. */
                Set<String> friends = new HashSet<String>();
index 8ab729b..93253c4 100644 (file)
@@ -285,6 +285,21 @@ public class ConfigurationSoneParserTest {
                setupString("Sone/1/Likes/Post/3/ID", null);
        }
 
+       @Test
+       public void likedPostReplyIdsAreParsedCorrectly() {
+               setupLikedPostReplyIds();
+               Set<String> 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<T> implements Value<T> {
 
                private final AtomicReference<T> value = new AtomicReference<T>();