@RunListener.ThreadSafe final class SynchronizedRunListener extends RunListener
RunListener
implementations that synchronizes
calls to the delegate.
This class synchronizes all listener calls on a RunNotifier instance. This is done because prior to JUnit 4.12, all listeners were called in a synchronized block in RunNotifier, so no two listeners were ever called concurrently. If we instead made the methods here synchronized, clients that added multiple listeners that called common code might see issues due to the reduced synchronization.
RunNotifier
RunListener.ThreadSafe
Modifier and Type | Field and Description |
---|---|
private RunListener |
listener |
private java.lang.Object |
monitor |
Constructor and Description |
---|
SynchronizedRunListener(RunListener listener,
java.lang.Object monitor) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
int |
hashCode() |
void |
testAssumptionFailure(Failure failure)
Called when an atomic test flags that it assumes a condition that is
false
|
void |
testFailure(Failure failure)
Called when an atomic test fails, or when a listener throws an exception.
|
void |
testFinished(Description description)
Called when an atomic test has finished, whether the test succeeds or fails.
|
void |
testIgnored(Description description)
Called when a test will not be run, generally because a test method is annotated
with
Ignore . |
void |
testRunFinished(Result result)
Called when all tests have finished.
|
void |
testRunStarted(Description description)
Called before any tests have been run.
|
void |
testStarted(Description description)
Called when an atomic test is about to be started.
|
void |
testSuiteFinished(Description description)
Called when a test suite has finished, whether the test suite succeeds or fails.
|
void |
testSuiteStarted(Description description)
Called when a test suite is about to be started.
|
java.lang.String |
toString() |
private final RunListener listener
private final java.lang.Object monitor
SynchronizedRunListener(RunListener listener, java.lang.Object monitor)
public void testRunStarted(Description description) throws java.lang.Exception
RunListener
testRunStarted
in class RunListener
description
- describes the tests to be runjava.lang.Exception
public void testRunFinished(Result result) throws java.lang.Exception
RunListener
testRunFinished
in class RunListener
result
- the summary of the test run, including all the tests that failedjava.lang.Exception
public void testSuiteStarted(Description description) throws java.lang.Exception
Description
, then RunListener.testSuiteFinished(Description)
will also be called for the same Description
.
Note that not all runners will call this method, so runners should
be prepared to handle RunListener.testStarted(Description)
calls for tests
where there was no corresponding testSuiteStarted()
call for
the parent Description
.
RunListener.testSuiteStarted(Description)
.testSuiteStarted
in class RunListener
description
- the description of the test suite that is about to be run
(generally a class name).java.lang.Exception
- if any occurs.public void testSuiteFinished(Description description) throws java.lang.Exception
Description
unless
RunListener.testSuiteStarted(Description)
was called for the same @code Description}.
Synchronized decorator for RunListener.testSuiteFinished(Description)
.testSuiteFinished
in class RunListener
description
- the description of the test suite that just ran.java.lang.Exception
public void testStarted(Description description) throws java.lang.Exception
RunListener
testStarted
in class RunListener
description
- the description of the test that is about to be run
(generally a class and method name)java.lang.Exception
public void testFinished(Description description) throws java.lang.Exception
RunListener
testFinished
in class RunListener
description
- the description of the test that just ranjava.lang.Exception
public void testFailure(Failure failure) throws java.lang.Exception
RunListener
In the case of a failure of an atomic test, this method will be called
with the same Description
passed to
RunListener.testStarted(Description)
, from the same thread that called
RunListener.testStarted(Description)
.
In the case of a listener throwing an exception, this will be called with
a Description
of Description.TEST_MECHANISM
, and may be called
on an arbitrary thread.
testFailure
in class RunListener
failure
- describes the test that failed and the exception that was thrownjava.lang.Exception
public void testAssumptionFailure(Failure failure)
RunListener
testAssumptionFailure
in class RunListener
failure
- describes the test that failed and the
AssumptionViolatedException
that was thrownpublic void testIgnored(Description description) throws java.lang.Exception
RunListener
Ignore
.testIgnored
in class RunListener
description
- describes the test that will not be runjava.lang.Exception
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object