Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.easymock.MockControl<T>
public class MockControl<T>
extends java.lang.Object
MockControl
object controls the behavior of its associated
mock object. For more information, see the EasyMock documentation.
Field Summary | |
static ArgumentsMatcher |
|
static ArgumentsMatcher |
|
static ArgumentsMatcher |
|
static Range |
|
static Range |
|
static Range |
|
Constructor Summary | |
|
Method Summary | |
static |
|
static |
|
static |
|
|
|
|
|
|
|
|
|
|
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
T |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
public static final ArgumentsMatcher ALWAYS_MATCHER
Matches always.
public static final ArgumentsMatcher ARRAY_MATCHER
Matches if each expected argument is equal to the corresponding actual argument for non-array arguments; array arguments are compared with the appropriatejava.util.Arrays.equals()
-method.
public static final ArgumentsMatcher EQUALS_MATCHER
Matches if each expected argument is equal to the corresponding actual argument.
public static final Range ONE
Exactly one call.
public static final Range ONE_OR_MORE
One or more calls.
public static final Range ZERO_OR_MORE
Zero or more calls.
public staticMockControl createControl(Class toMock)
Creates a mock control object for the specified interface. TheMockControl
and its associated mock object will not check the order of expected method calls. An unexpected method call on the mock object will lead to anAssertionError
.
- Parameters:
toMock
- the class of the interface to mock.
- Returns:
- the mock control.
public staticMockControl createNiceControl(Class toMock)
Creates a mock control object for the specified interface. TheMockControl
and its associated mock object will not check the order of expected method calls. An unexpected method call on the mock object will return an empty value (0, null, false).
- Parameters:
toMock
- the class of the interface to mock.
- Returns:
- the mock control.
public staticMockControl createStrictControl(Class toMock)
Creates a mock control object for the specified interface. TheMockControl
and its associated mock object will check the order of expected method calls. An unexpected method call on the mock object will lead to anAssertionError
.
- Parameters:
toMock
- the class of the interface to mock.
- Returns:
- the mock control.
publicvoid expectAndDefaultReturn(V1 ignored, V2 value)
Same asMockControl.setDefaultReturnValue(Object)
. For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
publicvoid expectAndReturn(V1 ignored, V2 value)
Same asMockControl.setReturnValue(Object)
. For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
publicvoid expectAndReturn(V1 ignored, V2 value, Range range)
Same asMockControl.setReturnValue(Object, Range)
. For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
publicvoid expectAndReturn(V1 ignored, V2 value, int count)
Same asMockControl.setReturnValue(Object, int)
. For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
publicvoid expectAndReturn(V1 ignored, V2 value, int min, int max)
Same asMockControl.setReturnValue(Object, int, int)
. For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public void expectAndDefaultThrow(Object ignored, Throwable throwable)
Same asMockControl.setDefaultThrowable(Throwable)
. For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public void expectAndReturn(int ignored, int value)
public void expectAndReturn(int ignored, int value, Range range)
public void expectAndReturn(int ignored, int value, int count)
public void expectAndReturn(int ignored, int value, int min, int max)
public void expectAndThrow(Object ignored, Throwable throwable)
Same asMockControl.setThrowable(Throwable)
. For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public void expectAndThrow(Object ignored, Throwable throwable, Range range)
Same asMockControl.setThrowable(Throwable, Range)
. For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public void expectAndThrow(Object ignored, Throwable throwable, int count)
Same asMockControl.setThrowable(Throwable, int)
. For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public void expectAndThrow(Object ignored, Throwable throwable, int min, int max)
Same asMockControl.setThrowable(Throwable, int, int)
. For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
- Parameters:
ignored
- an ignored value.
public T getMock()
Returns the mock object.
- Returns:
- the mock object of this control
public void replay()
Switches the mock object from record state to replay state. For more information, see the EasyMock documentation.
public final void reset()
Resets the mock control and the mock object to the state directly after creation.
public void setDefaultMatcher(ArgumentsMatcher matcher)
Sets the default ArgumentsMatcher for all methods of the mock object. The matcher must be set before any behavior is defined on the mock object.
public void setDefaultReturnValue(Object value)
Records that the mock object will by default allow the last method specified by a method call, and will react by returning the provided return value.
- Parameters:
value
- the return value.
public void setDefaultThrowable(Throwable throwable)
Records that the mock object will by default allow the last method specified by a method call, and will react by throwing the provided Throwable.
- Parameters:
throwable
- throwable the throwable to be thrown
public void setDefaultVoidCallable()
Records that the mock object will by default allow the last method specified by a method call.
public void setMatcher(ArgumentsMatcher matcher)
Sets the ArgumentsMatcher for the last method called on the mock object. The matcher must be set before any behavior for the method is defined.
public void setReturnValue(Object value)
Records that the mock object will expect the last method call once, and will react by returning the provided return value.
- Parameters:
value
- the return value.
public void setReturnValue(Object value, Range range)
Records that the mock object will expect the last method call a fixed number of times, and will react by returning the provided return value.
- Parameters:
value
- the return value.range
- the number of times that the call is expected.
public void setReturnValue(Object value, int times)
Records that the mock object will expect the last method call a fixed number of times, and will react by returning the provided return value.
- Parameters:
value
- the return value.times
- the number of times that the call is expected.
public void setReturnValue(Object value, int minCount, int maxCount)
Records that the mock object will expect the last method call betweenminCount
andmaxCount
times, and will react by returning the provided return value.
- Parameters:
value
- the return value.minCount
- the minimum number of times that the call is expected.maxCount
- the maximum number of times that the call is expected.
public void setThrowable(Throwable throwable)
Records that the mock object will expect the last method call once, and will react by throwing the provided Throwable.
- Parameters:
throwable
- the Throwable to throw.
public void setThrowable(Throwable throwable, Range range)
public void setThrowable(Throwable throwable, int times)
Records that the mock object will expect the last method call a fixed number of times, and will react by throwing the provided Throwable.
- Parameters:
throwable
- the Throwable to throw.times
- the number of times that the call is expected.
public void setThrowable(Throwable throwable, int minCount, int maxCount)
Records that the mock object will expect the last method call betweenminCount
andmaxCount
times, and will react by throwing the provided Throwable.
- Parameters:
throwable
- the Throwable to throw.minCount
- the minimum number of times that the call is expected.maxCount
- the maximum number of times that the call is expected.
public void setVoidCallable()
Records that the mock object will expect the last method call once, and will react by returning silently.
public void setVoidCallable(Range range)
public void setVoidCallable(int times)
Records that the mock object will expect the last method call a fixed number of times, and will react by returning silently.
- Parameters:
times
- the number of times that the call is expected.
public void setVoidCallable(int minCount, int maxCount)
Records that the mock object will expect the last method call betweenminCount
andmaxCount
times, and will react by returning silently.
- Parameters:
minCount
- the minimum number of times that the call is expected.maxCount
- the maximum number of times that the call is expected.
public void verify()
Verifies that all expectations have been met. For more information, see the EasyMock documentation.