biz.xsoftware.mock.client
Interface JsMockObject

All Known Implementing Classes:
JsMockSuperclass

public interface JsMockObject

The interface all mock objects implement. This is the interface used by the unit tests once the mock object is created.

Author:
Dean Hiller

Field Summary
static String ANY
          Field used to expect any method so expectCall 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(String method, JsBehavior behavior)
           
 void addIgnore(String method)
          When calling expect, the MockObject will ignore this method, so it will not result in an exception.
 void addReturnValue(String method, Object o)
          Add a return value to return when 'method' is called.
 void addThrowException(String method, Throwable e)
          Add an exception to throw when a method on the mockObject is called.
 JsCalledMethod expect(String method)
          Waits for one and only one method to be called.
 JsCalledMethod[] expect(String[] methods)
          Waits for all the methods to be called.
 int getExpectTimeout()
           
 void removeIgnore(String method)
          Removes the method from the ignored methods set.
 void setDefaultReturnValue(String method, Object o)
          Set the DefaultReturnValue for a 'method'
 void setExpectTimeout(int timeout)
           
 

Field Detail

NONE

static final String NONE
Field used to expect that no methods have been called.

See Also:
Constant Field Values

ANY

static final String ANY
Field used to expect any method so expectCall returns as soon as any method is called.

See Also:
Constant Field Values
Method Detail

expect

JsCalledMethod expect(String method)
Waits for one and only one method to be called. If any methods are called before or after this one(after can sometimes be caught by the MockObject when the threading is not synchronous), then this call will throw an ExpectFailedException.

Parameters:
method - The expected method.
Returns:
An array of params that were passed to the methods called

expect

JsCalledMethod[] expect(String[] methods)
Waits for all the methods to be called. If any of the methods are not called or are called out of order, this method throws an exception which will fail the test case. For each method, this will wait WAIT_TIME milliseconds for each method to be called. If the method is not called within this period, an exception will be thrown saying 'method' was not called within timeout period.

Parameters:
methods - The expected method(s) in the correct order.
Returns:
An array or arrays of params that were passed to the methods called

addThrowException

void addThrowException(String method,
                       Throwable e)
Add an exception to throw when a method on the mockObject is called.
This can be called many times where each time it is called, the exception is added to a queue. Each time 'method' is called, it checks the queue, if empty, it does not throw an exception.
Should only pass the type of Throwable that the 'method' can throw. If you pass IOException in for a method that doesn't have a signature of 'throws IOException', then one of the following exceptions will be thrown into the sysUnderTest
  1. UndeclaredThrowableException for MockObjects created with MockCreator
  2. RuntimeException for Subclasses of MockSuperclass

Parameters:
method - The method to throw the exception on when it is called.
e - The exception to throw on method.

addReturnValue

void addReturnValue(String method,
                    Object o)
Add a return value to return when 'method' is called.

This can be called multiple times and each call will add to a queue. When 'method' is called, it will return the first value on the queue. If the queue is null, 'method' will return the defaultvalue which is null unless setDefaultReturnValue is called on MockObject.

Use Integer to return int, Long for long, etc.

Parameters:
method - The method that when called returns first value on queue
o - The object to return that is added to the queue

addBehavior

void addBehavior(String method,
                 JsBehavior behavior)

addIgnore

void addIgnore(String method)
When calling expect, the MockObject will ignore this method, so it will not result in an exception.


removeIgnore

void removeIgnore(String method)
Removes the method from the ignored methods set.


setDefaultReturnValue

void setDefaultReturnValue(String method,
                           Object o)
Set the DefaultReturnValue for a 'method'

Parameters:
method - The method

setExpectTimeout

void setExpectTimeout(int timeout)

getExpectTimeout

int getExpectTimeout()


Copyright © 2000 Dean Hiller All Rights Reserved.
If you would like a shared copyright, contact me at deanhiller@users.sourceforge.net
SourceForge