Class ChainingRunNotifierWrapper


  • public class ChainingRunNotifierWrapper
    extends org.junit.runner.notification.RunNotifier
    Wraps a RunNotifier to extend the listener concept to act like a chain in meaning of having revert order on test finalizing. For this the listener added will not be passed to the wrapped instance to avoid calling them twice, so the wrapped instance holds only the instances assigned before wrapping. As the BlockJUnit4ClassRunner is used differently in environments there is no chance to intercept the RunNotifier creation, so this wrapper can be used first at entry of ParentRunner.run(RunNotifier) method. Unfortunately the firing of events for a complete test run are done outside. With that this events will not be delegatet to the wrapper instance in general as they will be called separately outside of run method.
    • Constructor Summary

      Constructors 
      Constructor Description
      ChainingRunNotifierWrapper​(org.junit.runner.notification.RunNotifier delegate)
      Creates a new notifier using passed notifier as delegate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFirstListener​(org.junit.runner.notification.RunListener listener)
      Adds the listener as first listener to this notifier, not to wrapped one.
      void addListener​(org.junit.runner.notification.RunListener listener)
      Adds the listener to this notifier, will not be added to wrapped one.
      void fireTestAssumptionFailed​(org.junit.runner.notification.Failure failure)
      Delegates to wrapper first, then calls RunListener.testAssumptionFailure(Failure) for all listeners in normal order.
      void fireTestFailure​(org.junit.runner.notification.Failure failure)
      Delegates to wrapper first, then calls RunListener.testFailure(Failure) for all listeners in reverse order.
      void fireTestFinished​(org.junit.runner.Description description)
      Calls RunListener.testFinished(Description) for all listeners in reversed order, afterwards it calls wrapper implementation.
      void fireTestIgnored​(org.junit.runner.Description description)
      Delegates to wrapper first, then calls RunListener.testIgnored(Description) for all listeners in normal order.
      void fireTestRunFinished​(org.junit.runner.Result result)
      Calls RunListener.testRunFinished(Result) for all listeners in reverse order.
      void fireTestRunStarted​(org.junit.runner.Description description)
      Calls RunListener.testRunStarted(Description) for all listeners in normal order.
      void fireTestStarted​(org.junit.runner.Description description)
      Delegates to wrapper first, then calls RunListener.testStarted(Description) for all listeners in normal order.
      void pleaseStop()
      Simply delegates to wrapped runner.
      protected org.junit.runner.Description recreateTestDescription​(org.junit.runner.Description description)  
      void removeAllListeners()
      Removes all listeners for this runner.
      void removeListener​(org.junit.runner.notification.RunListener listener)
      Removes the listener from wrapped notifier and this notifier.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ChainingRunNotifierWrapper

        public ChainingRunNotifierWrapper​(org.junit.runner.notification.RunNotifier delegate)
        Creates a new notifier using passed notifier as delegate.
    • Method Detail

      • addFirstListener

        public void addFirstListener​(org.junit.runner.notification.RunListener listener)
        Adds the listener as first listener to this notifier, not to wrapped one.
        Overrides:
        addFirstListener in class org.junit.runner.notification.RunNotifier
      • addListener

        public void addListener​(org.junit.runner.notification.RunListener listener)
        Adds the listener to this notifier, will not be added to wrapped one.
        Overrides:
        addListener in class org.junit.runner.notification.RunNotifier
      • removeListener

        public void removeListener​(org.junit.runner.notification.RunListener listener)
        Removes the listener from wrapped notifier and this notifier.
        Overrides:
        removeListener in class org.junit.runner.notification.RunNotifier
      • fireTestRunStarted

        public void fireTestRunStarted​(org.junit.runner.Description description)
        Calls RunListener.testRunStarted(Description) for all listeners in normal order. No call to wrapper will be done as listeners of wrapper will be called outside of run method of ClassRunner.
        Overrides:
        fireTestRunStarted in class org.junit.runner.notification.RunNotifier
      • fireTestRunFinished

        public void fireTestRunFinished​(org.junit.runner.Result result)
        Calls RunListener.testRunFinished(Result) for all listeners in reverse order. No call to wrapper will be done as listeners of wrapper will are called already outside of run method of ClassRunner.
        Overrides:
        fireTestRunFinished in class org.junit.runner.notification.RunNotifier
      • fireTestStarted

        public void fireTestStarted​(org.junit.runner.Description description)
                             throws org.junit.runner.notification.StoppedByUserException
        Delegates to wrapper first, then calls RunListener.testStarted(Description) for all listeners in normal order.
        Overrides:
        fireTestStarted in class org.junit.runner.notification.RunNotifier
        Throws:
        org.junit.runner.notification.StoppedByUserException
      • fireTestFailure

        public void fireTestFailure​(org.junit.runner.notification.Failure failure)
        Delegates to wrapper first, then calls RunListener.testFailure(Failure) for all listeners in reverse order.
        Overrides:
        fireTestFailure in class org.junit.runner.notification.RunNotifier
      • fireTestAssumptionFailed

        public void fireTestAssumptionFailed​(org.junit.runner.notification.Failure failure)
        Delegates to wrapper first, then calls RunListener.testAssumptionFailure(Failure) for all listeners in normal order.
        Overrides:
        fireTestAssumptionFailed in class org.junit.runner.notification.RunNotifier
      • fireTestIgnored

        public void fireTestIgnored​(org.junit.runner.Description description)
        Delegates to wrapper first, then calls RunListener.testIgnored(Description) for all listeners in normal order.
        Overrides:
        fireTestIgnored in class org.junit.runner.notification.RunNotifier
      • fireTestFinished

        public void fireTestFinished​(org.junit.runner.Description description)
        Calls RunListener.testFinished(Description) for all listeners in reversed order, afterwards it calls wrapper implementation.
        Overrides:
        fireTestFinished in class org.junit.runner.notification.RunNotifier
      • recreateTestDescription

        protected org.junit.runner.Description recreateTestDescription​(org.junit.runner.Description description)
      • pleaseStop

        public void pleaseStop()
        Simply delegates to wrapped runner.
        Overrides:
        pleaseStop in class org.junit.runner.notification.RunNotifier
      • removeAllListeners

        public void removeAllListeners()
        Removes all listeners for this runner.