예제 #1
0
  @Test
  public void testDestroy() throws Exception {
    final DebugChecker checker = new DebugChecker();
    final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
    checker.addListener(auditAdapter);
    final DebugFilter filter = new DebugFilter();
    checker.addFilter(filter);

    // should remove al listeners and filters
    checker.destroy();

    // Let's try fire some events
    checker.fireAuditStarted();
    checker.fireAuditFinished();
    checker.fireFileStarted("Some File Name");
    checker.fireFileFinished("Some File Name");

    final SortedSet<LocalizedMessage> messages = Sets.newTreeSet();
    messages.add(
        new LocalizedMessage(
            0, 0, "a Bundle", "message.key", new Object[] {"arg"}, null, getClass(), null));
    checker.fireErrors("Some File Name", messages);

    assertFalse("Checker.destroy() doesn't remove listeners.", auditAdapter.wasCalled());
    assertFalse("Checker.destroy() doesn't remove filters.", filter.wasCalled());
  }
예제 #2
0
  @Test
  public void testAddFilter() throws Exception {
    final DebugChecker checker = new DebugChecker();
    final DebugFilter filter = new DebugFilter();

    checker.addFilter(filter);

    filter.resetFilter();
    final SortedSet<LocalizedMessage> messages = Sets.newTreeSet();
    messages.add(
        new LocalizedMessage(
            0, 0, "a Bundle", "message.key", new Object[] {"arg"}, null, getClass(), null));
    checker.fireErrors("Some File Name", messages);
    assertTrue("Checker.fireErrors() doesn't call filter", filter.wasCalled());
  }
예제 #3
0
  @Test
  public void testRemoveListener() throws Exception {
    final DebugChecker checker = new DebugChecker();
    final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
    final DebugAuditAdapter aa2 = new DebugAuditAdapter();
    checker.addListener(auditAdapter);
    checker.addListener(aa2);
    checker.removeListener(auditAdapter);

    // Let's try fire some events
    checker.fireAuditStarted();
    assertTrue("Checker.fireAuditStarted() doesn't call listener", aa2.wasCalled());
    assertFalse("Checker.fireAuditStarted() does call removed listener", auditAdapter.wasCalled());

    aa2.resetListener();
    checker.fireAuditFinished();
    assertTrue("Checker.fireAuditFinished() doesn't call listener", aa2.wasCalled());
    assertFalse("Checker.fireAuditFinished() does call removed listener", auditAdapter.wasCalled());

    aa2.resetListener();
    checker.fireFileStarted("Some File Name");
    assertTrue("Checker.fireFileStarted() doesn't call listener", aa2.wasCalled());
    assertFalse("Checker.fireFileStarted() does call removed listener", auditAdapter.wasCalled());

    aa2.resetListener();
    checker.fireFileFinished("Some File Name");
    assertTrue("Checker.fireFileFinished() doesn't call listener", aa2.wasCalled());
    assertFalse("Checker.fireFileFinished() does call removed listener", auditAdapter.wasCalled());

    aa2.resetListener();
    final SortedSet<LocalizedMessage> messages = Sets.newTreeSet();
    messages.add(
        new LocalizedMessage(
            0, 0, "a Bundle", "message.key", new Object[] {"arg"}, null, getClass(), null));
    checker.fireErrors("Some File Name", messages);
    assertTrue("Checker.fireErrors() doesn't call listener", aa2.wasCalled());
    assertFalse("Checker.fireErrors() does call removed listener", auditAdapter.wasCalled());
  }