@ThreadSafe public class SpringContextRule extends Object implements org.junit.rules.TestRule
A JUnit rule to be used when Spring context mocking is required.
The rule will preserve Spring container from before the test method or test class execution (depending on whether
the rule is used as a Rule
or ClassRule
), and restore it after execution. To ensure thread safety
synchronization will be used.
The rule also provides methods for mocking the container context and specific Spring components.
Constructor and Description |
---|
SpringContextRule() |
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
<T> T |
mockSpringComponent(String componentKey,
Class<T> componentClass)
Mock a component that could be accessed by ComponentAccessor or ContainerManager.
|
void |
mockSpringComponent(String componentKey,
Object componentInstance)
Mock a component that could be accessed by ComponentAccessor or ContainerManager.
|
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
public <T> T mockSpringComponent(@NotNull String componentKey, @NotNull Class<T> componentClass)
componentKey
- key of the componentcomponentClass
- class of componentCopyright © 2016 Atlassian Software Systems Pty Ltd. All rights reserved.