From a4694502195ee6190d66236386d6813aa0b6f852 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 8 Sep 2014 19:05:07 +0200 Subject: [PATCH 1/1] Move liked post reply IDs to new configuration parser. --- .../pterodactylus/sone/core/ConfigurationSoneParser.java | 13 +++++++++++++ src/main/java/net/pterodactylus/sone/core/Core.java | 10 ++-------- .../sone/core/ConfigurationSoneParserTest.java | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) 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(); -- 2.7.4