public class MocksControl extends java.lang.Object implements IMocksControl, IExpectationSetters<java.lang.Object>, java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
MocksControl.MockType |
Modifier and Type | Field and Description |
---|---|
static Range |
AT_LEAST_ONCE
One or more calls.
|
static Range |
ONCE
Exactly one call.
|
static Range |
ZERO_OR_MORE
Zero or more calls.
|
Constructor and Description |
---|
MocksControl(MocksControl.MockType type) |
Modifier and Type | Method and Description |
---|---|
IExpectationSetters<java.lang.Object> |
andAnswer(IAnswer<? extends java.lang.Object> answer)
Sets an object that will be used to calculate the answer for the expected
invocation (either return a value, or throw an exception).
|
IExpectationSetters<java.lang.Object> |
andDelegateTo(java.lang.Object answer)
Sets an object implementing the same interface as the mock.
|
IExpectationSetters<java.lang.Object> |
andReturn(java.lang.Object value)
Sets a return value that will be returned for the expected invocation.
|
void |
andStubAnswer(IAnswer<? extends java.lang.Object> answer)
Sets a stub object that will be used to calculate the answer for the
expected invocation (either return a value, or throw an exception).
|
void |
andStubDelegateTo(java.lang.Object delegateTo)
Sets a stub object implementing the same interface as the mock.
|
void |
andStubReturn(java.lang.Object value)
Sets a stub return value that will be returned for the expected
invocation.
|
void |
andStubThrow(java.lang.Throwable throwable)
Sets a stub throwable that will be thrown for the expected invocation.
|
IExpectationSetters<java.lang.Object> |
andThrow(java.lang.Throwable throwable)
Sets a throwable that will be thrown for the expected invocation.
|
IExpectationSetters<java.lang.Object> |
anyTimes()
Expect the last invocation any times.
|
void |
asStub()
Sets stub behavior for the expected invocation (this is needed for void
methods).
|
IExpectationSetters<java.lang.Object> |
atLeastOnce()
Expect the last invocation at least once.
|
void |
checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)
Check that the mock is called from only one thread
|
void |
checkOrder(boolean value)
Switches order checking on and off.
|
<T> T |
createMock(java.lang.Class<T> toMock)
Creates a mock object that implements the given interface.
|
<T> T |
createMock(java.lang.String name,
java.lang.Class<T> toMock)
Creates a mock object that implements the given interface.
|
protected <T> IProxyFactory<T> |
createProxyFactory(java.lang.Class<T> toMock) |
IMocksControlState |
getState() |
void |
makeThreadSafe(boolean threadSafe)
Makes the mock thread safe.
|
IExpectationSetters<java.lang.Object> |
once()
Expect the last invocation once.
|
void |
replay()
Switches the control from record mode to replay mode.
|
void |
reset()
Removes all expectations for the mock objects of this control.
|
void |
resetToDefault()
Removes all expectations for the mock objects of this control and turn
them to default mocks.
|
void |
resetToNice()
Removes all expectations for the mock objects of this control and turn
them to nice mocks.
|
void |
resetToStrict()
Removes all expectations for the mock objects of this control and turn
them to strict mocks.
|
void |
setLegacyDefaultMatcher(ArgumentsMatcher matcher) |
void |
setLegacyDefaultReturnValue(java.lang.Object value) |
void |
setLegacyDefaultThrowable(java.lang.Throwable throwable) |
void |
setLegacyDefaultVoidCallable() |
void |
setLegacyMatcher(ArgumentsMatcher matcher) |
IExpectationSetters<java.lang.Object> |
times(int times)
Expect the last invocation
count times. |
IExpectationSetters<java.lang.Object> |
times(int min,
int max)
Expect the last invocation between
min and
max times. |
void |
verify()
Verifies that all expectations were met.
|
public static final Range ONCE
public static final Range AT_LEAST_ONCE
public static final Range ZERO_OR_MORE
public MocksControl(MocksControl.MockType type)
public IMocksControlState getState()
public <T> T createMock(java.lang.Class<T> toMock)
IMocksControl
createMock
in interface IMocksControl
T
- the interface that the mock object should implement.toMock
- the class of the interface that the mock object should implement.public <T> T createMock(java.lang.String name, java.lang.Class<T> toMock)
IMocksControl
createMock
in interface IMocksControl
T
- the interface that the mock object should implement.name
- the name of the mock object .toMock
- the class of the interface that the mock object should implement.protected <T> IProxyFactory<T> createProxyFactory(java.lang.Class<T> toMock)
public final void reset()
IMocksControl
reset
in interface IMocksControl
public void resetToNice()
IMocksControl
resetToNice
in interface IMocksControl
public void resetToDefault()
IMocksControl
resetToDefault
in interface IMocksControl
public void resetToStrict()
IMocksControl
resetToStrict
in interface IMocksControl
public void replay()
IMocksControl
replay
in interface IMocksControl
public void verify()
IMocksControl
verify
in interface IMocksControl
public void checkOrder(boolean value)
IMocksControl
checkOrder
in interface IMocksControl
value
- true
switches order checking on, false
switches it off.public void makeThreadSafe(boolean threadSafe)
IMocksControl
makeThreadSafe
in interface IMocksControl
threadSafe
- If the mock should be thread safe or notpublic void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)
IMocksControl
checkIsUsedInOneThread
in interface IMocksControl
shouldBeUsedInOneThread
- If it should be used in one thread only or notpublic IExpectationSetters<java.lang.Object> andReturn(java.lang.Object value)
IExpectationSetters
andReturn
in interface IExpectationSetters<java.lang.Object>
value
- the value to return.public IExpectationSetters<java.lang.Object> andThrow(java.lang.Throwable throwable)
IExpectationSetters
andThrow
in interface IExpectationSetters<java.lang.Object>
throwable
- the throwable to throw.public IExpectationSetters<java.lang.Object> andAnswer(IAnswer<? extends java.lang.Object> answer)
IExpectationSetters
andAnswer
in interface IExpectationSetters<java.lang.Object>
answer
- the object used to answer the invocation.public IExpectationSetters<java.lang.Object> andDelegateTo(java.lang.Object answer)
IExpectationSetters
andDelegateTo
in interface IExpectationSetters<java.lang.Object>
answer
- the object the call is delegated to.public void andStubReturn(java.lang.Object value)
IExpectationSetters
andStubReturn
in interface IExpectationSetters<java.lang.Object>
value
- the value to return.public void andStubThrow(java.lang.Throwable throwable)
IExpectationSetters
andStubThrow
in interface IExpectationSetters<java.lang.Object>
throwable
- the throwable to throw.public void andStubAnswer(IAnswer<? extends java.lang.Object> answer)
IExpectationSetters
andStubAnswer
in interface IExpectationSetters<java.lang.Object>
answer
- the object used to answer the invocation.public void andStubDelegateTo(java.lang.Object delegateTo)
IExpectationSetters
andStubDelegateTo
in interface IExpectationSetters<java.lang.Object>
delegateTo
- the object the call is delegated to.public void asStub()
IExpectationSetters
asStub
in interface IExpectationSetters<java.lang.Object>
public IExpectationSetters<java.lang.Object> times(int times)
IExpectationSetters
count
times.times
in interface IExpectationSetters<java.lang.Object>
times
- the number of invocations expected.public IExpectationSetters<java.lang.Object> times(int min, int max)
IExpectationSetters
min
and
max
times.times
in interface IExpectationSetters<java.lang.Object>
min
- the minimum number of invocations expected.max
- the maximum number of invocations expected.public IExpectationSetters<java.lang.Object> once()
IExpectationSetters
once
in interface IExpectationSetters<java.lang.Object>
public IExpectationSetters<java.lang.Object> atLeastOnce()
IExpectationSetters
atLeastOnce
in interface IExpectationSetters<java.lang.Object>
public IExpectationSetters<java.lang.Object> anyTimes()
IExpectationSetters
anyTimes
in interface IExpectationSetters<java.lang.Object>
public void setLegacyDefaultMatcher(ArgumentsMatcher matcher)
public void setLegacyMatcher(ArgumentsMatcher matcher)
public void setLegacyDefaultReturnValue(java.lang.Object value)
public void setLegacyDefaultVoidCallable()
public void setLegacyDefaultThrowable(java.lang.Throwable throwable)
Copyright © 2001-2009 OFFIS, Tammo Freese, Henri Tremblay. This documentation is provided under the terms of the MIT licence.]]>