com.atlassian.jira.junit.rules
Class MockitoContainer
java.lang.Object
com.atlassian.jira.junit.rules.MockitoContainer
- All Implemented Interfaces:
- org.junit.rules.TestRule
public class MockitoContainer
- extends Object
- implements org.junit.rules.TestRule
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
ComponentAccessor.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);
(...)
}
- Since:
- v6.1
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MockitoContainer
public MockitoContainer(Object test)
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
getMockComponentContainer
public MockComponentContainer getMockComponentContainer()
getMockWorker
public MockComponentWorker getMockWorker()
- A shorthand for getMockComponentContainer().getMockWorker()
- Returns:
- worker
getInnerChain
public org.junit.rules.RuleChain getInnerChain()
Copyright © 2002-2014 Atlassian. All Rights Reserved.