public class MocksControl extends Object implements IMocksControl, IExpectationSetters<Object>, Serializable
EasyMock. It contains the state of the mocks.| 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(MockType type) |
| Modifier and Type | Method and Description |
|---|---|
IExpectationSetters<Object> |
andAnswer(IAnswer<?> 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<Object> |
andDelegateTo(Object answer)
Sets an object implementing the same interface as the mock.
|
IExpectationSetters<Object> |
andReturn(Object value)
Sets a return value that will be returned for the expected invocation.
|
void |
andStubAnswer(IAnswer<?> 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(Object delegateTo)
Sets a stub object implementing the same interface as the mock.
|
void |
andStubReturn(Object value)
Sets a stub return value that will be returned for the expected
invocation.
|
void |
andStubThrow(Throwable throwable)
Sets a stub throwable that will be thrown for the expected invocation.
|
IExpectationSetters<Object> |
andThrow(Throwable throwable)
Sets a throwable that will be thrown for the expected invocation.
|
IExpectationSetters<Object> |
andVoid()
Records a call but returns nothing.
|
IExpectationSetters<Object> |
anyTimes()
Expect the last invocation any times.
|
void |
asStub()
Sets stub behavior for the expected invocation (this is needed for void
methods).
|
IExpectationSetters<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,R> R |
createMock(Class<T> toMock)
Same as
IMocksControl.mock(Class) but using the old naming. |
<T,R> R |
createMock(String name,
Class<T> toMock)
Same as
IMocksControl.mock(String, Class) but using the old naming. |
<T,R> R |
createMock(String name,
Class<T> toMock,
ConstructorArgs constructorArgs,
Method... mockedMethods)
Same as
IMocksControl.mock(String, Class, ConstructorArgs, Method...) but using the old naming |
static MocksControl |
getControl(Object mock) |
static InvocationHandler |
getInvocationHandler(Object mock) |
static <T,R extends T> |
getMockedClass(T proxy)
Return the class of interface (depending on the mock type) that was
mocked
|
static IProxyFactory |
getProxyFactory(Object o) |
IMocksControlState |
getState() |
MockType |
getType() |
void |
makeThreadSafe(boolean threadSafe)
Makes the mock thread safe.
|
IExpectationSetters<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.
|
IExpectationSetters<Object> |
times(int times)
Expect the last invocation
count times. |
IExpectationSetters<Object> |
times(int min,
int max)
Expect the last invocation between
min and max
times. |
void |
verify()
Verifies that all expectations were met and that no unexpected
call was performed.
|
void |
verifyRecording()
Verifies that all expectations were met.
|
void |
verifyUnexpectedCalls()
Verifies that no unexpected call was performed.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmock, mock, mockpublic static final Range ONCE
public static final Range AT_LEAST_ONCE
public static final Range ZERO_OR_MORE
public MocksControl(MockType type)
public MockType getType()
public IMocksControlState getState()
public <T,R> R createMock(Class<T> toMock)
IMocksControlIMocksControl.mock(Class) but using the old naming.createMock in interface IMocksControlT - the interface or class that the mock object should
implement/extend.R - the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the
caller, we return a different typetoMock - the interface or class that the mock object should
implement/extend.public <T,R> R createMock(String name, Class<T> toMock)
IMocksControlIMocksControl.mock(String, Class) but using the old naming.createMock in interface IMocksControlT - the interface or class that the mock object should
implement/extend.R - the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the
caller, we return a different typename - the name of the mock object.toMock - the interface or class that the mock object should
implement/extend.public <T,R> R createMock(String name, Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)
IMocksControlIMocksControl.mock(String, Class, ConstructorArgs, Method...) but using the old namingcreateMock in interface IMocksControlT - the class that the mock object should extend.R - the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the
caller, we return a different typename - the name of the mock object.toMock - the class that the mock object should extend.constructorArgs - constructor and parameters used to instantiate the mock. If null, no constructor will be calledmockedMethods - methods that will be mocked, other methods will behave
normally. If empty, all methods will be mockedpublic static IProxyFactory getProxyFactory(Object o)
public static MocksControl getControl(Object mock)
public static InvocationHandler getInvocationHandler(Object mock)
public static <T,R extends T> Class<R> getMockedClass(T proxy)
T - Mocked classR - Mock classproxy - Mock objectpublic void reset()
IMocksControlreset in interface IMocksControlpublic void resetToNice()
IMocksControlresetToNice in interface IMocksControlpublic void resetToDefault()
IMocksControlresetToDefault in interface IMocksControlpublic void resetToStrict()
IMocksControlresetToStrict in interface IMocksControlpublic void replay()
IMocksControlreplay in interface IMocksControlpublic void verifyRecording()
IMocksControlverifyRecording in interface IMocksControlpublic void verifyUnexpectedCalls()
IMocksControlverifyUnexpectedCalls in interface IMocksControlpublic void verify()
IMocksControlIMocksControl.verifyRecording()
followed by IMocksControl.verifyUnexpectedCalls().verify in interface IMocksControlpublic void checkOrder(boolean value)
IMocksControlcheckOrder in interface IMocksControlvalue - true switches order checking on,
false switches it off.public void makeThreadSafe(boolean threadSafe)
IMocksControlmakeThreadSafe in interface IMocksControlthreadSafe - If the mock should be thread safe or notpublic void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)
IMocksControlcheckIsUsedInOneThread in interface IMocksControlshouldBeUsedInOneThread - If it should be used in one thread only or notpublic IExpectationSetters<Object> andReturn(Object value)
IExpectationSettersandReturn in interface IExpectationSetters<Object>value - the value to return.public IExpectationSetters<Object> andThrow(Throwable throwable)
IExpectationSettersandThrow in interface IExpectationSetters<Object>throwable - the throwable to throw.public IExpectationSetters<Object> andAnswer(IAnswer<?> answer)
IExpectationSettersandAnswer in interface IExpectationSetters<Object>answer - the object used to answer the invocation.public IExpectationSetters<Object> andDelegateTo(Object answer)
IExpectationSettersandDelegateTo in interface IExpectationSetters<Object>answer - the object the call is delegated to.public IExpectationSetters<Object> andVoid()
IExpectationSettersexpectLastCall().andThrow(e).andVoid()andVoid in interface IExpectationSetters<Object>public void andStubReturn(Object value)
IExpectationSettersandStubReturn in interface IExpectationSetters<Object>value - the value to return.public void andStubThrow(Throwable throwable)
IExpectationSettersandStubThrow in interface IExpectationSetters<Object>throwable - the throwable to throw.public void andStubAnswer(IAnswer<?> answer)
IExpectationSettersandStubAnswer in interface IExpectationSetters<Object>answer - the object used to answer the invocation.public void andStubDelegateTo(Object delegateTo)
IExpectationSettersandStubDelegateTo in interface IExpectationSetters<Object>delegateTo - the object the call is delegated to.public void asStub()
IExpectationSettersasStub in interface IExpectationSetters<Object>public IExpectationSetters<Object> times(int times)
IExpectationSetterscount times.times in interface IExpectationSetters<Object>times - the number of invocations expectedpublic IExpectationSetters<Object> times(int min, int max)
IExpectationSettersmin and max
times.times in interface IExpectationSetters<Object>min - the minimum number of invocations expected.max - the maximum number of invocations expected.public IExpectationSetters<Object> once()
IExpectationSettersonce in interface IExpectationSetters<Object>public IExpectationSetters<Object> atLeastOnce()
IExpectationSettersatLeastOnce in interface IExpectationSetters<Object>public IExpectationSetters<Object> anyTimes()
IExpectationSettersanyTimes in interface IExpectationSetters<Object>Copyright © 2001–2024 EasyMock contributors. All rights reserved.