org.easymock
public class MockControl extends Object
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. |
protected static IBehaviorFactory | NICE_BEHAVIOR_FACTORY
internal constant with protected visibility to allow
access for extensions. |
static Range | ONE
Exactly one call. |
static Range | ONE_OR_MORE
One or more calls. |
protected static IBehaviorFactory | ORDERED_BEHAVIOR_FACTORY
internal constant with protected visibility to allow
access for extensions. |
protected static IBehaviorFactory | UNORDERED_BEHAVIOR_FACTORY
internal constant with protected visibility to allow
access for extensions. |
static Range | ZERO_OR_MORE
Zero or more calls. |
Constructor Summary | |
---|---|
protected | MockControl(Class toMock, IProxyFactory proxyFactory, IBehaviorFactory behaviorFactory)
Creates a new mock control object using the provided proxy and behavior
factory - this is an internal constructor with protected
visibility to allow access for extensions.
|
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. |
void | expectAndDefaultReturn(boolean ignored, boolean value)
Same as MockControl. |
void | expectAndDefaultReturn(long ignored, long value)
Same as MockControl. |
void | expectAndDefaultReturn(float ignored, float value)
Same as MockControl. |
void | expectAndDefaultReturn(double ignored, double value)
Same as MockControl. |
void | expectAndDefaultReturn(Object ignored, Object value)
Same as setDefaultReturnValue. |
void | expectAndDefaultThrow(boolean ignored, Throwable throwable)
Same as setDefaultThrowable. |
void | expectAndDefaultThrow(long ignored, Throwable throwable)
Same as setDefaultThrowable. |
void | expectAndDefaultThrow(float ignored, Throwable throwable)
Same as setDefaultThrowable. |
void | expectAndDefaultThrow(double ignored, Throwable throwable)
Same as setDefaultThrowable. |
void | expectAndDefaultThrow(Object ignored, Throwable throwable)
Same as setDefaultThrowable. |
void | expectAndReturn(boolean ignored, boolean value)
Same as MockControl. |
void | expectAndReturn(long ignored, long value)
Same as MockControl. |
void | expectAndReturn(float ignored, float value)
Same as MockControl. |
void | expectAndReturn(double ignored, double value)
Same as MockControl. |
void | expectAndReturn(Object ignored, Object value)
Same as setReturnValue. |
void | expectAndReturn(boolean ignored, boolean value, Range range)
Same as MockControl. |
void | expectAndReturn(long ignored, long value, Range range)
Same as MockControl. |
void | expectAndReturn(float ignored, float value, Range range)
Same as MockControl. |
void | expectAndReturn(double ignored, double value, Range range)
Same as MockControl. |
void | expectAndReturn(Object ignored, Object value, Range range)
Same as MockControl. |
void | expectAndReturn(boolean ignored, boolean value, int count)
Same as MockControl. |
void | expectAndReturn(long ignored, long value, int count)
Same as MockControl. |
void | expectAndReturn(float ignored, float value, int count)
Same as MockControl. |
void | expectAndReturn(double ignored, double value, int count)
Same as MockControl. |
void | expectAndReturn(Object ignored, Object value, int count)
Same as MockControl. |
void | expectAndReturn(boolean ignored, boolean value, int min, int max)
Same as MockControl. |
void | expectAndReturn(long ignored, long value, int min, int max)
Same as MockControl. |
void | expectAndReturn(float ignored, float value, int min, int max)
Same as MockControl. |
void | expectAndReturn(double ignored, double value, int min, int max)
Same as MockControl. |
void | expectAndReturn(Object ignored, Object value, int min, int max)
Same as MockControl. |
void | expectAndThrow(boolean ignored, Throwable throwable)
Same as setThrowable. |
void | expectAndThrow(long ignored, Throwable throwable)
Same as setThrowable. |
void | expectAndThrow(float ignored, Throwable throwable)
Same as setThrowable. |
void | expectAndThrow(double ignored, Throwable throwable)
Same as setThrowable. |
void | expectAndThrow(Object ignored, Throwable throwable)
Same as setThrowable. |
void | expectAndThrow(boolean ignored, Throwable throwable, Range range)
Same as MockControl. |
void | expectAndThrow(long ignored, Throwable throwable, Range range)
Same as MockControl. |
void | expectAndThrow(float ignored, Throwable throwable, Range range)
Same as MockControl. |
void | expectAndThrow(double ignored, Throwable throwable, Range range)
Same as MockControl. |
void | expectAndThrow(Object ignored, Throwable throwable, Range range)
Same as MockControl. |
void | expectAndThrow(boolean ignored, Throwable throwable, int count)
Same as MockControl. |
void | expectAndThrow(long ignored, Throwable throwable, int count)
Same as MockControl. |
void | expectAndThrow(float ignored, Throwable throwable, int count)
Same as MockControl. |
void | expectAndThrow(double ignored, Throwable throwable, int count)
Same as MockControl. |
void | expectAndThrow(Object ignored, Throwable throwable, int count)
Same as MockControl. |
void | expectAndThrow(boolean ignored, Throwable throwable, int min, int max)
Same as MockControl. |
void | expectAndThrow(long ignored, Throwable throwable, int min, int max)
Same as MockControl. |
void | expectAndThrow(float ignored, Throwable throwable, int min, int max)
Same as MockControl. |
void | expectAndThrow(double ignored, Throwable throwable, int min, int max)
Same as MockControl. |
void | expectAndThrow(Object ignored, Throwable throwable, int min, int max)
Same as MockControl. |
Object | 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(boolean 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 | setDefaultReturnValue(long 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 | setDefaultReturnValue(float 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 | setDefaultReturnValue(double 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 | 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(boolean value)
Records that the mock object will expect the last method call once, and
will react by returning the provided return value.
|
void | setReturnValue(long value)
Records that the mock object will expect the last method call once, and
will react by returning the provided return value.
|
void | setReturnValue(float value)
Records that the mock object will expect the last method call once, and
will react by returning the provided return value.
|
void | setReturnValue(double 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)
Records that the mock object will expect the last method call once, and
will react by returning the provided return value.
|
void | setReturnValue(boolean 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(double 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(float 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(long 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 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(boolean value, Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, and will react by returning the
provided return value. |
void | setReturnValue(double value, Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, and will react by returning the
provided return value. |
void | setReturnValue(float value, Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, and will react by returning the
provided return value. |
void | setReturnValue(long value, Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, 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 the number
of times specified by the range argument, and will react by returning the
provided return value. |
void | setReturnValue(boolean 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 | setReturnValue(long 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 | setReturnValue(float 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 | setReturnValue(double 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 | 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, 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, Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, 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(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(Range range)
Records that the mock object will expect the last method call the number
of times specified by the range argument, 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. |
java.util.Arrays.equals()
-method.protected
visibility to allow
access for extensions.protected
visibility to allow
access for extensions.protected
visibility to allow
access for extensions.protected
visibility to allow access for extensions.
Parameters: toMock the class of the interface to mock. proxyFactory the proxy factory. behaviorFactory the behavior factory.
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 AssertionFailedError
.
Parameters: toMock the class of the interface to mock.
Returns: the mock control.
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
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 AssertionFailedError
.
Parameters: toMock the class of the interface to mock.
Returns: the mock control.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Parameters: ignored an ignored value.
Returns: the mock object of this control
Throws: IllegalStateException if the mock object already is in replay state.
Throws: IllegalStateException if called in replay state, or if any behavior is already defined on the mock object.
Parameters: value the return value.
Throws: 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
.
Parameters: value the return value.
Throws: 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
byte, short, char, int, or long
.
Parameters: value the return value.
Throws: 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 float
.
Parameters: value the return value.
Throws: 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 double
.
Parameters: value the return value.
Throws: 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 an object. IllegalArgumentException if the provided return value is not compatible to the return value of the last method called on the mock object.
Parameters: throwable throwable the throwable to be thrown
Throws: IllegalArgumentException if the last method called on the mock cannot throw the provided Throwable. NullPointerException if throwable is null. IllegalStateException if the mock object is in replay state, or if no method was called on the mock object before.
Throws: 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.
Throws: IllegalStateException if called in replay state, or if no method was called on the mock object before.
Parameters: value the return value.
Throws: 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
.
Parameters: value the return value.
Throws: 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
byte, short, char, int, or long
.
Parameters: value the return value.
Throws: 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 float
.
Parameters: value the return value.
Throws: 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 double
.
Parameters: value the return value.
Throws: 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 an object. IllegalArgumentException if the provided return value is not compatible to the return value of the last method called on the mock object.
Parameters: value the return value. times the number of times that the call is expected.
Throws: 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
.
Parameters: value the return value. times the number of times that the call is expected.
Throws: 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 double
.
Parameters: value the return value. times the number of times that the call is expected.
Throws: 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 float
.
Parameters: value the return value. times the number of times that the call is expected.
Throws: 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
byte, short, char, int, or long
.
Parameters: value the return value. times the number of times that the call is expected.
Throws: 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 an object. IllegalArgumentException if the provided return value is not compatible to the return value of the last method called on the mock object.
Parameters: value the return value. range the number of times that the call is expected.
Throws: 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
.
Parameters: value the return value. range the number of times that the call is expected.
Throws: 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 double
.
Parameters: value the return value. range the number of times that the call is expected.
Throws: 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 float
.
Parameters: value the return value. range the number of times that the call is expected.
Throws: 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
byte, short, char, int, or long
.
Parameters: value the return value. range the number of times that the call is expected.
Throws: 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 an object. IllegalArgumentException if the provided return value is not compatible to the return value of the last method called on the mock object.
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.
Throws: 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
.
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.
Throws: 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
byte, short, char, int, or long
.
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.
Throws: 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 float
.
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.
Throws: 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 double
.
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.
Throws: 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 an object. IllegalArgumentException if the provided return value is not compatible to the return value of the last method called on the mock object.
Parameters: throwable the Throwable to throw.
Throws: IllegalStateException if the mock object is in replay state or if no method was called on the mock object before. IllegalArgumentException if the last method called on the mock cannot throw the provided Throwable. NullPointerException if throwable is null.
Parameters: throwable the Throwable to throw. times the number of times that the call is expected.
Throws: IllegalStateException if the mock object is in replay state or if no method was called on the mock object before. IllegalArgumentException if the last method called on the mock cannot throw the provided Throwable. NullPointerException if throwable is null.
Parameters: throwable the Throwable to throw. range the number of times that the call is expected.
Throws: IllegalStateException if the mock object is in replay state or if no method was called on the mock object before. IllegalArgumentException if the last method called on the mock cannot throw the provided Throwable. NullPointerException if throwable is null.
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.
Throws: IllegalStateException if the mock object is in replay state or if no method was called on the mock object before. IllegalArgumentException if the last method called on the mock cannot throw the provided Throwable. NullPointerException if throwable is null.
Throws: 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.
Parameters: times the number of times that the call is expected.
Throws: 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.
Parameters: range the number of times that the call is expected.
Throws: 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.
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.
Throws: 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.
Throws: IllegalStateException if the mock object is in record state. AssertionFailedError if any expectation has not been met.