org.xwiki.test.jmock
Class AbstractMockingComponentTestCase<T>
java.lang.Object
org.xwiki.test.jmock.AbstractMockingTestCase
org.xwiki.test.jmock.AbstractMockingComponentTestCase<T>
Deprecated. starting with 4.3.1 use MockitoComponentMockingRule instead
@Deprecated
public abstract class AbstractMockingComponentTestCase<T>
- extends AbstractMockingTestCase
Unit tests for Components should extend this class instead of the older
AbstractComponentTestCase test class. To use this class, annotate your test class with
with MockingRequirement, passing the implementation class you're testing.
Then in your test code, do a lookup of your component under test and you'll get a component instance which has all
its injected dependencies mocked automatically.
For example:
@MockingRequirement(MyComponentImplementation.class)
public class MyComponentTest extends AbstractMockingComponentTestCase<MyComponent>
{
@Test
public void someTest() throws Exception
{
MyComponent myComponent = getMockedComponent();
...
}
Note that by default there are no component registered against the component manager except those mocked
automatically by the @MockingRequirement annotation. This has 2 advantages:
- This is the spirit of AbstractMockingComponentTestCase since they're supposed to mock all dependencies and
define their behaviors
- It makes the tests up to 10 times faster
If you really need to register some components, use the ComponentList annotation and if you really really
need to register all components (it takes time) then use AllComponents.
- Since:
- 2.2M1
- Version:
- $Id: f26a3b9fa8fb479386af1c61443aff6f1893b8dd $
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AbstractMockingComponentTestCase
public AbstractMockingComponentTestCase()
- Deprecated.
getMockedComponent
public T getMockedComponent()
throws org.xwiki.component.manager.ComponentLookupException
- Deprecated.
- Returns:
- the first component mocked by a
MockingRequirement annotation
- Throws:
org.xwiki.component.manager.ComponentLookupException- Since:
- 4.2M3
getMockedComponent
public T getMockedComponent(Class mockedComponentClass)
throws org.xwiki.component.manager.ComponentLookupException
- Deprecated.
- Parameters:
mockedComponentClass - the class of the mocked component to return
- Returns:
- the component mocked by a
MockingRequirement annotation that is of the passed class type
- Throws:
org.xwiki.component.manager.ComponentLookupException- Since:
- 4.2M3
getMockLogger
public org.slf4j.Logger getMockLogger(Class<?> mockedComponentClass)
throws Exception
- Deprecated.
- Returns:
- the Mock Logger if the Component under Test has requested an Injection of a Logger or null otherwise
- Throws:
Exception
getMockLogger
public org.slf4j.Logger getMockLogger()
throws Exception
- Deprecated.
- Returns:
- the Mock Logger if the Component under Test has requested an Injection of a Logger or null otherwise
- Throws:
Exception
setUp
public void setUp()
throws Exception
- Deprecated.
- Throws:
Exception
getComponentManager
public MockingComponentManager getComponentManager()
throws Exception
- Deprecated.
- Specified by:
getComponentManager in class AbstractMockingTestCase
- Returns:
- a configured Component Manager
- Throws:
Exception
Copyright © 2004–2014 XWiki. All rights reserved.