Class SynchronizedRunListener


  • @ThreadSafe
    final class SynchronizedRunListener
    extends RunListener
    Thread-safe decorator for 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 sychronized, clients that added multiple listeners that called common code might see issues due to the reduced synchronization.

    Since:
    4.12
    See Also:
    RunNotifier
    • Field Detail

      • 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: RunListener
        Called before any tests have been run. This may be called on an arbitrary thread.
        Overrides:
        testRunStarted in class RunListener
        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: RunListener
        Called when all tests have finished. This may be called on an arbitrary thread.
        Overrides:
        testRunFinished in class RunListener
        Parameters:
        result - the summary of the test run, including all the tests that failed
        Throws:
        java.lang.Exception
      • testStarted

        public void testStarted​(Description description)
                         throws java.lang.Exception
        Description copied from class: RunListener
        Called when an atomic test is about to be started.
        Overrides:
        testStarted in class RunListener
        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: RunListener
        Called when an atomic test has finished, whether the test succeeds or fails.
        Overrides:
        testFinished in class RunListener
        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: RunListener
        Called 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 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.

        Overrides:
        testFailure in class RunListener
        Parameters:
        failure - describes the test that failed and the exception that was thrown
        Throws:
        java.lang.Exception
      • testIgnored

        public void testIgnored​(Description description)
                         throws java.lang.Exception
        Description copied from class: RunListener
        Called when a test will not be run, generally because a test method is annotated with Ignore.
        Overrides:
        testIgnored in class RunListener
        Parameters:
        description - describes the test that will not be run
        Throws:
        java.lang.Exception
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object