Move friend parsing to new configuration parser.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 8 Sep 2014 17:09:56 +0000 (19:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 8 Sep 2014 17:09:56 +0000 (19:09 +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 1491f87..39dcd12 100644 (file)
@@ -162,6 +162,19 @@ public class ConfigurationSoneParser {
                return likedPostReplyIds;
        }
 
+       public Set<String> parseFriends() {
+               Set<String> friends = new HashSet<String>();
+               while (true) {
+                       String friendId =
+                                       getString("/Friends/" + friends.size() + "/ID", null);
+                       if (friendId == null) {
+                               break;
+                       }
+                       friends.add(friendId);
+               }
+               return friends;
+       }
+
        public static class InvalidPostFound extends RuntimeException { }
 
        public static class InvalidPostReplyFound extends RuntimeException { }
index a6d46c2..2fdd01a 100644 (file)
@@ -1140,14 +1140,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                configurationSoneParser.parseLikedPostReplyIds();
 
                /* load friends. */
-               Set<String> friends = new HashSet<String>();
-               while (true) {
-                       String friendId = configuration.getStringValue(sonePrefix + "/Friends/" + friends.size() + "/ID").getValue(null);
-                       if (friendId == null) {
-                               break;
-                       }
-                       friends.add(friendId);
-               }
+               Set<String> friends = configurationSoneParser.parseFriends();
 
                /* load albums. */
                List<Album> topLevelAlbums = new ArrayList<Album>();
index 93253c4..4aa291b 100644 (file)
@@ -300,6 +300,20 @@ public class ConfigurationSoneParserTest {
                setupString("Sone/1/Likes/Reply/3/ID", null);
        }
 
+       @Test
+       public void friendsAreParsedCorrectly() {
+               setupFriends();
+               Set<String> friends = configurationSoneParser.parseFriends();
+               assertThat(friends, containsInAnyOrder("F1", "F2", "F3"));
+       }
+
+       private void setupFriends() {
+               setupString("Sone/1/Friends/0/ID", "F1");
+               setupString("Sone/1/Friends/1/ID", "F2");
+               setupString("Sone/1/Friends/2/ID", "F3");
+               setupString("Sone/1/Friends/3/ID", null);
+       }
+
        private static class TestValue<T> implements Value<T> {
 
                private final AtomicReference<T> value = new AtomicReference<T>();