public class MocksControl extends Object implements IMocksControl, IExpectationSetters<Object>, Serializable
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, wait
mock, mock, mock
public 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)
IMocksControl
IMocksControl.mock(Class)
but using the old naming.createMock
in interface IMocksControl
T
- 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)
IMocksControl
IMocksControl.mock(String, Class)
but using the old naming.createMock
in interface IMocksControl
T
- 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)
IMocksControl
IMocksControl.mock(String, Class, ConstructorArgs, Method...)
but using the old namingcreateMock
in interface IMocksControl
T
- 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()
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 verifyRecording()
IMocksControl
verifyRecording
in interface IMocksControl
public void verifyUnexpectedCalls()
IMocksControl
verifyUnexpectedCalls
in interface IMocksControl
public void verify()
IMocksControl
IMocksControl.verifyRecording()
followed by IMocksControl.verifyUnexpectedCalls()
.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<Object> andReturn(Object value)
IExpectationSetters
andReturn
in interface IExpectationSetters<Object>
value
- the value to return.public IExpectationSetters<Object> andThrow(Throwable throwable)
IExpectationSetters
andThrow
in interface IExpectationSetters<Object>
throwable
- the throwable to throw.public IExpectationSetters<Object> andAnswer(IAnswer<?> answer)
IExpectationSetters
andAnswer
in interface IExpectationSetters<Object>
answer
- the object used to answer the invocation.public IExpectationSetters<Object> andDelegateTo(Object answer)
IExpectationSetters
andDelegateTo
in interface IExpectationSetters<Object>
answer
- the object the call is delegated to.public IExpectationSetters<Object> andVoid()
IExpectationSetters
expectLastCall().andThrow(e).andVoid()
andVoid
in interface IExpectationSetters<Object>
public void andStubReturn(Object value)
IExpectationSetters
andStubReturn
in interface IExpectationSetters<Object>
value
- the value to return.public void andStubThrow(Throwable throwable)
IExpectationSetters
andStubThrow
in interface IExpectationSetters<Object>
throwable
- the throwable to throw.public void andStubAnswer(IAnswer<?> answer)
IExpectationSetters
andStubAnswer
in interface IExpectationSetters<Object>
answer
- the object used to answer the invocation.public void andStubDelegateTo(Object delegateTo)
IExpectationSetters
andStubDelegateTo
in interface IExpectationSetters<Object>
delegateTo
- the object the call is delegated to.public void asStub()
IExpectationSetters
asStub
in interface IExpectationSetters<Object>
public IExpectationSetters<Object> times(int times)
IExpectationSetters
count
times.times
in interface IExpectationSetters<Object>
times
- the number of invocations expectedpublic IExpectationSetters<Object> times(int min, int max)
IExpectationSetters
min
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()
IExpectationSetters
once
in interface IExpectationSetters<Object>
public IExpectationSetters<Object> atLeastOnce()
IExpectationSetters
atLeastOnce
in interface IExpectationSetters<Object>
public IExpectationSetters<Object> anyTimes()
IExpectationSetters
anyTimes
in interface IExpectationSetters<Object>
Copyright © 2001–2022 EasyMock contributors. All rights reserved.