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);
}
...
}
- 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
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.