public class

MockitoContainer

extends Object
implements TestRule
java.lang.Object
   ↳ com.atlassian.jira.junit.rules.MockitoContainer

Class Overview

Rule that combines mockito initialization with MockComponentContainer. This will take care of initializing mocks using Mockito and also putting them in a mock component container so that they're available via getComponent(Class). After the test has run, the mock container will be tear down so that next test does not accidentally access stale state.

Usage:

     @Rule public MockitoContainer mockitoContainer = MockitoMocksInContainer.rule(this);

     @Mock
     @AvailableInContainer
     private UserService mockUserService;

     @Mock private JiraAuthenticationContext jiraAuthenticationContext;
 
where the userService will be available via ComponentAccessor, but the jiraAuthenticationContext will just be instantiated as a Mockito mock

Gives also ability to access initialized MockComponentWorker which allows to manipulate mocks directly from tests

Example:

     @Rule public MockitoContainer mockitoContainer = MockitoMocksInContainer.rule(this);

     @Mock
     public void testSomething(){
         mockitoContainer.getMockWorker().setMockUserKeyStore().useDefaultMapping(false);
         (...)
     }
 

Summary

Public Constructors
MockitoContainer(Object test)
Public Methods
Statement apply(Statement base, Description description)
RuleChain getInnerChain()
MockComponentContainer getMockComponentContainer()
MockComponentWorker getMockWorker()
A shorthand for getMockComponentContainer().getMockWorker()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.junit.rules.TestRule

Public Constructors

public MockitoContainer (Object test)

Public Methods

public Statement apply (Statement base, Description description)

public RuleChain getInnerChain ()

public MockComponentContainer getMockComponentContainer ()

public MockComponentWorker getMockWorker ()

A shorthand for getMockComponentContainer().getMockWorker()

Returns
  • worker