org.easymock

Class MockControl<T>


public class MockControl<T>
extends java.lang.Object

A MockControl object controls the behavior of its associated mock object. For more information, see the EasyMock documentation.

Field Summary

static ArgumentsMatcher
ALWAYS_MATCHER
Matches always.
static 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 appropriate java.util.Arrays.equals() -method.
static ArgumentsMatcher
EQUALS_MATCHER
Matches if each expected argument is equal to the corresponding actual argument.
static Range
ONE
Exactly one call.
static Range
ONE_OR_MORE
One or more calls.
static Range
ZERO_OR_MORE
Zero or more calls.

Constructor Summary

MockControl(MocksControl ctrl, Class toMock)

Method Summary

static
MockControl createControl(Class toMock)
Creates a mock control object for the specified interface.
static
MockControl createNiceControl(Class toMock)
Creates a mock control object for the specified interface.
static
MockControl createStrictControl(Class toMock)
Creates a mock control object for the specified interface.
V2 extends V1> void expectAndDefaultReturn(V1 ignored, V2 value)
Same as MockControl.setDefaultReturnValue(Object).
V2 extends V1> void expectAndReturn(V1 ignored, V2 value)
Same as MockControl.setReturnValue(Object).
V2 extends V1> void expectAndReturn(V1 ignored, V2 value, Range range)
Same as MockControl.setReturnValue(Object, Range).
V2 extends V1> void expectAndReturn(V1 ignored, V2 value, int count)
Same as MockControl.setReturnValue(Object, int).
V2 extends V1> void expectAndReturn(V1 ignored, V2 value, int min, int max)
Same as MockControl.setReturnValue(Object, int, int).
void
expectAndDefaultThrow(Object ignored, Throwable throwable)
Same as MockControl.setDefaultThrowable(Throwable).
void
expectAndReturn(int ignored, int value)
void
expectAndReturn(int ignored, int value, Range range)
void
expectAndReturn(int ignored, int value, int count)
void
expectAndReturn(int ignored, int value, int min, int max)
void
expectAndThrow(Object ignored, Throwable throwable)
Same as MockControl.setThrowable(Throwable).
void
expectAndThrow(Object ignored, Throwable throwable, Range range)
Same as MockControl.setThrowable(Throwable, Range).
void
expectAndThrow(Object ignored, Throwable throwable, int count)
Same as MockControl.setThrowable(Throwable, int).
void
expectAndThrow(Object ignored, Throwable throwable, int min, int max)
Same as MockControl.setThrowable(Throwable, int, int).
T
getMock()
Returns the mock object.
void
replay()
Switches the mock object from record state to replay state.
void
reset()
Resets the mock control and the mock object to the state directly after creation.
void
setDefaultMatcher(ArgumentsMatcher matcher)
Sets the default ArgumentsMatcher for all methods of the mock object.
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.
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.
void
setDefaultVoidCallable()
Records that the mock object will by default allow the last method specified by a method call.
void
setMatcher(ArgumentsMatcher matcher)
Sets the ArgumentsMatcher for the last method called on the mock object.
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.
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.
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.
void
setReturnValue(Object value, int minCount, int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount times, and will react by returning the provided return value.
void
setThrowable(Throwable throwable)
Records that the mock object will expect the last method call once, and will react by throwing the provided Throwable.
void
setThrowable(Throwable throwable, Range range)
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.
void
setThrowable(Throwable throwable, int minCount, int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount times, and will react by throwing the provided Throwable.
void
setVoidCallable()
Records that the mock object will expect the last method call once, and will react by returning silently.
void
setVoidCallable(Range range)
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.
void
setVoidCallable(int minCount, int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount times, and will react by returning silently.
void
verify()
Verifies that all expectations have been met.

Field Details

ALWAYS_MATCHER

public static final ArgumentsMatcher ALWAYS_MATCHER
Matches always.

ARRAY_MATCHER

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 appropriate java.util.Arrays.equals() -method.

EQUALS_MATCHER

public static final ArgumentsMatcher EQUALS_MATCHER
Matches if each expected argument is equal to the corresponding actual argument.

ONE

public static final Range ONE
Exactly one call.

ONE_OR_MORE

public static final Range ONE_OR_MORE
One or more calls.

ZERO_OR_MORE

public static final Range ZERO_OR_MORE
Zero or more calls.

Constructor Details

MockControl

protected MockControl(MocksControl ctrl,
                      Class toMock)

Method Details

MockControl createControl

public static  MockControl createControl(Class toMock)
Creates a mock control object for the specified interface. The MockControl 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 an AssertionError.
Parameters:
toMock - the class of the interface to mock.
Returns:
the mock control.

MockControl createNiceControl

public static  MockControl createNiceControl(Class toMock)
Creates a mock control object for the specified interface. The MockControl 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.

MockControl createStrictControl

public static  MockControl createStrictControl(Class toMock)
Creates a mock control object for the specified interface. The MockControl and its associated mock object will check the order of expected method calls. An unexpected method call on the mock object will lead to an AssertionError.
Parameters:
toMock - the class of the interface to mock.
Returns:
the mock control.

V2 extends V1> void expectAndDefaultReturn

public  void expectAndDefaultReturn(V1 ignored,
                                                       V2 value)
Same as MockControl.setDefaultReturnValue(Object). For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

V2 extends V1> void expectAndReturn

public  void expectAndReturn(V1 ignored,
                                                V2 value)
Same as MockControl.setReturnValue(Object). For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

V2 extends V1> void expectAndReturn

public  void expectAndReturn(V1 ignored,
                                                V2 value,
                                                Range range)
Same as MockControl.setReturnValue(Object, Range). For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

V2 extends V1> void expectAndReturn

public  void expectAndReturn(V1 ignored,
                                                V2 value,
                                                int count)
Same as MockControl.setReturnValue(Object, int). For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

V2 extends V1> void expectAndReturn

public  void expectAndReturn(V1 ignored,
                                                V2 value,
                                                int min,
                                                int max)
Same as MockControl.setReturnValue(Object, int, int). For explanation, see "Convenience Methods for Return Values" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

expectAndDefaultThrow

public void expectAndDefaultThrow(Object ignored,
                                  Throwable throwable)
Same as MockControl.setDefaultThrowable(Throwable). For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

expectAndReturn

public void expectAndReturn(int ignored,
                            int value)

expectAndReturn

public void expectAndReturn(int ignored,
                            int value,
                            Range range)

expectAndReturn

public void expectAndReturn(int ignored,
                            int value,
                            int count)

expectAndReturn

public void expectAndReturn(int ignored,
                            int value,
                            int min,
                            int max)

expectAndThrow

public void expectAndThrow(Object ignored,
                           Throwable throwable)
Same as MockControl.setThrowable(Throwable). For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

expectAndThrow

public void expectAndThrow(Object ignored,
                           Throwable throwable,
                           Range range)
Same as MockControl.setThrowable(Throwable, Range). For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

expectAndThrow

public void expectAndThrow(Object ignored,
                           Throwable throwable,
                           int count)
Same as MockControl.setThrowable(Throwable, int). For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

expectAndThrow

public void expectAndThrow(Object ignored,
                           Throwable throwable,
                           int min,
                           int max)
Same as MockControl.setThrowable(Throwable, int, int). For explanation, see "Convenience Methods for Throwables" in the EasyMock documentation.
Parameters:
ignored - an ignored value.

getMock

public T getMock()
Returns the mock object.
Returns:
the mock object of this control

replay

public void replay()
Switches the mock object from record state to replay state. For more information, see the EasyMock documentation.

reset

public final void reset()
Resets the mock control and the mock object to the state directly after creation.

setDefaultMatcher

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.

setDefaultReturnValue

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.

setDefaultThrowable

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

setDefaultVoidCallable

public void setDefaultVoidCallable()
Records that the mock object will by default allow the last method specified by a method call.

setMatcher

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.

setReturnValue

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.

setReturnValue

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.

setReturnValue

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.

setReturnValue

public void setReturnValue(Object value,
                           int minCount,
                           int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount 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.

setThrowable

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.

setThrowable

public void setThrowable(Throwable throwable,
                         Range range)

setThrowable

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.

setThrowable

public void setThrowable(Throwable throwable,
                         int minCount,
                         int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount 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.

setVoidCallable

public void setVoidCallable()
Records that the mock object will expect the last method call once, and will react by returning silently.

setVoidCallable

public void setVoidCallable(Range range)

setVoidCallable

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.

setVoidCallable

public void setVoidCallable(int minCount,
                            int maxCount)
Records that the mock object will expect the last method call between minCount and maxCount 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.

verify

public void verify()
Verifies that all expectations have been met. For more information, see the EasyMock documentation.