public class MockObject<T> extends Object implements Mock<T>, MockFactory, ObjectToInjectHolder<T>
| Modifier and Type | Field and Description |
|---|---|
protected BehaviorDefiningInvocations |
alwaysMatchingBehaviorDefiningInvocations |
protected Map<String,Mock<?>> |
chainedMocksPerName |
protected static ThreadLocal<MatchingInvocationBuilder> |
matchingInvocationBuilderThreadLocal |
protected Class<T> |
mockedType |
protected MockProxy<T> |
mockProxy |
protected String |
name |
protected BehaviorDefiningInvocations |
oneTimeMatchingBehaviorDefiningInvocations |
protected static ThreadLocal<Scenario> |
scenarioThreadLocal |
| Constructor and Description |
|---|
MockObject(Class<?> mockedType,
Object testObject)
Creates a mock of the given type with un-capitalized type name + Mock as name, e.g. myServiceMock.
|
MockObject(String name,
Class<?> mockedType,
Object testObject)
Creates a mock of the given type.
|
| Modifier and Type | Method and Description |
|---|---|
T |
assertInvoked()
Asserts that an invocation that matches the invocation following this call has been observed
on this mock object during this test.
|
T |
assertInvokedInSequence()
Asserts that an invocation that matches the invocation following this call has been observed
on this mock object during this test.
|
T |
assertNotInvoked()
Asserts that no invocation that matches the invocation following this call has been observed
on this mock object during this test.
|
protected BehaviorDefiningInvocations |
createAlwaysMatchingBehaviorDefiningInvocations() |
protected MatchingInvocationHandler |
createAlwaysMatchingBehaviorDefiningMatchingInvocationHandler(MockBehavior mockBehavior) |
protected MatchingInvocationHandler |
createAssertInvokedInSequenceVerifyingMatchingInvocationHandler() |
protected MatchingInvocationHandler |
createAssertInvokedVerifyingMatchingInvocationHandler() |
protected MatchingInvocationHandler |
createAssertNotInvokedVerifyingMatchingInvocationHandler() |
<M> Mock<M> |
createChainedMock(String name,
Class<M> mockedType) |
protected MatchingInvocationBuilder |
createMatchingInvocationBuilder() |
protected MockProxy<T> |
createMockProxy() |
protected BehaviorDefiningInvocations |
createOneTimeMatchingBehaviorDefiningInvocations() |
protected MatchingInvocationHandler |
createOneTimeMatchingBehaviorDefiningMatchingInvocationHandler(MockBehavior mockBehavior) |
protected Scenario |
createScenario(Object testObject) |
static Scenario |
getCurrentScenario() |
protected MatchingInvocationBuilder |
getMatchingInvocationBuilder() |
T |
getMock()
Returns the mock proxy instance.
|
Class<?> |
getMockedType() |
String |
getName() |
T |
getObjectToInject()
Returns the mock proxy instance.
|
Type |
getObjectToInjectType(Field field) |
protected Scenario |
getScenario(Object testObject) |
T |
oncePerforms(MockBehavior mockBehavior)
Defines behavior for this mock so that will be performed when the invocation following
this call matches the observed behavior.
|
T |
onceRaises(Class<? extends Throwable> exceptionClass)
Defines behavior for this mock so that it raises an instance of the given exception class when the invocation following
this call matches the observed behavior.
|
T |
onceRaises(Throwable exception)
Defines behavior for this mock so that it raises the given exception when the invocation following
this call matches the observed behavior.
|
T |
onceReturns(Object returnValue)
Defines behavior for this mock so that it will return the given value when the invocation following
this call matches the observed behavior.
|
T |
performs(MockBehavior mockBehavior)
Defines behavior for this mock so that will be performed when the invocation following
this call matches the observed behavior.
|
T |
raises(Class<? extends Throwable> exceptionClass)
Defines behavior for this mock so that it raises the given exception when the invocation following
this call matches the observed behavior.
|
T |
raises(Throwable exception)
Defines behavior for this mock so that it raises the given exception when the invocation following
this call matches the observed behavior.
|
void |
resetBehavior()
Removes all behavior defined for this mock.
|
T |
returns(Object returnValue)
Defines behavior for this mock so that it will return the given value when the invocation following
this call matches the observed behavior.
|
protected T |
startMatchingInvocation(MatchingInvocationHandler matchingInvocationHandler) |
protected String name
protected BehaviorDefiningInvocations oneTimeMatchingBehaviorDefiningInvocations
protected BehaviorDefiningInvocations alwaysMatchingBehaviorDefiningInvocations
protected static ThreadLocal<Scenario> scenarioThreadLocal
protected static ThreadLocal<MatchingInvocationBuilder> matchingInvocationBuilderThreadLocal
public MockObject(Class<?> mockedType, Object testObject)
mockedType - The mock type that will be proxied, use the raw type when mocking generic types, not nulltestObject - The test object, not nullpublic MockObject(String name, Class<?> mockedType, Object testObject)
name - The name of the mock, e.g. the field-name, null for the defaultmockedType - The mock type that will be proxied, use the raw type when mocking generic types, not nulltestObject - The test object, not nullpublic static Scenario getCurrentScenario()
public T getObjectToInject()
getObjectToInject in interface ObjectToInjectHolder<T>public Type getObjectToInjectType(Field field)
getObjectToInjectType in interface ObjectToInjectHolder<T>field - The field that declared this mock object, null if there is no field (or not known)public T getMock()
public Class<?> getMockedType()
public T returns(Object returnValue)
onceReturns(java.lang.Object) method.public T raises(Throwable exception)
onceRaises(java.lang.Throwable) method.public T raises(Class<? extends Throwable> exceptionClass)
onceRaises(java.lang.Throwable) method.public T performs(MockBehavior mockBehavior)
oncePerforms(org.unitils.mock.mockbehavior.MockBehavior) method.public T onceReturns(Object returnValue)
returns(java.lang.Object) instead.onceReturns in interface Mock<T>returnValue - The value to returnpublic T onceRaises(Throwable exception)
raises(java.lang.Throwable) instead.onceRaises in interface Mock<T>exception - The exception to raise, not nullpublic T onceRaises(Class<? extends Throwable> exceptionClass)
raises(java.lang.Throwable) instead.onceRaises in interface Mock<T>exceptionClass - The type of exception to raise, not nullpublic T oncePerforms(MockBehavior mockBehavior)
performs(org.unitils.mock.mockbehavior.MockBehavior) instead.oncePerforms in interface Mock<T>mockBehavior - The behavior to perform, not nullpublic T assertInvoked()
assertInvoked in interface Mock<T>public T assertInvokedInSequence()
assertInvokedInSequence in interface Mock<T>public T assertNotInvoked()
assertNotInvoked in interface Mock<T>public void resetBehavior()
resetBehavior in interface Mock<T>public <M> Mock<M> createChainedMock(String name, Class<M> mockedType)
createChainedMock in interface MockFactorypublic String getName()
protected T startMatchingInvocation(MatchingInvocationHandler matchingInvocationHandler)
protected MatchingInvocationBuilder getMatchingInvocationBuilder()
protected MatchingInvocationHandler createOneTimeMatchingBehaviorDefiningMatchingInvocationHandler(MockBehavior mockBehavior)
protected MatchingInvocationHandler createAlwaysMatchingBehaviorDefiningMatchingInvocationHandler(MockBehavior mockBehavior)
protected BehaviorDefiningInvocations createOneTimeMatchingBehaviorDefiningInvocations()
protected BehaviorDefiningInvocations createAlwaysMatchingBehaviorDefiningInvocations()
protected MatchingInvocationHandler createAssertInvokedVerifyingMatchingInvocationHandler()
protected MatchingInvocationHandler createAssertInvokedInSequenceVerifyingMatchingInvocationHandler()
protected MatchingInvocationHandler createAssertNotInvokedVerifyingMatchingInvocationHandler()
protected MatchingInvocationBuilder createMatchingInvocationBuilder()
Copyright © 2016. All Rights Reserved.