Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/mock
In directory sc8-pr-cvs16:/tmp/cvs-serv9113/input/javasrc/biz/xsoftware/mock
Modified Files:
CalledMethod.java Behavior.java MockObject.java
Added Files:
CloningBehavior.java
Removed Files:
NoCloneBehavior.java
Log Message:
modify behavior stuff.
Index: MockObject.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/mock/MockObject.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** MockObject.java 15 Nov 2006 17:12:39 -0000 1.10
--- MockObject.java 14 May 2007 14:26:14 -0000 1.11
***************
*** 60,64 ****
/**
! * Set the DefaultReturnValue for a 'method'
* @param method The method name to set the default return value for
* @param returnValue
--- 60,71 ----
/**
! * Set the DefaultReturnValue for a 'method'. This value is returned if none
! * of the following happen
! * <ol>
! * <li>addReturnValue is not called giving a return value</li>
! * <li>addThrowException is not called returning an exception</li>
! * <li>addBehavior is not called running a snippet of code that returns a value</li>
! * </ol>
! *
* @param method The method name to set the default return value for
* @param returnValue
***************
*** 66,70 ****
--- 73,108 ----
public void setDefaultReturnValue(String method, Object returnValue);
+ /**
+ * Set the DefaultBehavior for a 'method'. This Behavior object is used to run a snippet
+ * of code if none of the following happen
+ * <ol>
+ * <li>addReturnValue is not called giving a return value</li>
+ * <li>addThrowException is not called returning an exception</li>
+ * <li>addBehavior is not called running a snippet of code that returns a value</li>
+ * </ol>
+ *
+ * See the Behavior class for more info on what to put in the Behavior implementation.
+ *
+ * @param method When this method is called, the Behavior will be run.
+ * @param b The snippet of code to be run.
+ */
public void setDefaultBehavior(String method, Behavior b);
+
+ /**
+ * Set the DefaultBehavior for a 'method'. This Behavior object is used to run a snippet
+ * of code if none of the following happen
+ * <ol>
+ * <li>addReturnValue is not called giving a return value</li>
+ * <li>addThrowException is not called returning an exception</li>
+ * <li>addBehavior is not called running a snippet of code that returns a value</li>
+ * </ol>
+ *
+ * A Behavior or CloningBehavior can be passed in. See the Behavior or CloningBehavior
+ * class for more info on what to put in the Behavior implementation.
+ *
+ * @param method When this method is called, the Behavior will be run.
+ * @param b The snippet of code to be run.
+ * @param argTypes The parameters types of the method so overloaded method can be specified
+ */
public void setDefaultBehavior(String method, Behavior b, Class ... argTypes);
***************
*** 106,110 ****
--- 144,165 ----
public void addReturnValue(String method, Object ... o);
+ /**
+ * Adds a snippet of code to be run which exists in the Behavior implementation.
+ * A Behavior or CloningBehavior can be passed in. See the Behavior or CloningBehavior
+ * class for more info on what to put in the Behavior implementation.
+ *
+ * @param method When this method is called, the Behavior will be run
+ * @param behavior The snippet of code to be run.
+ */
public void addBehavior(String method, Behavior behavior);
+ /**
+ * Adds a snippet of code to be run which exists in the Behavior implementation.
+ * A Behavior or CloningBehavior can be passed in. See the Behavior or CloningBehavior
+ * class for more info on what to put in the Behavior implementation.
+ *
+ * @param method When this method is called, the Behavior will be run
+ * @param behavior The snippet of code to be run.
+ * @param argTypes The parameters to the method to distinguish between overloaded methods.
+ */
public void addBehavior(String method, Behavior behavior, Class... argTypes);
***************
*** 143,148 ****
--- 198,212 ----
// public void removeIgnore(String method, Class ... argTypes);
+ /**
+ * Sets the timeout which is the delay that a mockobject waits for a method to be
+ * called before failing. The default is 5 seconds.
+ */
public void setExpectTimeout(int timeout);
+ /**
+ * Gets the timeout which is the delay that a mockobject waits for a method to be
+ * called before failing.
+ * @return
+ */
public int getExpectTimeout();
--- NEW FILE: CloningBehavior.java ---
package biz.xsoftware.mock;
/**
* The same exact thing as the Behavior method except a cloning method must be supplied to.
* Sometimes the Behavior method will make modifications to the passed in parameter methods.
* The cloning method allows the mockobject to take a snapshot of the parameters passed into
* the method before they are modified. Then the test can still verify later the correct
* parameters were passed in. So, if you are mocking a method
* </br></br>
* public int doSomethingCool(Map map, int i, long l);
* </br></br>
* Then you must have a cloning method of the form
* </br></br>
* public Object[] doSomethingCoolClone(Map map, int i, long l);
* </br></br>
* Notice that you probably only need to clone the Map and would need to return an object
* array of all the parameters as so... new Object[] { clonedMap, i, l);
*
* @author dhiller
*
*/
public interface CloningBehavior extends Behavior
{
}
Index: CalledMethod.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/mock/CalledMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CalledMethod.java 10 Sep 2006 18:25:52 -0000 1.1
--- CalledMethod.java 14 May 2007 14:26:13 -0000 1.2
***************
*** 30,47 ****
this.howItWasCalled = howItWasCalled;
}
!
public String getMethodName() {
return method;
}
public int getParameterCount() {
return params.length;
}
public Object getParameter(int index) {
return params[index];
}
/**
! *
*/
public Object[] getAllParams() {
--- 30,62 ----
this.howItWasCalled = howItWasCalled;
}
! /**
! * Gets the method this CalledMethod object represents
! * @return
! */
public String getMethodName() {
return method;
}
+ /**
+ * Gets the number of parameters passed into method
+ * @return
+ */
public int getParameterCount() {
return params.length;
}
+ /**
+ * Gets the parameter at location=index
+ * @param index The location of the parameter
+ * @return The parameter that was passed into the method at location=index
+ */
public Object getParameter(int index) {
return params[index];
}
/**
! * Gets all the parameters that were passed into the method. For example, if a method
! * is called ... doSomethingCool("1234", 5, "eeee"), then the following will be returned
! * </br></br>
! * new Object[] {"1234", new Integer(5), "eeee")}
*/
public Object[] getAllParams() {
***************
*** 49,55 ****
--- 64,76 ----
}
+ /**
+ * Returns a stacktrace of how the method was called. This is useful for debugging when you
+ * didn't expect the method to be called.
+ * @return Throwable of how the method was called.
+ */
public Throwable getHowItWasCalled() {
return howItWasCalled;
}
+
@Override
public String toString() {
--- NoCloneBehavior.java DELETED ---
Index: Behavior.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/mock/Behavior.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Behavior.java 15 Sep 2006 21:22:56 -0000 1.4
--- Behavior.java 14 May 2007 14:26:14 -0000 1.5
***************
*** 2,9 ****
/**
*/
! public interface Behavior
! {
-
}
--- 2,17 ----
/**
+ * A way of providing snippets of code to be run when a method is called. If you want
+ * to pass in a Behavior implementation for </br></br>
+ *
+ * public int doSomethingCool(int i, String s, long l);
+ *
+ * </br></br>
+ * then your Behavior class must define the same exact method and that method will be
+ * called in your Behavior implementation when the mockobject's doSomethingCool method
+ * is called. You must also return the same value as the doSomethingCool method which
+ * in this case is an int.
*/
! public interface Behavior {
}
|