ExceptionWitness { public final void clearException() { if (isExceptionState.compareAndSet(true, false)) { this.eventBus.post(new ExceptionClearedEvent(origin)); } } @Inject  ExceptionWitness(final EventBus eventBus, @Assisted final Object origin); final void flagException(final Exception exception, @Nullable final String message); final void flagException(Exception exception); final void flagWarning(final String warningMessage); final void clearException(); final boolean isException();  }
@Test public void testClearNoErrorCallCount() { errorWitness.clearException(); assertEquals("No error was posted but clear fired a clear event", 0, testWitnessListener .clearRunCount); }
@Test public void testErrorThenClearCallCount() { fireAnError(); errorWitness.clearException(); assertTrue("The cleared witness observer was not present", testWitnessListener .clearedWitnessObserver.isPresent()); assertEquals("The cleared run count was not 1", 1, testWitnessListener.clearRunCount); assertEquals("Witness observer was not the same as the observer from the cleared event", witnessObserver, testWitnessListener.clearedWitnessObserver.get()); }
@Test public void testErrorThenClearMultipleCallCount() { fireAnError(); for (int i = 0; i < 10; i++) { errorWitness.clearException(); } assertEquals("The cleared run count was not 1 after multiple clearException calls without an " + "error call between them", 1, testWitnessListener.clearRunCount); }