return knownPosts;
}
+ public synchronized Set<String> loadKnownPostReplies() {
+ Set<String> knownPostReplies = new HashSet<String>();
+ int replyCounter = 0;
+ while (true) {
+ String knownReplyId = configuration
+ .getStringValue("KnownReplies/" + replyCounter++ + "/ID")
+ .getValue(null);
+ if (knownReplyId == null) {
+ break;
+ }
+ knownPostReplies.add(knownReplyId);
+ }
+ return knownPostReplies;
+ }
+
}
/** Loads the known post replies. */
private void loadKnownPostReplies() {
+ Set<String> knownPostReplies = configurationLoader.loadKnownPostReplies();
lock.writeLock().lock();
try {
- int replyCounter = 0;
- while (true) {
- String knownReplyId = configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").getValue(null);
- if (knownReplyId == null) {
- break;
- }
- knownPostReplies.add(knownReplyId);
- }
+ this.knownPostReplies.clear();
+ this.knownPostReplies.addAll(knownPostReplies);
} finally {
lock.writeLock().unlock();
}
assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
}
+ @Test
+ public void loaderCanLoadKnownPostReplies() {
+ when(configuration.getStringValue("KnownReplies/0/ID"))
+ .thenReturn(new TestValue<String>("PostReply2"));
+ when(configuration.getStringValue("KnownReplies/1/ID"))
+ .thenReturn(new TestValue<String>("PostReply1"));
+ when(configuration.getStringValue("KnownReplies/2/ID"))
+ .thenReturn(new TestValue<String>(null));
+ Set<String> knownPosts = configurationLoader.loadKnownPostReplies();
+ assertThat(knownPosts,
+ containsInAnyOrder("PostReply1", "PostReply2"));
+ }
+
}