Top Description Fields Constructors Methods
org.easymock.internal

public Class MocksControl

extends Object
implements IMocksControl, IExpectationSetters<Object>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.easymock.IExpectationSetters, org.easymock.IMocksControl
Imports
org.easymock.ConstructorArgs, .EasyMock, .EasyMockSupport, .IAnswer, .IExpectationSetters, .IMocksControl, .MockType, java.io.Serializable, java.lang.reflect.InvocationHandler, .Method, .Proxy, java.util.Arrays, .Set

Controls all the mocks created by EasyMock. It contains the state of the mocks.
Author
OFFIS, Tammo Freese

Field Summary

Modifier and TypeField and Description
public static final Range
AT_LEAST_ONCE

One or more calls.

private IMocksBehavior
private static volatile IProxyFactory
classProxyFactory

lazily created; the proxy factory for classes

private static final IProxyFactory
public static final Range
ONCE

Exactly one call.

private static final long
private IMocksControlState
private MockType
public static final Range
ZERO_OR_MORE

Zero or more calls.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public IExpectationSetters<Object>
andAnswer(IAnswer<?>
the object used to answer the invocation.
answer
)

Implements org.easymock.IExpectationSetters.andAnswer.

Sets an object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
public IExpectationSetters<Object>
andDelegateTo(Object
the object the call is delegated to.
answer
)

Implements org.easymock.IExpectationSetters.andDelegateTo.

Sets an object implementing the same interface as the mock.
public IExpectationSetters<Object>
andReturn(Object
the value to return.
value
)

Implements org.easymock.IExpectationSetters.andReturn.

Sets a return value that will be returned for the expected invocation.
public void
andStubAnswer(IAnswer<?>
the object used to answer the invocation.
answer
)

Implements org.easymock.IExpectationSetters.andStubAnswer.

Sets a stub object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
public void
andStubDelegateTo(Object
the object the call is delegated to.
delegateTo
)

Implements org.easymock.IExpectationSetters.andStubDelegateTo.

Sets a stub object implementing the same interface as the mock.
public void
andStubReturn(Object
the value to return.
value
)

Implements org.easymock.IExpectationSetters.andStubReturn.

Sets a stub return value that will be returned for the expected invocation.
public void
andStubThrow(Throwable
the throwable to throw.
throwable
)

Implements org.easymock.IExpectationSetters.andStubThrow.

Sets a stub throwable that will be thrown for the expected invocation.
public IExpectationSetters<Object>
andThrow(Throwable
the throwable to throw.
throwable
)

Implements org.easymock.IExpectationSetters.andThrow.

Sets a throwable that will be thrown for the expected invocation.
public IExpectationSetters<Object>
andVoid()

Implements org.easymock.IExpectationSetters.andVoid.

Records a call but returns nothing.
public IExpectationSetters<Object>
anyTimes()

Implements org.easymock.IExpectationSetters.anyTimes.

Expect the last invocation any times.
public void
asStub()

Implements org.easymock.IExpectationSetters.asStub.

Sets stub behavior for the expected invocation (this is needed for void methods).
public IExpectationSetters<Object>
atLeastOnce()

Implements org.easymock.IExpectationSetters.atLeastOnce.

Expect the last invocation at least once.
private <T> void
public void
checkIsUsedInOneThread(boolean
If it should be used in one thread only or not
shouldBeUsedInOneThread
)

Implements org.easymock.IMocksControl.checkIsUsedInOneThread.

Check that the mock is called from only one thread
public void
checkOrder(boolean
true switches order checking on, false switches it off.
value
)

Implements org.easymock.IMocksControl.checkOrder.

Switches order checking on and off.
public <T, R> R
createMock(Class<T>
the interface or class that the mock object should implement/extend.
toMock
)

Implements org.easymock.IMocksControl.createMock.

Same as mock(Class) but using the old naming.
public <T, R> R
createMock(String
the name of the mock object.
name
,
Class<T>
the interface or class that the mock object should implement/extend.
toMock
)

Implements org.easymock.IMocksControl.createMock.

Same as mock(String, Class) but using the old naming.
public <T, R> R
createMock(String
the name of the mock object.
name
,
Class<T>
the class that the mock object should extend.
toMock
,
ConstructorArgs
constructor and parameters used to instantiate the mock. If null, no constructor will be called
constructorArgs
,
Method...
methods that will be mocked, other methods will behave normally. If empty, all methods will be mocked
mockedMethods
)

Implements org.easymock.IMocksControl.createMock.

