void apply(ConversationBlip blip) { if (!p.apply(blip)) { throw Exit.INSTANCE; } for (ConversationThread thread : blip.getReplyThreads()) { apply(thread); } } }
/** * Convenience function that returns all reply threads to a blip as a List. */ protected static List<ConversationThread> getAllReplyList(ConversationBlip blip) { return CollectionUtils.newArrayList(blip.getReplyThreads()); }
/** * Convenience function that returns all reply threads to a blip as a List. */ protected static List<ConversationThread> getAllReplyList(ConversationBlip blip) { return CollectionUtils.newArrayList(blip.getReplyThreads()); }
@Override public String render(ConversationBlip blip, String document, IdentityMap<ConversationThread, String> anchors, IdentityMap<Conversation, String> nestedReplies) { StringBuilder r = new StringBuilder("Blip ["); r.append(" id: " + blip.getId()); r.append("; content: " + document); r.append("; anchors: ["); for (ConversationThread reply : blip.getReplyThreads()) { r.append(" "); r.append(anchors.get(reply)); } r.append(" ]"); return r.toString(); }
@Override public String render(ConversationBlip blip, String document, IdentityMap<ConversationThread, String> anchors, IdentityMap<Conversation, String> nestedReplies) { StringBuilder r = new StringBuilder("Blip ["); r.append(" id: " + blip.getId()); r.append("; content: " + document); r.append("; anchors: ["); for (ConversationThread reply : blip.getReplyThreads()) { r.append(" "); r.append(anchors.get(reply)); } r.append(" ]"); return r.toString(); }
/** * Checks that the set of all reply threads of a blip is the same as the union * of the inline reply and non-inline reply threads. */ private static void assertThreadChildrenConsistent(ConversationBlip blip) { Set<ConversationThread> allChildren = new HashSet<ConversationThread>(); for (ConversationThread thread : blip.getReplyThreads()) { assertFalse(allChildren.contains(thread)); allChildren.add(thread); } for (ConversationThread child : blip.getReplyThreads()) { assertTrue(allChildren.contains(child)); allChildren.remove(child); } // make sure they are exactly equals assertEquals(0, allChildren.size()); }
/** * Checks that the set of all reply threads of a blip is the same as the union * of the inline reply and non-inline reply threads. */ private static void assertThreadChildrenConsistent(ConversationBlip blip) { Set<ConversationThread> allChildren = new HashSet<ConversationThread>(); for (ConversationThread thread : blip.getReplyThreads()) { assertFalse(allChildren.contains(thread)); allChildren.add(thread); } for (ConversationThread child : blip.getReplyThreads()) { assertTrue(allChildren.contains(child)); allChildren.remove(child); } // make sure they are exactly equals assertEquals(0, allChildren.size()); }
public void testDeleteEmptyThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); replyThread.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertThreadInvalid(replyThread); }
public void testDeleteEmptyThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); replyThread.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertThreadInvalid(replyThread); }
public void testDeleteLastBlipInNonRootThreadDeletesThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); ConversationBlip replyBlip = replyThread.appendBlip(); replyBlip.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertThreadInvalid(replyThread); }
public void testDeleteLastBlipInNonRootThreadDeletesThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); ConversationBlip replyBlip = replyThread.appendBlip(); replyBlip.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertThreadInvalid(replyThread); }
public void testDeleteNonRootThreadRemovesAllBlipsAndThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); ConversationBlip replyBlip1 = replyThread.appendBlip(); ConversationBlip replyBlip2 = replyThread.appendBlip(); replyThread.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertBlipInvalid(replyBlip1); assertBlipInvalid(replyBlip2); assertThreadInvalid(replyThread); }
public void testDeleteNonRootThreadRemovesAllBlipsAndThread() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread replyThread = blip.addReplyThread(); ConversationBlip replyBlip1 = replyThread.appendBlip(); ConversationBlip replyBlip2 = replyThread.appendBlip(); replyThread.delete(); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertThreadChildrenConsistent(blip); assertBlipInvalid(replyBlip1); assertBlipInvalid(replyBlip2); assertThreadInvalid(replyThread); }
/** * Asserts that the state-querying methods on a blip can be called. */ protected static void assertBlipAccessible(ConversationBlip blip) { blip.getReplyThreads(); blip.getAuthorId(); blip.getContent(); blip.getContributorIds(); blip.getConversation(); blip.getId(); blip.locateReplyThreads(); blip.getLastModifiedTime(); blip.getLastModifiedVersion(); blip.getReplyThreads(); blip.getThread(); blip.hackGetRaw(); blip.isRoot(); }
/** * Tests that methods which access the state of a thread without changing it * are correct after thread deletion. */ public void testThreadCanBeAccessedAfterDeletion() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread thread = blip.addReplyThread(); ConversationBlip replyBlip = thread.appendBlip(); thread.delete(); assertBlipInvalid(replyBlip); assertBlipAccessible(replyBlip); assertThreadInvalid(thread); assertThreadAccessible(thread); assertEquals(blip, thread.getParentBlip()); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertEquals(thread, replyBlip.getThread()); assertEquals(Collections.emptyList(), getBlipList(thread)); }
/** * Tests that methods which access the state of a thread without changing it * are correct after thread deletion. */ public void testThreadCanBeAccessedAfterDeletion() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread thread = blip.addReplyThread(); ConversationBlip replyBlip = thread.appendBlip(); thread.delete(); assertBlipInvalid(replyBlip); assertBlipAccessible(replyBlip); assertThreadInvalid(thread); assertThreadAccessible(thread); assertEquals(blip, thread.getParentBlip()); assertFalse(blip.getReplyThreads().iterator().hasNext()); assertEquals(thread, replyBlip.getThread()); assertEquals(Collections.emptyList(), getBlipList(thread)); }
public void testAppendRepliesAppendsRepliesToBlip() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread t1 = blip.addReplyThread(); // Append blips to get a new ID for the next thread. t1.appendBlip(); ConversationThread t2 = blip.addReplyThread(); t2.appendBlip(); ConversationThread t3 = blip.addReplyThread(); t3.appendBlip(); assertSame(blip, t1.getParentBlip()); assertEquals(Arrays.asList(t1, t2, t3), CollectionUtils.newArrayList(blip.getReplyThreads())); assertThreadChildrenConsistent(blip); }
public void testAppendRepliesAppendsRepliesToBlip() { ConversationBlip blip = target.getRootThread().appendBlip(); ConversationThread t1 = blip.addReplyThread(); // Append blips to get a new ID for the next thread. t1.appendBlip(); ConversationThread t2 = blip.addReplyThread(); t2.appendBlip(); ConversationThread t3 = blip.addReplyThread(); t3.appendBlip(); assertSame(blip, t1.getParentBlip()); assertEquals(Arrays.asList(t1, t2, t3), CollectionUtils.newArrayList(blip.getReplyThreads())); assertThreadChildrenConsistent(blip); }
public void testCanReplyAfterDeletingReplyThread() { ConversationThread topThread = target.getRootThread().appendBlip().addReplyThread(); ConversationBlip topBlip = topThread.appendBlip(); // Add two reply threads. Delete the second (by deleting its blip). ConversationThread firstReply = topBlip.addReplyThread(); firstReply.appendBlip(); ConversationThread secondReply = topBlip.addReplyThread(); secondReply.appendBlip().delete(); // Reply again. This used to throw IndexOutOfBounds. ConversationThread replacementReply = topBlip.addReplyThread(); ConversationBlip replacementBlip = replacementReply.appendBlip(); assertBlipValid(replacementBlip); assertEquals(Arrays.asList(firstReply, replacementReply), CollectionUtils.newArrayList(topBlip.getReplyThreads())); }
public void testCanReplyAfterDeletingReplyThread() { ConversationThread topThread = target.getRootThread().appendBlip().addReplyThread(); ConversationBlip topBlip = topThread.appendBlip(); // Add two reply threads. Delete the second (by deleting its blip). ConversationThread firstReply = topBlip.addReplyThread(); firstReply.appendBlip(); ConversationThread secondReply = topBlip.addReplyThread(); secondReply.appendBlip().delete(); // Reply again. This used to throw IndexOutOfBounds. ConversationThread replacementReply = topBlip.addReplyThread(); ConversationBlip replacementBlip = replacementReply.appendBlip(); assertBlipValid(replacementBlip); assertEquals(Arrays.asList(firstReply, replacementReply), CollectionUtils.newArrayList(topBlip.getReplyThreads())); }