Class SynchronizedRunListener
- java.lang.Object
-
- org.junit.runner.notification.RunListener
-
- org.junit.runner.notification.SynchronizedRunListener
-
@ThreadSafe final class SynchronizedRunListener extends RunListener
Thread-safe decorator forRunListenerimplementations 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.
- Since:
- 4.12
- See Also:
RunNotifier
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.junit.runner.notification.RunListener
RunListener.ThreadSafe
-
-
Field Summary
Fields Modifier and Type Field Description private RunListenerlistenerprivate java.lang.Objectmonitor
-
Constructor Summary
Constructors Constructor Description SynchronizedRunListener(RunListener listener, java.lang.Object monitor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object other)inthashCode()voidtestAssumptionFailure(Failure failure)Called when an atomic test flags that it assumes a condition that is falsevoidtestFailure(Failure failure)Called when an atomic test fails, or when a listener throws an exception.voidtestFinished(Description description)Called when an atomic test has finished, whether the test succeeds or fails.voidtestIgnored(Description description)Called when a test will not be run, generally because a test method is annotated withIgnore.voidtestRunFinished(Result result)Called when all tests have finished.voidtestRunStarted(Description description)Called before any tests have been run.voidtestStarted(Description description)Called when an atomic test is about to be started.voidtestSuiteFinished(Description description)Called when a test suite has finished, whether the test suite succeeds or fails.voidtestSuiteStarted(Description description)Called when a test suite is about to be started.java.lang.StringtoString()
-
-
-
Field Detail
-
listener
private final RunListener listener
-
monitor
private final java.lang.Object monitor
-
-
Constructor Detail
-
SynchronizedRunListener
SynchronizedRunListener(RunListener listener, java.lang.Object monitor)
-
-
Method Detail
-
testRunStarted
public void testRunStarted(Description description) throws java.lang.Exception
Description copied from class:RunListenerCalled before any tests have been run. This may be called on an arbitrary thread.- Overrides:
testRunStartedin classRunListener- Parameters:
description- describes the tests to be run- Throws:
java.lang.Exception
-
testRunFinished
public void testRunFinished(Result result) throws java.lang.Exception
Description copied from class:RunListenerCalled when all tests have finished. This may be called on an arbitrary thread.- Overrides:
testRunFinishedin classRunListener- Parameters:
result- the summary of the test run, including all the tests that failed- Throws:
java.lang.Exception
-
testSuiteStarted
public void testSuiteStarted(Description description) throws java.lang.Exception
Called when a test suite is about to be started. If this method is called for a givenDescription, thenRunListener.testSuiteFinished(Description)will also be called for the sameDescription.Note that not all runners will call this method, so runners should be prepared to handle
Synchronized decorator forRunListener.testStarted(Description)calls for tests where there was no correspondingtestSuiteStarted()call for the parentDescription.RunListener.testSuiteStarted(Description).- Overrides:
testSuiteStartedin classRunListener- Parameters:
description- the description of the test suite that is about to be run (generally a class name).- Throws:
java.lang.Exception- if any occurs.- Since:
- 4.13
-
testSuiteFinished
public void testSuiteFinished(Description description) throws java.lang.Exception
Called when a test suite has finished, whether the test suite succeeds or fails. This method will not be called for a givenDescriptionunlessRunListener.testSuiteStarted(Description)was called for the same @code Description}. Synchronized decorator forRunListener.testSuiteFinished(Description).- Overrides:
testSuiteFinishedin classRunListener- Parameters:
description- the description of the test suite that just ran.- Throws:
java.lang.Exception- Since:
- 4.13
-
testStarted
public void testStarted(Description description) throws java.lang.Exception
Description copied from class:RunListenerCalled when an atomic test is about to be started.- Overrides:
testStartedin classRunListener- Parameters:
description- the description of the test that is about to be run (generally a class and method name)- Throws:
java.lang.Exception
-
testFinished
public void testFinished(Description description) throws java.lang.Exception
Description copied from class:RunListenerCalled when an atomic test has finished, whether the test succeeds or fails.- Overrides:
testFinishedin classRunListener- Parameters:
description- the description of the test that just ran- Throws:
java.lang.Exception
-
testFailure
public void testFailure(Failure failure) throws java.lang.Exception
Description copied from class:RunListenerCalled when an atomic test fails, or when a listener throws an exception.In the case of a failure of an atomic test, this method will be called with the same
Descriptionpassed toRunListener.testStarted(Description), from the same thread that calledRunListener.testStarted(Description).In the case of a listener throwing an exception, this will be called with a
DescriptionofDescription.TEST_MECHANISM, and may be called on an arbitrary thread.- Overrides:
testFailurein classRunListener- Parameters:
failure- describes the test that failed and the exception that was thrown- Throws:
java.lang.Exception
-
testAssumptionFailure
public void testAssumptionFailure(Failure failure)
Description copied from class:RunListenerCalled when an atomic test flags that it assumes a condition that is false- Overrides:
testAssumptionFailurein classRunListener- Parameters:
failure- describes the test that failed and theAssumptionViolatedExceptionthat was thrown
-
testIgnored
public void testIgnored(Description description) throws java.lang.Exception
Description copied from class:RunListenerCalled when a test will not be run, generally because a test method is annotated withIgnore.- Overrides:
testIgnoredin classRunListener- Parameters:
description- describes the test that will not be run- Throws:
java.lang.Exception
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-