Same as mock(String, Class, ConstructorArgs, Method...) but using the old naming
private static IProxyFactory
public static MocksControl
public static InvocationHandler
public static <
Mocked class
T
,
Mock class
R extends T
>
Class<R>

Returns:

the mocked class or interface
getMockedClass
(T
Mock object
proxy
)

Return the class of interface (depending on the mock type) that was mocked

public static IProxyFactory
public IMocksControlState
public MockType
public void
makeThreadSafe(boolean
If the mock should be thread safe or not
threadSafe
)

Implements org.easymock.IMocksControl.makeThreadSafe.

Makes the mock thread safe.
public IExpectationSetters<Object>
once()

Implements org.easymock.IExpectationSetters.once.

Expect the last invocation once.
public void
replay()

Implements org.easymock.IMocksControl.replay.

Switches the control from record mode to replay mode.
public void
reset()

Implements org.easymock.IMocksControl.reset.

Removes all expectations for the mock objects of this control.
public void
resetToDefault()

Implements org.easymock.IMocksControl.resetToDefault.

Removes all expectations for the mock objects of this control and turn them to default mocks.
public void
resetToNice()

Implements org.easymock.IMocksControl.resetToNice.

Removes all expectations for the mock objects of this control and turn them to nice mocks.
public void
resetToStrict()

Implements org.easymock.IMocksControl.resetToStrict.

Removes all expectations for the mock objects of this control and turn them to strict mocks.
public IExpectationSetters<Object>
times(int
the number of invocations expected
times
)

Implements org.easymock.IExpectationSetters.times.

Expect the last invocation count times.
public IExpectationSetters<Object>
times(int
the minimum number of invocations expected.
min
,
int
the maximum number of invocations expected.
max
)

Implements org.easymock.IExpectationSetters.times.

Expect the last invocation between min and max times.
public void
verify()

Implements org.easymock.IMocksControl.verify.

Verifies that all expectations were met and that no unexpected call was performed.
public void
verifyRecording()

Implements org.easymock.IMocksControl.verifyRecording.

Verifies that all expectations were met.
public void
verifyUnexpectedCalls()

Implements org.easymock.IMocksControl.verifyUnexpectedCalls.

Verifies that no unexpected call was performed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AT_LEAST_ONCEback to summary
public static final Range AT_LEAST_ONCE

One or more calls.

behaviorback to summary
private IMocksBehavior behavior
classProxyFactoryback to summary
private static volatile IProxyFactory classProxyFactory

lazily created; the proxy factory for classes

interfaceProxyFactoryback to summary
private static final IProxyFactory interfaceProxyFactory
ONCEback to summary
public static final Range ONCE

Exactly one call.

serialVersionUIDback to summary
private static final long serialVersionUID
stateback to summary
private IMocksControlState state
typeback to summary
private MockType type
ZERO_OR_MOREback to summary
public static final Range ZERO_OR_MORE

Zero or more calls.

Constructor Detail

MocksControlback to summary
public MocksControl(MockType type)

Method Detail

andAnswerback to summary
public IExpectationSetters<Object> andAnswer(IAnswer<?> answer)

Implements org.easymock.IExpectationSetters.andAnswer.

Doc from org.easymock.IExpectationSetters.andAnswer.

Sets an object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).

Parameters
answer:IAnswer<?>

the object used to answer the invocation.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
andDelegateToback to summary
public IExpectationSetters<Object> andDelegateTo(Object answer)

Implements org.easymock.IExpectationSetters.andDelegateTo.

Doc from org.easymock.IExpectationSetters.andDelegateTo.

Sets an object implementing the same interface as the mock. The expected method call will be delegated to it with the actual arguments. The answer returned by this call will then be the answer returned by the mock (either return a value, or throw an exception).

Parameters
answer:Object

the object the call is delegated to.

Returns:IExpectationSetters<Object>

the value returned by the delegated call.

Annotations
@Override
andReturnback to summary
public IExpectationSetters<Object> andReturn(Object value)

Implements org.easymock.IExpectationSetters.andReturn.

Doc from org.easymock.IExpectationSetters.andReturn.

Sets a return value that will be returned for the expected invocation.

Parameters
value:Object

the value to return.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
andStubAnswerback to summary
public void andStubAnswer(IAnswer<?> answer)

Implements org.easymock.IExpectationSetters.andStubAnswer.

Doc from org.easymock.IExpectationSetters.andStubAnswer.

Sets a stub object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).

