Class MockitoTestRule

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

    public class MockitoTestRule
    extends Object
    implements org.junit.rules.TestRule
    A crude hack to allow using MockitoRule with RuleChain for a defined run order. Example:
    
     private final MockitoTestRule mockitoRule = new MockitoTestRule(this, MockitoJUnit.rule());
     private final ResourceTestRule resourceRule = ResourceTestRule.builder()
         .addResource(PersonResource::new)
         .build();
    
     @Rule
     public final RuleChain ruleChain = RuleChain.outerRule(mockitoRule).around(resourceRule);
     
    See Also:
    MockitoRule, RuleChain, #351: missing current instance in TestRule apply(), #997: ClassRule/TestRule version of Mockito's JUnitRule
    • Constructor Detail

      • MockitoTestRule

        public MockitoTestRule​(Object testInstance,
                               org.mockito.junit.MockitoRule delegate)
        Create a new adapter for a MockitoRule instance.
        Parameters:
        testInstance - The instance of the test class (which is most likely this)
        delegate - The instance of MockitoRule to wrap around
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule