T
- type of the mock controlledEasyMock
are
used to create and control mock objects.@Deprecated
public class MockControl<T>
extends java.lang.Object
implements java.io.Serializable
MockControl
object controls the behavior of its associated
mock object. For more information, see the EasyMock documentation.Modifier and Type | Field and Description |
---|---|
static ArgumentsMatcher |
ALWAYS_MATCHER
Deprecated.
Matches always.
|
static ArgumentsMatcher |
ARRAY_MATCHER
Deprecated.
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
Deprecated.
Matches if each expected argument is equal to the corresponding actual
argument.
|
static Range |
ONE
Deprecated.
Exactly one call.
|
static Range |
ONE_OR_MORE
Deprecated.
One or more calls.
|
static Range |
ZERO_OR_MORE
Deprecated.
Zero or more calls.
|
Modifier | Constructor and Description |
---|---|
protected |
MockControl(MocksControl ctrl,
java.lang.Class<T> toMock)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static <T> MockControl<T> |
createControl(java.lang.Class<T> toMock)
Deprecated.
Creates a mock control object for the specified interface.
|
static <T> MockControl<T> |
createNiceControl(java.lang.Class<T> toMock)
Deprecated.
Creates a mock control object for the specified interface.
|
static <T> MockControl<T> |
createStrictControl(java.lang.Class<T> toMock)
Deprecated.
Creates a mock control object for the specified interface.
|
<V1,V2 extends V1> |
expectAndDefaultReturn(V1 ignored,
V2 value)
Deprecated.
Same as
setDefaultReturnValue(Object) . |
void |
expectAndDefaultThrow(java.lang.Object ignored,
java.lang.Throwable throwable)
Deprecated.
Same as
setDefaultThrowable(Throwable) . |
void |
expectAndReturn(int ignored,
int value)
Deprecated.
|
void |
expectAndReturn(int ignored,
int value,
int count)
Deprecated.
|
void |
expectAndReturn(int ignored,
int value,
int min,
int max)
Deprecated.
|
void |
expectAndReturn(int ignored,
int value,
Range range)
Deprecated.
|
<V1,V2 extends V1> |
expectAndReturn(V1 ignored,
V2 value)
Deprecated.
Same as
setReturnValue(Object) . |
<V1,V2 extends V1> |
expectAndReturn(V1 ignored,
V2 value,
int count)
Deprecated.
Same as
setReturnValue(Object, int) . |
<V1,V2 extends V1> |
expectAndReturn(V1 ignored,
V2 value,
int min,
int max)
Deprecated.
Same as
setReturnValue(Object, int, int) . |
<V1,V2 extends V1> |
expectAndReturn(V1 ignored,
V2 value,
Range range)
Deprecated.
Same as
setReturnValue(Object, Range) . |
void |
expectAndThrow(java.lang.Object ignored,
java.lang.Throwable throwable)
Deprecated.
Same as
setThrowable(Throwable) . |
void |
expectAndThrow(java.lang.Object ignored,
java.lang.Throwable throwable,
int count)
Deprecated.
Same as
setThrowable(Throwable, int) . |
void |
expectAndThrow(java.lang.Object ignored,
java.lang.Throwable throwable,
int min,
int max)
Deprecated.
Same as
setThrowable(Throwable, int, int) . |
void |
expectAndThrow(java.lang.Object ignored,
java.lang.Throwable throwable,
Range range)
Deprecated.
Same as
setThrowable(Throwable, Range) . |
T |
getMock()
Deprecated.
Returns the mock object.
|
void |
replay()
Deprecated.
Switches the mock object from record state to replay state.
|
void |
reset()
Deprecated.
Resets the mock control and the mock object to the state directly after
creation.
|
void |
setDefaultMatcher(ArgumentsMatcher matcher)
Deprecated.
Sets the default ArgumentsMatcher for all methods of the mock object.
|
void |
setDefaultReturnValue(java.lang.Object value)
Deprecated.
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(java.lang.Throwable throwable)
Deprecated.
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()
Deprecated.
Records that the mock object will by default allow the last method
specified by a method call.
|
void |
setMatcher(ArgumentsMatcher matcher)
Deprecated.
Sets the ArgumentsMatcher for the last method called on the mock object.
|
void |
setReturnValue(java.lang.Object value)
Deprecated.
Records that the mock object will expect the last method call once, and
will react by returning the provided return value.
|
void |
setReturnValue(java.lang.Object value,
int times)
Deprecated.
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(java.lang.Object value,
int minCount,
int maxCount)
Deprecated.
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 |
setReturnValue(java.lang.Object value,
Range range)
Deprecated.
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 |
setThrowable(java.lang.Throwable throwable)
Deprecated.
Records that the mock object will expect the last method call once, and
will react by throwing the provided Throwable.
|
void |
setThrowable(java.lang.Throwable throwable,
int times)
Deprecated.
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(java.lang.Throwable throwable,
int minCount,
int maxCount)
Deprecated.
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 |
setThrowable(java.lang.Throwable throwable,
Range range)
Deprecated.
|
void |
setVoidCallable()
Deprecated.
Records that the mock object will expect the last method call once, and
will react by returning silently.
|
void |
setVoidCallable(int times)
Deprecated.
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)
Deprecated.
Records that the mock object will expect the last method call between
minCount and maxCount times, and will react
by returning silently. |
void |
setVoidCallable(Range range)
Deprecated.
|
void |
verify()
Deprecated.
Verifies that all expectations have been met.
|
public static final Range ONE
public static final Range ONE_OR_MORE
public static final Range ZERO_OR_MORE
public static final ArgumentsMatcher EQUALS_MATCHER
public static final ArgumentsMatcher ALWAYS_MATCHER
public static final ArgumentsMatcher ARRAY_MATCHER
java.util.Arrays.equals()
-method.protected MockControl(MocksControl ctrl, java.lang.Class<T> toMock)
public static <T> MockControl<T> createControl(java.lang.Class<T> toMock)
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
.T
- type of the mock controlledtoMock
- the class of the interface to mock.public static <T> MockControl<T> createStrictControl(java.lang.Class<T> toMock)
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
.T
- type of the mock controlledtoMock
- the class of the interface to mock.public static <T> MockControl<T> createNiceControl(java.lang.Class<T> toMock)
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).T
- type of the mock controlledtoMock
- the class of the interface to mock.public T getMock()
public final void reset()
public void replay()
java.lang.IllegalStateException
- if the mock object already is in replay state.public void verify()
java.lang.IllegalStateException
- if the mock object is in record state.java.lang.AssertionError
- if any expectation has not been met.public void setVoidCallable()
java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before, or if the last method
called on the mock was no void method.public void setThrowable(java.lang.Throwable throwable)
throwable
- the Throwable to throw.java.lang.IllegalStateException
- if the mock object is in replay state or if no method was
called on the mock object before.java.lang.IllegalArgumentException
- if the last method called on the mock cannot throw the
provided Throwable.java.lang.NullPointerException
- if throwable is null.public void setReturnValue(java.lang.Object value)
value
- the return value.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before. or if the last method
called on the mock does not return boolean
.public void setVoidCallable(int times)
times
- the number of times that the call is expected.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before, or if the last method
called on the mock was no void method.public void setThrowable(java.lang.Throwable throwable, int times)
throwable
- the Throwable to throw.times
- the number of times that the call is expected.java.lang.IllegalStateException
- if the mock object is in replay state or if no method was
called on the mock object before.java.lang.IllegalArgumentException
- if the last method called on the mock cannot throw the
provided Throwable.java.lang.NullPointerException
- if throwable is null.public void setReturnValue(java.lang.Object value, int times)
value
- the return value.times
- the number of times that the call is expected.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before. or if the last method
called on the mock does not return boolean
.public void setReturnValue(java.lang.Object value, Range range)
value
- the return value.range
- the number of times that the call is expected.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before. or if the last method
called on the mock does not return boolean
.public void setDefaultVoidCallable()
java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before, or if the last method
called on the mock was no void method.public void setDefaultThrowable(java.lang.Throwable throwable)
throwable
- throwable the throwable to be thrownjava.lang.IllegalArgumentException
- if the last method called on the mock cannot throw the
provided Throwable.java.lang.NullPointerException
- if throwable is null.java.lang.IllegalStateException
- if the mock object is in replay state, or if no method was
called on the mock object before.public void setDefaultReturnValue(java.lang.Object value)
value
- the return value.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before. or if the last method
called on the mock does not return boolean
.public void setMatcher(ArgumentsMatcher matcher)
matcher
- the matcher for the last method calledjava.lang.IllegalStateException
- if called in replay state, or if no method was called on the
mock object before.public void setVoidCallable(int minCount, int maxCount)
minCount
and maxCount
times, and will react
by returning silently.minCount
- the minimum number of times that the call is expected.maxCount
- the maximum number of times that the call is expected.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before, or if the last method
called on the mock was no void method.public void setVoidCallable(Range range)
public void setThrowable(java.lang.Throwable throwable, int minCount, int maxCount)
minCount
and maxCount
times, and will react
by throwing the provided Throwable.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.java.lang.IllegalStateException
- if the mock object is in replay state or if no method was
called on the mock object before.java.lang.IllegalArgumentException
- if the last method called on the mock cannot throw the
provided Throwable.java.lang.NullPointerException
- if throwable is null.public void setThrowable(java.lang.Throwable throwable, Range range)
public void setReturnValue(java.lang.Object value, int minCount, int maxCount)
minCount
and maxCount
times, and will react
by returning the provided return value.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.java.lang.IllegalStateException
- if the mock object is in replay state, if no method was
called on the mock object before. or if the last method
called on the mock does not return boolean
.public void setDefaultMatcher(ArgumentsMatcher matcher)
matcher
- the default matcher for this controljava.lang.IllegalStateException
- if called in replay state, or if any behavior is already
defined on the mock object.public <V1,V2 extends V1> void expectAndReturn(V1 ignored, V2 value)
setReturnValue(Object)
. For explanation, see
"Convenience Methods for Return Values" in the EasyMock documentation.V1
- mocked method return typeV2
- returned value typeignored
- an ignored value.value
- value returned by the mockpublic void expectAndReturn(int ignored, int value)
public <V1,V2 extends V1> void expectAndReturn(V1 ignored, V2 value, Range range)
setReturnValue(Object, Range)
. For
explanation, see "Convenience Methods for Return Values" in the EasyMock
documentation.V1
- mocked method return typeV2
- returned value typeignored
- an ignored value.value
- value returned by the mockrange
- range of number of callspublic void expectAndReturn(int ignored, int value, Range range)
public <V1,V2 extends V1> void expectAndReturn(V1 ignored, V2 value, int count)
setReturnValue(Object, int)
. For
explanation, see "Convenience Methods for Return Values" in the EasyMock
documentation.V1
- mocked method return typeV2
- returned value typeignored
- an ignored value.value
- value returned by the mockcount
- number of times the call is expectedpublic void expectAndReturn(int ignored, int value, int count)
public <V1,V2 extends V1> void expectAndReturn(V1 ignored, V2 value, int min, int max)
setReturnValue(Object, int, int)
. For
explanation, see "Convenience Methods for Return Values" in the EasyMock
documentation.V1
- mocked method return typeV2
- returned value typeignored
- an ignored value.value
- value returned by the mockmin
- minimum number of times the call is expectedmax
- maximum number of times the call is expectedpublic void expectAndReturn(int ignored, int value, int min, int max)
public void expectAndThrow(java.lang.Object ignored, java.lang.Throwable throwable)
setThrowable(Throwable)
. For explanation,
see "Convenience Methods for Throwables" in the EasyMock documentation.ignored
- an ignored value.throwable
- to be thrown on the callpublic void expectAndThrow(java.lang.Object ignored, java.lang.Throwable throwable, Range range)
setThrowable(Throwable, Range)
. For
explanation, see "Convenience Methods for Throwables" in the EasyMock
documentation.ignored
- an ignored value.throwable
- to be thrown on the callrange
- range of number of callspublic void expectAndThrow(java.lang.Object ignored, java.lang.Throwable throwable, int count)
setThrowable(Throwable, int)
. For
explanation, see "Convenience Methods for Throwables" in the EasyMock
documentation.ignored
- an ignored value.throwable
- to be thrown on the callcount
- number of times the call is expectedpublic void expectAndThrow(java.lang.Object ignored, java.lang.Throwable throwable, int min, int max)
setThrowable(Throwable, int, int)
. For
explanation, see "Convenience Methods for Throwables" in the EasyMock
documentation.ignored
- an ignored value.throwable
- to be thrown on the callmin
- minimum number of times the call is expectedmax
- maximum number of times the call is expectedpublic <V1,V2 extends V1> void expectAndDefaultReturn(V1 ignored, V2 value)
setDefaultReturnValue(Object)
. For
explanation, see "Convenience Methods for Return Values" in the EasyMock
documentation.V1
- mocked method return typeV2
- returned value typeignored
- an ignored value.value
- value returned by the mockpublic void expectAndDefaultThrow(java.lang.Object ignored, java.lang.Throwable throwable)
setDefaultThrowable(Throwable)
. For
explanation, see "Convenience Methods for Throwables" in the EasyMock
documentation.ignored
- an ignored value.throwable
- to be thrown on the callCopyright © 2001-2009 OFFIS, Tammo Freese, Henri Tremblay. This documentation is provided under the terms of the MIT licence.]]>