return replies;
}
+ public Set<String> parseLikedPostIds() {
+ Set<String> likedPostIds = new HashSet<String>();
+ while (true) {
+ String likedPostId =
+ getString("/Likes/Post/" + likedPostIds.size() + "/ID",
+ null);
+ if (likedPostId == null) {
+ break;
+ }
+ likedPostIds.add(likedPostId);
+ }
+ return likedPostIds;
+ }
+
public static class InvalidPostFound extends RuntimeException { }
public static class InvalidPostReplyFound extends RuntimeException { }
}
/* load post likes. */
- Set<String> likedPostIds = new HashSet<String>();
- while (true) {
- String likedPostId = configuration.getStringValue(sonePrefix + "/Likes/Post/" + likedPostIds.size() + "/ID").getValue(null);
- if (likedPostId == null) {
- break;
- }
- likedPostIds.add(likedPostId);
- }
+ Set<String> likedPostIds =
+ configurationSoneParser.parseLikedPostIds();
/* load reply likes. */
Set<String> likedReplyIds = new HashSet<String>();
import java.util.Collection;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostFound;
setupPostReply("0", "R0", "P0", 1000L, null);
}
+ @Test
+ public void likedPostIdsParsedCorrectly() {
+ setupLikedPostIds();
+ Set<String> likedPostIds =
+ configurationSoneParser.parseLikedPostIds();
+ assertThat(likedPostIds, containsInAnyOrder("P1", "P2", "P3"));
+ }
+
+ private void setupLikedPostIds() {
+ setupString("Sone/1/Likes/Post/0/ID", "P1");
+ setupString("Sone/1/Likes/Post/1/ID", "P2");
+ setupString("Sone/1/Likes/Post/2/ID", "P3");
+ setupString("Sone/1/Likes/Post/3/ID", null);
+ }
+
private static class TestValue<T> implements Value<T> {
private final AtomicReference<T> value = new AtomicReference<T>();