Class GuiceyHooksRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    @Deprecated
    public class GuiceyHooksRule
    extends org.junit.rules.ExternalResource
    Deprecated.
    use junit 5 extensions which allow hooks declaration directly
    Junit rule for changing application configuration (remove some components or register test specific (e.g. mocks)). Supposed to be used in conjunction with DropwizardAppRule or GuiceyAppRule. Must be used ONLY with RuleChain because normally rules order is not predictable:
    static GuiceyAppRule RULE = new GuiceyAppRule(App.class, null);
        {@literal @}ClassRule
        public static RuleChain chain = RuleChain
                .outerRule(new GuiceyHooksRule((builder) -> builder.modules(...)))
                .around(RULE);
     
    To declare common extensions for all tests, declare common rule in test class (without @ClassRule annotation!) and use it in chain:
    public class BaseTest {
             static GuiceyHooksRule BASE = new GuiceyHooksRule((builder) -> builder.modules(...))
         }
    
         public class SomeTest extends BaseTest {
             static GuiceyAppRule RULE = new GuiceyAppRule(App.class, null);
             {@literal @}ClassRule
             public static RuleChain chain = RuleChain
                .outerRule(BASE)
                .around(new GuiceyHooksRule((builder) -> builder.modules(...)) // optional test-specific staff
                .around(RULE);
         }
     

    IMPORTANT: rule will not work with spock extensions (because of lifecycle specifics)! Use UseGuiceyHooks or new hooks attribute in UseGuiceyApp or UseDropwizardApp instead.

    Rule is thread safe: it is assumed that rule will be applied at the same thread as test application initialization.

    Since:
    11.04.2018
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void after()
      Deprecated.
       
      protected void before()
      Deprecated.
       
      • Methods inherited from class org.junit.rules.ExternalResource

        apply
      • Methods inherited from class java.lang.Object

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

      • before

        protected void before()
                       throws java.lang.Throwable
        Deprecated.
        Overrides:
        before in class org.junit.rules.ExternalResource
        Throws:
        java.lang.Throwable
      • after

        protected void after()
        Deprecated.
        Overrides:
        after in class org.junit.rules.ExternalResource