Class TestRuleAdapter

  • All Implemented Interfaces:
    org.junit.rules.TestRule
    Direct Known Subclasses:
    RequireAssertionsRule

    public abstract class TestRuleAdapter
    extends java.lang.Object
    implements org.junit.rules.TestRule
    An abstract TestRule that guarantees the execution of afterAlways(java.util.List<java.lang.Throwable>) even if an exception has been thrown from delegate Statement. This is much like AfterClass or After annotations but can be used with RuleChain to guarantee the order of execution.
    • Constructor Summary

      Constructors 
      Constructor Description
      TestRuleAdapter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterAlways​(java.util.List<java.lang.Throwable> errors)
      Always called after the delegate Statement, even if an exception (or assumption failure) occurs.
      protected void afterIfSuccessful()
      Called only if the delegate Statement returned successfully.
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement s, org.junit.runner.Description d)  
      protected void before()
      Always called before the delegate Statement.
      • Methods inherited from class java.lang.Object

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

      • TestRuleAdapter

        public TestRuleAdapter()
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement s,
                                                       org.junit.runner.Description d)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • before

        protected void before()
                       throws java.lang.Throwable
        Always called before the delegate Statement.
        Throws:
        java.lang.Throwable
      • afterAlways

        protected void afterAlways​(java.util.List<java.lang.Throwable> errors)
                            throws java.lang.Throwable
        Always called after the delegate Statement, even if an exception (or assumption failure) occurs. Any exceptions thrown from the body of this method will be chained using MultipleFailureException.
        Parameters:
        errors - A list of errors received so far. The list is modifiable although should only be extended with new potential exceptions.
        Throws:
        java.lang.Throwable
      • afterIfSuccessful

        protected void afterIfSuccessful()
                                  throws java.lang.Throwable
        Called only if the delegate Statement returned successfully.
        Throws:
        java.lang.Throwable