|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.mock.core.MockObject<T>
public class MockObject<T>
Implementation of a Mock.
Field Summary | |
---|---|
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 Summary | |
---|---|
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. |
Method Summary | ||
---|---|---|
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()
|
|
|
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)
Gets the type of the object to inject. |
|
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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected String name
protected Class<T> mockedType
protected MockProxy<T> mockProxy
protected BehaviorDefiningInvocations oneTimeMatchingBehaviorDefiningInvocations
protected BehaviorDefiningInvocations alwaysMatchingBehaviorDefiningInvocations
protected Map<String,Mock<?>> chainedMocksPerName
protected static ThreadLocal<Scenario> scenarioThreadLocal
protected static ThreadLocal<MatchingInvocationBuilder> matchingInvocationBuilderThreadLocal
Constructor Detail |
---|
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 nullMethod Detail |
---|
public static Scenario getCurrentScenario()
public T getObjectToInject()
getObjectToInject
in interface ObjectToInjectHolder<T>
public Type getObjectToInjectType(Field field)
ObjectToInjectHolder
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()
getMock
in interface Mock<T>
public Class<?> getMockedType()
public T returns(Object returnValue)
onceReturns(java.lang.Object)
method.
returns
in interface Mock<T>
returnValue
- The value to return
public T raises(Throwable exception)
onceRaises(java.lang.Throwable)
method.
raises
in interface Mock<T>
exception
- The exception to raise, not null
public T raises(Class<? extends Throwable> exceptionClass)
onceRaises(java.lang.Throwable)
method.
raises
in interface Mock<T>
exceptionClass
- The type of exception to raise, not null
public T performs(MockBehavior mockBehavior)
oncePerforms(org.unitils.mock.mockbehavior.MockBehavior)
method.
performs
in interface Mock<T>
mockBehavior
- The behavior to perform, not null
public T onceReturns(Object returnValue)
returns(java.lang.Object)
instead.
onceReturns
in interface Mock<T>
returnValue
- The value to return
public T onceRaises(Throwable exception)
raises(java.lang.Throwable)
instead.
onceRaises
in interface Mock<T>
exception
- The exception to raise, not null
public T onceRaises(Class<? extends Throwable> exceptionClass)
raises(java.lang.Throwable)
instead.
onceRaises
in interface Mock<T>
exceptionClass
- The type of exception to raise, not null
public T oncePerforms(MockBehavior mockBehavior)
performs(org.unitils.mock.mockbehavior.MockBehavior)
instead.
oncePerforms
in interface Mock<T>
mockBehavior
- The behavior to perform, not null
public 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 MockFactory
public String getName()
protected T startMatchingInvocation(MatchingInvocationHandler matchingInvocationHandler)
protected MatchingInvocationBuilder getMatchingInvocationBuilder()
protected Scenario getScenario(Object testObject)
protected MockProxy<T> createMockProxy()
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 Scenario createScenario(Object testObject)
protected MatchingInvocationBuilder createMatchingInvocationBuilder()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |