Update of /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26781/input/javasrc/biz/xsoftware/mock
Modified Files:
MockSuperclass.java MockObject.java
Log Message:
added add/removeIgnore and did some minor cleanup
Index: MockSuperclass.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockSuperclass.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** MockSuperclass.java 25 Aug 2006 17:26:29 -0000 1.11
--- MockSuperclass.java 25 Aug 2006 19:42:09 -0000 1.12
***************
*** 76,80 ****
private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>();
! private String[] ignoredMethods = new String[0];
private Cloner cloner;
--- 76,80 ----
private Map<String, Object> methodToDefaultRetVal = new HashMap<String, Object>();
! private List<String> ignoredMethods = new ArrayList<String>();
private Cloner cloner;
***************
*** 118,144 ****
return waitTime;
}
!
! public void ignore(String method)
{
! ignoreImpl(new String[] {method});
}
! public void ignore(String ... methods)
{
ignoreImpl(methods);
}
! private void ignoreImpl(String[] methods)
{
! setIgnoredMethods(methods);
}
! public void setIgnoredMethods(String[] methods) {
if(methods == null)
! ignoredMethods = new String[0];
verifyMethodsExist(methods);
! ignoredMethods = methods;
}
/**
--- 118,177 ----
return waitTime;
}
!
! public void addIgnore(String method)
{
! ignoreImpl(method);
}
! public void addIgnore(String ... methods)
{
ignoreImpl(methods);
}
! public void removeIgnore(String method)
{
! removeIgnoreImpl(method);
}
! public void removeIgnore(String ... methods)
! {
! removeIgnoreImpl(methods);
! }
!
! private void removeIgnoreImpl(String ... methods)
! {
! for(String method : methods)
! {
! ignoredMethods.remove(method);
! }
! }
!
! private void ignoreImpl(String ... methods)
! {
! addIgnoredMethods(methods);
! }
!
! public void addIgnoredMethods(String[] methods) {
if(methods == null)
! return;
verifyMethodsExist(methods);
! for(String method : methods)
! {
! ignoredMethods.add(method);
! }
}
+
+ public void setIgnoredMethods(String[] methods)
+ {
+ if(methods == null)
+ ignoredMethods = new ArrayList<String>();
+ verifyMethodsExist(methods);
+
+ for(String method : methods)
+ {
+ ignoredMethods.add(method);
+ }
+ }
/**
***************
*** 171,175 ****
params = "no params";
} else {
! Object[] array = (Object[])parameters;
for(int i = 0; i < array.length-1; i++) {
params += array[i]+", ";
--- 204,208 ----
params = "no params";
} else {
! Object[] array = parameters;
for(int i = 0; i < array.length-1; i++) {
params += array[i]+", ";
***************
*** 196,200 ****
private Object findNextAction(String method, Object[] params) throws Throwable {
! List l = (List)methodToReturnVal.get(method);
if(l == null)
{
--- 229,233 ----
private Object findNextAction(String method, Object[] params) throws Throwable {
! List l = methodToReturnVal.get(method);
if(l == null)
{
***************
*** 253,257 ****
+reason, retVal, ExpectFailedException.TIMED_OUT);
}
! Integer index = (Integer)expectedMethods.remove(o.getMethodName());
if(index == null) {
String reason = putTogetherReason(methods, ignorables, methodsCalledList, null);
--- 286,290 ----
+reason, retVal, ExpectFailedException.TIMED_OUT);
}
! Integer index = expectedMethods.remove(o.getMethodName());
if(index == null) {
String reason = putTogetherReason(methods, ignorables, methodsCalledList, null);
***************
*** 496,500 ****
//continue while loop.
for(int i = 0; i < methodsCalled.size(); i++) {
! CalledMethod calledMethod = (CalledMethod)methodsCalled.remove(0);
calledMethods.add(calledMethod);
if(!ignorables.contains(calledMethod.getMethodName())) {
--- 529,533 ----
//continue while loop.
for(int i = 0; i < methodsCalled.size(); i++) {
! CalledMethod calledMethod = methodsCalled.remove(0);
calledMethods.add(calledMethod);
if(!ignorables.contains(calledMethod.getMethodName())) {
***************
*** 510,520 ****
}
! private Set<String> createIgnorableMap(String[] ignorableMethods) {
Set<String> ignorables = new HashSet<String>();
if(ignorableMethods != null) {
! for(int i = 0; i < ignorableMethods.length; i++) {
! if(ignorableMethods[i] != null)
! ignorables.add(ignorableMethods[i]);
! }
}
return ignorables;
--- 543,553 ----
}
! private Set<String> createIgnorableMap(List<String> ignorableMethods) {
Set<String> ignorables = new HashSet<String>();
if(ignorableMethods != null) {
! for(String method : ignorableMethods)
! {
! ignorables.add(method);
! }
}
return ignorables;
***************
*** 523,527 ****
List<CalledMethod> leftOver = new ArrayList<CalledMethod>();
for(int i = 0; i < methodsCalled.size(); i++) {
! CalledMethod o = (CalledMethod)methodsCalled.get(i);
if(!ignorables.contains(o.getMethodName()) && o != null) {
leftOver.add(o);
--- 556,560 ----
List<CalledMethod> leftOver = new ArrayList<CalledMethod>();
for(int i = 0; i < methodsCalled.size(); i++) {
! CalledMethod o = methodsCalled.get(i);
if(!ignorables.contains(o.getMethodName()) && o != null) {
leftOver.add(o);
***************
*** 532,536 ****
CalledMethod[] m = new CalledMethod[0];
! m = (CalledMethod[])leftOver.toArray(m);
return new LeftOverMethods(m);
}
--- 565,569 ----
CalledMethod[] m = new CalledMethod[0];
! m = leftOver.toArray(m);
return new LeftOverMethods(m);
}
***************
*** 543,552 ****
}
/**
- * @return
*/
public CalledMethod[] getMethods() {
return leftOver;
}
! public String toString() {
String retVal = "";
for(int i = 0; i < leftOver.length; i++) {
--- 576,585 ----
}
/**
*/
public CalledMethod[] getMethods() {
return leftOver;
}
! @Override
! public String toString() {
String retVal = "";
for(int i = 0; i < leftOver.length; i++) {
Index: MockObject.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib2/input/javasrc/biz/xsoftware/mock/MockObject.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MockObject.java 4 Aug 2006 16:20:52 -0000 1.5
--- MockObject.java 25 Aug 2006 19:42:09 -0000 1.6
***************
*** 11,15 ****
* The interface all mock objects implement. This is the interface used
* by the unit tests once the mock object is created.
! *
* @author Dean Hiller
*/
--- 11,15 ----
* The interface all mock objects implement. This is the interface used
* by the unit tests once the mock object is created.
! *
* @author Dean Hiller
*/
***************
*** 25,32 ****
*/
public static String ANY = "'Any 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.
--- 25,32 ----
*/
public static String ANY = "'Any 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.
***************
*** 34,45 ****
* @param method The expected method.
* @return An array of params that were passed to the methods called
! *
* @deprecated please use expect(String method)
! */
public CalledMethod expectCall(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.
--- 34,45 ----
* @param method The expected method.
* @return An array of params that were passed to the methods called
! *
* @deprecated please use expect(String method)
! */
public CalledMethod expectCall(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.
***************
*** 47,51 ****
* @param method The expected method.
* @return An array of params that were passed to the methods called
! */
public CalledMethod expect(String method);
--- 47,51 ----
* @param method The expected method.
* @return An array of params that were passed to the methods called
! */
public CalledMethod expect(String method);
***************
*** 56,66 ****
* 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.
! *
* @param methods The expected method(s) in the correct order.
* @return An array or arrays of params that were passed to the methods called
! */
public CalledMethod[] expect(String ... methods);
!
/**
* Waits for all the methods to be called. If any of the methods
--- 56,66 ----
* 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.
! *
* @param methods The expected method(s) in the correct order.
* @return An array or arrays of params that were passed to the methods called
! */
public CalledMethod[] expect(String ... methods);
!
/**
* Waits for all the methods to be called. If any of the methods
***************
*** 69,89 ****
* 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.
! *
* @param methods The expected methods in the correct order.
* @return An array or arrays of params that were passed to the methods called
! *
* @deprecated please use expectCall(String ... methods)
! */
public CalledMethod[] expectOrderedCalls(String[] methods);
!
/**
* Expect many methods to be called irrelevant of the order in which they are
* called.
! *
* @param methods The methods to be called in no particular order
* @return An array of params that were passed to the methods called. This
* array lines up with the methods array passed in.
! *
* @deprecated this will go away soon, unless you email me that you depend on it.
*/
--- 69,89 ----
* 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.
! *
* @param methods The expected methods in the correct order.
* @return An array or arrays of params that were passed to the methods called
! *
* @deprecated please use expectCall(String ... methods)
! */
public CalledMethod[] expectOrderedCalls(String[] methods);
!
/**
* Expect many methods to be called irrelevant of the order in which they are
* called.
! *
* @param methods The methods to be called in no particular order
* @return An array of params that were passed to the methods called. This
* array lines up with the methods array passed in.
! *
* @deprecated this will go away soon, unless you email me that you depend on it.
*/
***************
*** 106,110 ****
* <li> RuntimeException for Subclasses of MockSuperclass</li>
* </ol>
! *
* @param method The method to throw the exception on when it is called.
* @param e The exception to throw on method.
--- 106,110 ----
* <li> RuntimeException for Subclasses of MockSuperclass</li>
* </ol>
! *
* @param method The method to throw the exception on when it is called.
* @param e The exception to throw on method.
***************
*** 114,118 ****
* Add a return value to return when 'method' is called.
* <br></br>
! * 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,
--- 114,118 ----
* Add a return value to return when 'method' is called.
* <br></br>
! * 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,
***************
*** 121,145 ****
* <br></br>
* Use Integer to return int, Long for long, etc.
! *
* @param method The method that when called returns first value on queue
* @param o The object to return that is added to the queue
*/
public void addReturnValue(String method, Object o);
!
/**
* When calling expectCall, 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.
! *
* @deprecated please use ignore(String ... methods)
*/
public void setIgnoredMethods(String[] methods);
!
/**
* When calling expect, the MockObject will ignore this method,
* so it will not result in an exception.
*/
! public void ignore(String method);
!
/**
* When calling expect, the MockObject will ignore the methods
--- 121,146 ----
* <br></br>
* Use Integer to return int, Long for long, etc.
! *
* @param method The method that when called returns first value on queue
* @param o The object to return that is added to the queue
*/
public void addReturnValue(String method, Object o);
!
/**
* When calling expectCall, 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.
! *
* @deprecated please use ignore(String ... methods)
*/
public void setIgnoredMethods(String[] methods);
!
!
/**
* When calling expect, the MockObject will ignore this method,
* so it will not result in an exception.
*/
! public void addIgnore(String method);
!
/**
* When calling expect, the MockObject will ignore the methods
***************
*** 147,164 ****
* called, it will not result in an exception.
*/
! public void ignore(String ... methods);
!
public void setCloner(Cloner c);
/**
* Set the DefaultReturnValue for a 'method'
! * @param method The method
*/
public void setDefaultReturnValue(String method, Object o);
!
public void setExpectTimeout(int timeout);
!
public int getExpectTimeout();
public void addBehavior(String string, Behavior behavior);
!
}
--- 148,176 ----
* called, it will not result in an exception.
*/
! public void addIgnore(String ... methods);
!
!
! /**
! * Removes the method from the ignored methods set.
! */
! public void removeIgnore(String method);
!
! /**
! * Removes the methods from the ignored methods set.
! */
! public void removeIgnore(String ... methods);
!
public void setCloner(Cloner c);
/**
* Set the DefaultReturnValue for a 'method'
! * @param method The method
*/
public void setDefaultReturnValue(String method, Object o);
!
public void setExpectTimeout(int timeout);
!
public int getExpectTimeout();
public void addBehavior(String string, Behavior behavior);
!
}
|