Parameters
answer:IAnswer<?>

the object used to answer the invocation.

Annotations
@Override
andStubDelegateToback to summary
public void andStubDelegateTo(Object delegateTo)

Implements org.easymock.IExpectationSetters.andStubDelegateTo.

Doc from org.easymock.IExpectationSetters.andStubDelegateTo.

Sets a stub object implementing the same interface as the mock. The expected method call will be delegated to it with the actual arguments. The answer returned by this call will then be the answer returned by the mock (either return a value, or throw an exception).

Parameters
delegateTo:Object

the object the call is delegated to.

Annotations
@Override
andStubReturnback to summary
public void andStubReturn(Object value)

Implements org.easymock.IExpectationSetters.andStubReturn.

Doc from org.easymock.IExpectationSetters.andStubReturn.

Sets a stub return value that will be returned for the expected invocation.

Parameters
value:Object

the value to return.

Annotations
@Override
andStubThrowback to summary
public void andStubThrow(Throwable throwable)

Implements org.easymock.IExpectationSetters.andStubThrow.

Doc from org.easymock.IExpectationSetters.andStubThrow.

Sets a stub throwable that will be thrown for the expected invocation.

Parameters
throwable:Throwable

the throwable to throw.

Annotations
@Override
andThrowback to summary
public IExpectationSetters<Object> andThrow(Throwable throwable)

Implements org.easymock.IExpectationSetters.andThrow.

Doc from org.easymock.IExpectationSetters.andThrow.

Sets a throwable that will be thrown for the expected invocation.

Parameters
throwable:Throwable

the throwable to throw.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
andVoidback to summary
public IExpectationSetters<Object> andVoid()

Implements org.easymock.IExpectationSetters.andVoid.

Doc from org.easymock.IExpectationSetters.andVoid.

Records a call but returns nothing. Used to chain calls on void methods expectLastCall().andThrow(e).andVoid()

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
anyTimesback to summary
public IExpectationSetters<Object> anyTimes()

Implements org.easymock.IExpectationSetters.anyTimes.

Doc from org.easymock.IExpectationSetters.anyTimes.

Expect the last invocation any times.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
asStubback to summary
public void asStub()

Implements org.easymock.IExpectationSetters.asStub.

Doc from org.easymock.IExpectationSetters.asStub.

Sets stub behavior for the expected invocation (this is needed for void methods).

Annotations
@Override
atLeastOnceback to summary
public IExpectationSetters<Object> atLeastOnce()

Implements org.easymock.IExpectationSetters.atLeastOnce.

Doc from org.easymock.IExpectationSetters.atLeastOnce.

Expect the last invocation at least once.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
checkInterfaceHasDefaultMethodAndIsMockingOnlyThemback to summary
private <T> void checkInterfaceHasDefaultMethodAndIsMockingOnlyThem(Class<T> toMock, Method[] mockedMethods)
checkIsUsedInOneThreadback to summary
public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)

Implements org.easymock.IMocksControl.checkIsUsedInOneThread.

Doc from org.easymock.IMocksControl.checkIsUsedInOneThread.

Check that the mock is called from only one thread

Parameters
shouldBeUsedInOneThread:boolean

If it should be used in one thread only or not

Annotations
@Override
checkOrderback to summary
public void checkOrder(boolean value)

Implements org.easymock.IMocksControl.checkOrder.

Doc from org.easymock.IMocksControl.checkOrder.

Switches order checking on and off.

Parameters
value:boolean

true switches order checking on, false switches it off.

Annotations
@Override
createMockback to summary
public <T, R> R createMock(Class<T> toMock)

Implements org.easymock.IMocksControl.createMock.

Doc from org.easymock.IMocksControl.createMock.

Same as mock(Class) but using the old naming.

Parameters
<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 type
toMock:Class<T>

the interface or class that the mock object should implement/extend.

Returns:R

the mock object.

Annotations
@Override
createMockback to summary
public <T, R> R createMock(String name, Class<T> toMock)

Implements org.easymock.IMocksControl.createMock.

Doc from org.easymock.IMocksControl.createMock.

Same as mock(String, Class) but using the old naming.

Parameters
<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 type
name:String

the name of the mock object.

toMock:Class<T>

the interface or class that the mock object should implement/extend.

Returns:R

the mock object.

Annotations
@Override
createMockback to summary
public <T, R> R createMock(String name, Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)

Implements org.easymock.IMocksControl.createMock.

Doc from org.easymock.IMocksControl.createMock.

