|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MockObject
The interface all mock objects implement. This is the interface used by the unit tests once the mock object is created.
Field Summary | |
---|---|
static String |
ANY
Field used to expect any method so expect returns as soon as any method is called. |
static String |
NONE
Field used to expect that no methods have been called. |
Method Summary | ||
---|---|---|
void |
addBehavior(MethodSignature methodSignature,
Behavior behavior)
Adds a snippet of code to be run which exists in the Behavior implementation. |
|
void |
addBehavior(String method,
Behavior behavior)
Adds a snippet of code to be run which exists in the Behavior implementation. |
|
void |
addBehavior(String method,
Behavior behavior,
Class<?>... argTypes)
Deprecated. Since 2007 Aug 8. Use addBehavior(MethodSignature, Behavior) instead |
|
void |
addIgnore(MethodSignature... methodSignature)
When calling expect, the MockObject will ignore the methods in 'methods' variable so if one of the methods in this array is called, it will not result in an exception. |
|
void |
addIgnore(String... method)
When calling expect, the MockObject will ignore the methods in 'methods' variable so if one of the methods in this array is called, it will not result in an exception |
|
|
addReturnValue(MethodSignature methodSignature,
T... o)
Add a return value to return when 'method' is called. |
|
|
addReturnValue(Method method,
T... o)
Add a return value to return when 'method' is called. |
|
void |
addReturnValue(String method,
boolean isArray,
Object... o)
Deprecated. addReturnValue(Method, Object...) was enhanced to detect if the given method returns
an array. If it does then the object array passed in will be the object returned for a single method call |
|
|
addReturnValue(String method,
T... o)
Add a return value to return when 'method' is called. |
|
void |
addThrowException(MethodSignature method,
Throwable e)
Add an exception to throw when a method on the mockObject is called. |
|
void |
addThrowException(String method,
Throwable e)
Add an exception to throw when a method on the mockObject is called. |
|
CalledMethod[] |
expect(String... methods)
Waits for all the methods to be called. |
|
CalledMethod |
expect(String method)
Waits for one and only one method to be called. |
|
CalledMethod[] |
expect(String method,
int times)
Waits for a methods to be called a specific number of times. |
|
CalledMethod |
expectCall(String method)
Deprecated. Use expect(String) now |
|
CalledMethod |
expectCall(String method,
String... ignoredMethods)
Deprecated. Use a combination of addIgnore(String[]) and
expect(String) |
|
CalledMethod[] |
expectOnceThenIgnore(String... methods)
This method will expect the given method one time and ignore any further calls to the method. |
|
CalledMethod[] |
expectOrderedCalls(String... methods)
Deprecated. Use expect(String[]) instead |
|
CalledMethod[] |
expectOrderedCalls(String[] methods,
String[] ignoredMethods)
Deprecated. This is no longer supported, the use of addIgnore(String[]) in combination with
expect(String[]) should be used |
|
CalledMethod[] |
expectUnordered(String... methods)
Expects the given methods to be called in no particular order |
|
CalledMethod |
expectUnordered(String method)
|
|
CalledMethod[] |
expectUnorderedCalls(String... methods)
Deprecated. No longer supported |
|
CalledMethod[] |
expectUnorderedCalls(String[] methods,
String[] ignoredMethods)
Deprecated. This is no longer supported, the use of addIgnore(String[]) in combination with
expect(String[]) should be used |
|
int |
getExpectTimeout()
Gets the timeout which is the delay that a mockobject waits for a method to be called before failing. |
|
boolean |
isCaseSensitive()
Returns the current setting for case sensitivity |
|
void |
removeIgnore(MethodSignature... methodSignature)
Removes the method from the ignored methods set. |
|
void |
removeIgnore(String... methods)
Removes the method(s) from the ignored methods set |
|
void |
reset()
This method will reset the MockObject to an empty state. |
|
void |
setBehavior(Behavior behavior)
This method will look at the given behavior and will automatically call setDefaultBehavior(String, Behavior, Class[]) for all the
methods that have the BehaviorMethod annotation |
|
void |
setCaseSensitive(boolean isCaseSensitive)
This is used if you want to ignore case sensitivity. |
|
void |
setDefaultBehavior(MethodSignature methodSignature,
Behavior b)
Set the DefaultBehavior for a 'method'. |
|
void |
setDefaultBehavior(String method,
Behavior b)
Set the DefaultBehavior for a 'method'. |
|
void |
setDefaultBehavior(String method,
Behavior b,
Class<?>... argTypes)
Deprecated. Since 2007 Aug 8. Use setDefaultBehavior(MethodSignature, Behavior)
instead |
|
void |
setDefaultReturnValue(Method method,
Object returnValue)
Provide the return value for a specific Method . |
|
void |
setDefaultReturnValue(String method,
Object returnValue)
Set the DefaultReturnValue for a 'method'. |
|
void |
setExpectTimeout(int timeout)
Sets the timeout which is the delay that a mockobject waits for a method to be called before failing. |
Field Detail |
---|
static final String NONE
static final String ANY
Method Detail |
---|
CalledMethod expect(String method)
method
- The expected method.
CalledMethod[] expect(String... methods)
methods
- The expected method(s) in the correct order.
CalledMethod[] expect(String method, int times)
method
- times
- is the number of times the methods is expected to be called
CalledMethod expectUnordered(String method)
CalledMethod[] expectUnordered(String... methods)
methods
- The methods to expect
CalledMethod[] expectOnceThenIgnore(String... methods)
methods
- The method names to ignore
@Deprecated CalledMethod expectCall(String method)
expect(String)
now
CalledMethod expectCall(String method, String... ignoredMethods)
addIgnore(String[])
and
expect(String)
@Deprecated CalledMethod[] expectOrderedCalls(String... methods)
expect(String[])
instead
@Deprecated CalledMethod[] expectOrderedCalls(String[] methods, String[] ignoredMethods)
addIgnore(String[])
in combination with
expect(String[])
should be used
@Deprecated CalledMethod[] expectUnorderedCalls(String... methods)
@Deprecated CalledMethod[] expectUnorderedCalls(String[] methods, String[] ignoredMethods)
addIgnore(String[])
in combination with
expect(String[])
should be used
addIgnore(String[])
with the given ignored methods, then
runs expectUnorderedCalls(String[])
, saving the result. Then
removes the ignored methods and finally returns the saved result
void setDefaultReturnValue(String method, Object returnValue)
method
- The method name to set the default return value forreturnValue
- void setDefaultReturnValue(Method method, Object returnValue)
Method
. This is useful
for specifying a method that you're having trouble getting MockObject to
handle correctly.
For example:
MockObject m = MockObjectFactory.createMock(Runnable.class);
Method method = Object.class.getMethod("toString");
m.setDefaultReturnValue(method, "test");
assertEquals("test", m.toString());
method
- The method to tie the return value to.returnValue
- The value to return when the method is calledvoid setDefaultBehavior(String method, Behavior b)
method
- When this method is called, the Behavior will be run.b
- The snippet of code to be run.@Deprecated void setDefaultBehavior(String method, Behavior b, Class<?>... argTypes)
setDefaultBehavior(MethodSignature, Behavior)
instead
method
- When this method is called, the Behavior will be run.b
- The snippet of code to be run.argTypes
- The parameters types of the method so overloaded method
can be specifiedvoid setDefaultBehavior(MethodSignature methodSignature, Behavior b)
methodSignature
- Used to define which method the behavior should be
assigned tob
- The snippet of code to be run.void addThrowException(String method, Throwable e)
This method only expects the method name. It will search for a method
name that matches ignoring any method parameters. If more than one
methods are found then an exception will be thrown. In this case use
addThrowException(MethodSignature, Throwable)
instead
method
- The method to throw the exception on when it is called.e
- The exception to throw on method.void addThrowException(MethodSignature method, Throwable e)
method
- e
- <T> void addReturnValue(String method, T... o)
method
- The method that when called returns first value on queueo
- The object or objects to return that is added to the queue<T> void addReturnValue(MethodSignature methodSignature, T... o)
<T> void addReturnValue(Method method, T... o)
@Deprecated void addReturnValue(String method, boolean isArray, Object... o)
addReturnValue(Method, Object...)
was enhanced to detect if the given method returns
an array. If it does then the object array passed in will be the object returned for a single method call
void setBehavior(Behavior behavior)
setDefaultBehavior(String, Behavior, Class[])
for all the
methods that have the BehaviorMethod
annotation
behavior
- void addBehavior(String method, Behavior behavior)
method
- When this method is called, the Behavior will be runbehavior
- The snippet of code to be run.@Deprecated void addBehavior(String method, Behavior behavior, Class<?>... argTypes)
addBehavior(MethodSignature, Behavior)
instead
method
- When this method is called, the Behavior will be runbehavior
- The snippet of code to be run.argTypes
- The parameters to the method to distinguish between
overloaded methods.void addBehavior(MethodSignature methodSignature, Behavior behavior)
methodSignature
- Used to define which method the behavior should be
assigned tobehavior
- The snippet of code to be run.void addIgnore(String... method)
method
- The name of the method(s) to ignorevoid addIgnore(MethodSignature... methodSignature)
methodSignature
- The MethodSignature
to add to the list of
ignored methodsvoid removeIgnore(String... methods)
methods
- The name of the method(s) to remove from the list of
ignored methodsvoid removeIgnore(MethodSignature... methodSignature)
methodSignature
- The MethodSignature
to remove from the
ignore listvoid setExpectTimeout(int timeout)
int getExpectTimeout()
void setCaseSensitive(boolean isCaseSensitive)
isCaseSensitive
- boolean isCaseSensitive()
void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |