org.xwiki.test
Class AbstractMockingComponentTestCase
java.lang.Object
org.xwiki.test.AbstractMockingTestCase
org.xwiki.test.AbstractMockingComponentTestCase
public abstract class AbstractMockingComponentTestCase
- extends AbstractMockingTestCase
Unit tests for Components should extend this class instead of the older
AbstractComponentTestCase test class. To use this class, add a private field of the type of
the component class being tested and annotate it with MockingRequirement. This test
case will then find all Requirements of the component class being tested and inject mocks for each of them. To set
expectations simply look them up in setUp() (for example) and define their expectations in your test methods or
setUp(). For example:
public class MyComponentTest
{
@MockingRequirement
private MyComponent myComponent;
private SomeRequirementComponentRoleClass requirement;
@Override
@Before
public void setUp() throws Exception
{
super.setUp();
requirement = getComponentManager().lookup(SomeRequirementComponentRoleClass.class);
}
...
}
Note that if your component under test is using other components in its initialize() method
you'll need to override the configure() method to add Mock expectations there.
- Since:
- 2.2M1
- Version:
- $Id$
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AbstractMockingComponentTestCase
public AbstractMockingComponentTestCase()
getMockLogger
public org.slf4j.Logger getMockLogger(Class<?> mockRequirementInstanceClass)
- Returns:
- the Mock Logger if the Component under Test has requested an Injection of a Logger or null otherwise
getMockLogger
public org.slf4j.Logger getMockLogger()
- Returns:
- the Mock Logger if the Component under Test has requested an Injection of a Logger or null otherwise
setUp
public void setUp()
throws Exception
- Throws:
Exception
setupDependencies
protected void setupDependencies()
throws Exception
- Setup mock dependencies before initializing the @MockingRequirement components.
- Throws:
Exception
configure
public void configure()
throws Exception
- Provides a hook so that users of this class can perform configuration before the component is looked up. This
allows for example the ability to set expectations on mocked components used in Initializable.initialize()
methods.
- Throws:
Exception
getComponentManager
public EmbeddableComponentManager getComponentManager()
throws Exception
- Specified by:
getComponentManager in class AbstractMockingTestCase
- Returns:
- a configured Component Manager
- Throws:
Exception
Copyright © 2004-2012 XWiki. All Rights Reserved.