Same as mock(String, Class, ConstructorArgs, Method...) but using the old naming

Parameters
<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 type
name:String

the name of the mock object.

toMock:Class<T>

the class that the mock object should extend.

constructorArgs:ConstructorArgs

constructor and parameters used to instantiate the mock. If null, no constructor will be called

mockedMethods:Method[]

methods that will be mocked, other methods will behave normally. If empty, all methods will be mocked

Returns:R

the mock object.

Annotations
@Override
getClassProxyFactoryback to summary
private static IProxyFactory getClassProxyFactory()
getControlback to summary
public static MocksControl getControl(Object mock)
getInvocationHandlerback to summary
public static InvocationHandler getInvocationHandler(Object mock)
getMockedClassback to summary
public static <T, R extends T> Class<R> getMockedClass(T proxy)

Return the class of interface (depending on the mock type) that was mocked

Parameters
<T>
Mocked class
<R>
Mock class
proxy:T

Mock object

Returns:Class<R>

the mocked class or interface

Annotations
@SuppressWarnings:unchecked
getProxyFactoryback to summary
public static IProxyFactory getProxyFactory(Object o)
getStateback to summary
public IMocksControlState getState()
getTypeback to summary
public MockType getType()
makeThreadSafeback to summary
public void makeThreadSafe(boolean threadSafe)

Implements org.easymock.IMocksControl.makeThreadSafe.

Doc from org.easymock.IMocksControl.makeThreadSafe.

Makes the mock thread safe.

Parameters
threadSafe:boolean

If the mock should be thread safe or not

Annotations
@Override
onceback to summary
public IExpectationSetters<Object> once()

Implements org.easymock.IExpectationSetters.once.

Doc from org.easymock.IExpectationSetters.once.

Expect the last invocation once. This is default in EasyMock.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
replayback to summary
public void replay()

Implements org.easymock.IMocksControl.replay.

Doc from org.easymock.IMocksControl.replay.

Switches the control from record mode to replay mode.

Annotations
@Override
resetback to summary
public void reset()

Implements org.easymock.IMocksControl.reset.

Doc from org.easymock.IMocksControl.reset.

Removes all expectations for the mock objects of this control.

Annotations
@Override
resetToDefaultback to summary
public void resetToDefault()

Implements org.easymock.IMocksControl.resetToDefault.

Doc from org.easymock.IMocksControl.resetToDefault.

Removes all expectations for the mock objects of this control and turn them to default mocks.

Annotations
@Override
resetToNiceback to summary
public void resetToNice()

Implements org.easymock.IMocksControl.resetToNice.

Doc from org.easymock.IMocksControl.resetToNice.

Removes all expectations for the mock objects of this control and turn them to nice mocks.

Annotations
@Override
resetToStrictback to summary
public void resetToStrict()

Implements org.easymock.IMocksControl.resetToStrict.

Doc from org.easymock.IMocksControl.resetToStrict.

Removes all expectations for the mock objects of this control and turn them to strict mocks.

Annotations
@Override
timesback to summary
public IExpectationSetters<Object> times(int times)

Implements org.easymock.IExpectationSetters.times.

Doc from org.easymock.IExpectationSetters.times.

Expect the last invocation count times.

Parameters
times:int

the number of invocations expected

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
timesback to summary
public IExpectationSetters<Object> times(int min, int max)

Implements org.easymock.IExpectationSetters.times.

Doc from org.easymock.IExpectationSetters.times.

Expect the last invocation between min and max times.

Parameters
min:int

the minimum number of invocations expected.

max:int

the maximum number of invocations expected.

Returns:IExpectationSetters<Object>

this object to allow method call chaining.

Annotations
@Override
verifyback to summary
public void verify()

Implements org.easymock.IMocksControl.verify.

Doc from org.easymock.IMocksControl.verify.

Verifies that all expectations were met and that no unexpected call was performed. It has the same effect as calling verifyRecording() followed by verifyUnexpectedCalls().

Annotations
@Override
verifyRecordingback to summary
public void verifyRecording()

Implements org.easymock.IMocksControl.verifyRecording.

Doc from org.easymock.IMocksControl.verifyRecording.

Verifies that all expectations were met.

Annotations
@Override
verifyUnexpectedCallsback to summary
public void verifyUnexpectedCalls()

Implements org.easymock.IMocksControl.verifyUnexpectedCalls.

Doc from org.easymock.IMocksControl.verifyUnexpectedCalls.

Verifies that no unexpected call was performed.

Annotations
@Override