|
From: Nat P. <np...@us...> - 2002-10-14 14:42:52
|
Update of /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock
In directory usw-pr-cvs1:/tmp/cvs-serv12855/source/com/b13media/mock
Modified Files:
Mock.java
Log Message:
Added expectNotCalled method to Mock class.
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/Mock.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Mock.java 11 Oct 2002 14:57:37 -0000 1.2
+++ Mock.java 14 Oct 2002 14:42:47 -0000 1.3
@@ -33,6 +33,7 @@
private String _name;
private Map _expectations = new HashMap();
+ private Set _expectations_not_called = new HashSet();
private Map _order_constraints = new HashMap();
private Set _called_methods = new HashSet();
private boolean _strict = false;
@@ -98,6 +99,7 @@
*/
public void expect( ExpectedCall call ) {
_expectations.put( call.getMethodName(), call );
+ _expectations_not_called.remove( call.getMethodName() );
}
/** Expect a method call and return a result when it is called.
@@ -153,6 +155,17 @@
expect( new ExpectedThrow( method, args, exception ) );
}
+ /** Expect a method not to be called.
+ * An {@link junit.framework.AssertionFailedError} will be thrown if
+ * the method is called.
+ *
+ * @param method
+ * The name of the method that will not be called.
+ */
+ public void expectNotCalled( String method ) {
+ _expectations_not_called.add(method);
+ }
+
/** Define an order between two calls. The method named
* <var>subsequent_method</var> <em>must</em> be called after
* the method namd <var>preceding_method</var>, otherwise an
@@ -193,6 +206,8 @@
{
String method_name = method.getName();
+ assertCanBeCalled( method_name );
+
if( _expectations.containsKey( method_name ) ) {
ExpectedCall expected =
(ExpectedCall)_expectations.get(method_name);
@@ -262,9 +277,15 @@
}
}
+ private void assertCanBeCalled( String method_name ) {
+ if( _expectations_not_called.contains(method_name) ) {
+ fail(_name + ": unexpected call to method " + method_name );
+ }
+ }
+
private void assertHasBeenCalled( String method_name ) {
if( !_called_methods.contains(method_name) ) {
- fail( "method " + method_name + " was not called" );
+ fail( _name + ": method " + method_name + " was not called" );
}
}
|