public class MocksControl extends Object implements IMocksControl, IExpectationSetters<Object>, Serializable
Modifier and Type | Class and Description |
---|---|
static class |
MocksControl.MockType
Deprecated.
Use org.easymock.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) |
MocksControl(MockType type) |
Modifier and Type | Method and Description |
---|---|
IExpectationSetters<Object> |
andAnswer(IAnswer<? extends 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<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<? extends 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(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> T |
createMock(Class<T> toMock)
Creates a mock object that implements the given interface.
|
<T> T |
createMock(Class<T> toMock,
ConstructorArgs constructorArgs,
Method... mockedMethods)
Deprecated.
|
<T> T |
createMock(Class<T> toMock,
Method... mockedMethods)
Deprecated.
|
<T> T |
createMock(String name,
Class<T> toMock)
Creates a mock object that implements the given interface.
|
<T> T |
createMock(String name,
Class<T> toMock,
ConstructorArgs constructorArgs,
Method... mockedMethods)
Deprecated.
|
<T> T |
createMock(String name,
Class<T> toMock,
Method... mockedMethods)
Deprecated.
|
static MocksControl |
getControl(Object mock) |
static InvocationHandler |
getInvocationHandler(Object mock) |
static <T,V extends T> |
getMockedType(V 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.
|
public static final Range ONCE
public static final Range AT_LEAST_ONCE
public static final Range ZERO_OR_MORE
public MocksControl(MockType type)
public MocksControl(MocksControl.MockType type)
public MockType getType()
public IMocksControlState getState()
public <T> T createMock(Class<T> toMock)
IMocksControl
createMock
in interface IMocksControl
T
- the interface or class that the mock object should
implement/extend.toMock
- the interface or class that the mock object should
implement/extend.public <T> T createMock(String name, Class<T> toMock)
IMocksControl
createMock
in interface IMocksControl
T
- the interface or class that the mock object should
implement/extend.name
- the name of the mock object.toMock
- the interface or class that the mock object should
implement/extend.@Deprecated public <T> T createMock(String name, Class<T> toMock, Method... mockedMethods)
IMocksControl
createMock
in interface IMocksControl
T
- the class that the mock object should extend.name
- the name of the mock object.toMock
- the class that the mock object should extend.mockedMethods
- methods that will be mocked, other methods will behave
normally@Deprecated public <T> T createMock(Class<T> toMock, Method... mockedMethods)
IMocksControl
createMock
in interface IMocksControl
T
- the class that the mock object should extend.toMock
- the class that the mock object should extend.mockedMethods
- methods that will be mocked, other methods will behave
normally@Deprecated public <T> T createMock(Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)
IMocksControl
createMock
in interface IMocksControl
T
- the class that the mock object should extend.toMock
- the class that the mock object should extend.constructorArgs
- constructor and parameters used to instantiate the mock.mockedMethods
- methods that will be mocked, other methods will behave
normally@Deprecated public <T> T createMock(String name, Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)
IMocksControl
createMock
in interface IMocksControl
T
- the class that the mock object should extend.name
- the name of the mock object.toMock
- the class that the mock object should extend.constructorArgs
- constructor and parameters used to instantiate the mock.mockedMethods
- methods that will be mocked, other methods will behave
normallypublic static IProxyFactory getProxyFactory(Object o)
public static MocksControl getControl(Object mock)
public static InvocationHandler getInvocationHandler(Object mock)
public static <T,V extends T> Class<T> getMockedType(V proxy)
T
- Mocked classV
- Mock classproxy
- Mock objectpublic 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<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<? extends Object> 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<? extends Object> 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–2015 EasyMock contributors. All rights reserved.