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)
IMocksControlcreateMock in interface IMocksControlT - 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)
IMocksControlcreateMock in interface IMocksControlT - 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)
IMocksControlcreateMock in interface IMocksControlT - 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)
IMocksControlcreateMock in interface IMocksControlT - 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)
IMocksControlcreateMock in interface IMocksControlT - 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)
IMocksControlcreateMock in interface IMocksControlT - 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()
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 verify()
IMocksControlverify 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<? extends Object> 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()
IExpectationSetters
expectLastCall().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<? extends Object> 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–2014 EasyMock contributors. All rights reserved.