From: David ‘Bombe’ Roden Date: Mon, 8 Sep 2014 17:09:56 +0000 (+0200) Subject: Move friend parsing to new configuration parser. X-Git-Tag: 0.9-rc1^2~3^2~139 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=62bb6456a7c2667dec2f8b7b88db465eb6c07257;p=Sone.git Move friend 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 1491f87..39dcd12 100644 --- a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java @@ -162,6 +162,19 @@ public class ConfigurationSoneParser { return likedPostReplyIds; } + public Set parseFriends() { + Set friends = new HashSet(); + 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 { } diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index a6d46c2..2fdd01a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1140,14 +1140,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, configurationSoneParser.parseLikedPostReplyIds(); /* load friends. */ - Set friends = new HashSet(); - while (true) { - String friendId = configuration.getStringValue(sonePrefix + "/Friends/" + friends.size() + "/ID").getValue(null); - if (friendId == null) { - break; - } - friends.add(friendId); - } + Set friends = configurationSoneParser.parseFriends(); /* load albums. */ List topLevelAlbums = new ArrayList(); diff --git a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java index 93253c4..4aa291b 100644 --- a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java @@ -300,6 +300,20 @@ public class ConfigurationSoneParserTest { setupString("Sone/1/Likes/Reply/3/ID", null); } + @Test + public void friendsAreParsedCorrectly() { + setupFriends(); + Set 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 implements Value { private final AtomicReference value = new AtomicReference();