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

    blogEntry.addComment(comment);
    comment.setPending();
    service.putBlogEntry(blogEntry);

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

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

          public void commentApproved(CommentEvent event) {
            assertEquals(comment, event.getSource());
            buf.reverse();
          }

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

    blog.getEventListenerList().addCommentListener(listener);
    comment.setApproved();
    service.putBlogEntry(blogEntry);
    assertEquals("321", buf.toString());
  }