Example #1
0
  /** Tests that listeners are fired when a comment is added. */
  public void testListenersFiredWhenCommentAdded() throws Exception {
    final StringBuffer buf = new StringBuffer("123");
    final Comment comment =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");

    CommentListener listener =
        new CommentListener() {
          public void commentAdded(CommentEvent event) {
            assertEquals(comment, event.getSource());
            buf.reverse();
          }

          public void commentRemoved(CommentEvent event) {
            fail();
          }

          public void commentApproved(CommentEvent event) {
            fail();
          }

          public void commentRejected(CommentEvent event) {
            fail();
          }
        };

    blog.getEventListenerList().addCommentListener(listener);
    service.putBlogEntry(blogEntry);
    blogEntry.addComment(comment);
    service.putBlogEntry(blogEntry);
    assertEquals("321", buf.toString());
  }
Example #2
0
  /** Tests that comment listeners are fired when a blog entry is removed. */
  public void testListenersFiredForCommentsWhenBlogEntryRemoved() throws Exception {
    final Comment comment1 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    final Comment comment2 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    final Comment comment3 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");

    blogEntry.addComment(comment1);
    blogEntry.addComment(comment2);
    service.putBlogEntry(blogEntry);

    comment3.setParent(comment2);
    blogEntry.addComment(comment3);
    service.putBlogEntry(blogEntry);

    final List comments = new ArrayList();

    CommentListener listener =
        new CommentListener() {
          public void commentAdded(CommentEvent event) {
            fail();
          }

          public void commentRemoved(CommentEvent event) {
            comments.add(event.getSource());
          }

          public void commentApproved(CommentEvent event) {
            fail();
          }

          public void commentRejected(CommentEvent event) {
            fail();
          }
        };

    blog.getEventListenerList().addCommentListener(listener);
    service.removeBlogEntry(blogEntry);

    assertEquals(comment1, comments.get(0));
    assertEquals(comment2, comments.get(1));
    assertEquals(comment3, comments.get(2));
  }