|
From: Nat P. <np...@us...> - 2002-10-16 13:13:03
|
Update of /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock
In directory usw-pr-cvs1:/tmp/cvs-serv28414/source/com/b13media/mock
Modified Files:
Mock.java
Log Message:
Renamed addDefaultResult to setupDefaultResult to match setupResult and setupThrow methods.
Added explicit test for setupDefaultResult; it was implicitly tested before.
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/Mock.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Mock.java 16 Oct 2002 12:56:21 -0000 1.5
+++ Mock.java 16 Oct 2002 13:12:56 -0000 1.6
@@ -45,15 +45,15 @@
*/
public Mock( String name ) {
_name = name;
- addDefaultResult( byte.class, new Byte((byte)0) );
- addDefaultResult( short.class, new Short((short)0) );
- addDefaultResult( int.class, new Integer(0) );
- addDefaultResult( long.class, new Long(0L) );
- addDefaultResult( float.class, new Float(0.0f) );
- addDefaultResult( double.class, new Double(0.0d) );
- addDefaultResult( boolean.class, Boolean.FALSE );
- addDefaultResult( char.class, new Character('\0') );
- addDefaultResult( String.class, "" );
+ setupDefaultResult( byte.class, new Byte((byte)0) );
+ setupDefaultResult( short.class, new Short((short)0) );
+ setupDefaultResult( int.class, new Integer(0) );
+ setupDefaultResult( long.class, new Long(0L) );
+ setupDefaultResult( float.class, new Float(0.0f) );
+ setupDefaultResult( double.class, new Double(0.0d) );
+ setupDefaultResult( boolean.class, Boolean.FALSE );
+ setupDefaultResult( char.class, new Character('\0') );
+ setupDefaultResult( String.class, "" );
}
/** Creates a Mock object and automatically assigns a name to it. The assigned
@@ -86,7 +86,46 @@
_strict = strict;
}
- public void addDefaultResult( Class result_type, Object result_value ) {
+ /** Set up calls to <var>method</var> to return <var>result</var>,
+ * but do not define any expectations upon arguments to those calls.
+ * Arguments of calls to <var>method</var> will be ignored.
+ *
+ * @param method
+ * The name of the method that will be called.
+ * @param result
+ * The result that will be returned from this call. Primitive types
+ * must be wrapped in the equivalent Java object, and will be unwrapped
+ * before being returned to the caller of the method.
+ */
+ public void setupResult( String method, Object result ) {
+ expectReturn( method, null, result );
+ }
+
+ /** Set up calls to <var>method</var> to throw <var>exception</var>,
+ * but do not define any expectations upon arguments to those calls.
+ * Arguments of calls to <var>method</var> will be ignored.
+ *
+ * @param method
+ * The name of the method that will be called.
+ * @param exception
+ * The exception or error that will be thrown as a result of this call.
+ */
+ public void setupThrow( String method, Throwable exception ) {
+ expectThrow( method, null, exception );
+ }
+
+ /** Set up the value returned by methods that have the given result
+ * type, if no result or exception has been explicitly defined for
+ * the called method by {@link #setupResult}, {@link #setupThrow},
+ * {@link #expectReturn} or {@link #expectThrow}.
+ *
+ * @param result_type
+ * The result type of methods to be mocked.
+ * @param result_value
+ * The default value returned by mocked methods that return values
+ * of type <var>result_type</var>.
+ */
+ public void setupDefaultResult( Class result_type, Object result_value ) {
_default_results.put( result_type, result_value );
}
@@ -156,34 +195,6 @@
*/
public void expectNotCalled( String method ) {
_expectations_not_called.add(method);
- }
-
- /** Set up calls to <var>method</var> to return <var>result</var>,
- * but do not define any expectations upon arguments to those calls.
- * Arguments of calls to <var>method</var> will be ignored.
- *
- * @param method
- * The name of the method that will be called.
- * @param result
- * The result that will be returned from this call. Primitive types
- * must be wrapped in the equivalent Java object, and will be unwrapped
- * before being returned to the caller of the method.
- */
- public void setupResult( String method, Object result ) {
- expectReturn( method, null, result );
- }
-
- /** Set up calls to <var>method</var> to throw <var>exception</var>,
- * but do not define any expectations upon arguments to those calls.
- * Arguments of calls to <var>method</var> will be ignored.
- *
- * @param method
- * The name of the method that will be called.
- * @param exception
- * The exception or error that will be thrown as a result of this call.
- */
- public void setupThrow( String method, Throwable exception ) {
- expectThrow( method, null, exception );
}
/** Define an order between two calls. The method named
|