|
From: Nat P. <np...@us...> - 2002-10-16 13:56:45
|
Update of /cvsroot/mockobjects/nat/jmock/test/com/b13media/mock
In directory usw-pr-cvs1:/tmp/cvs-serv13215/test/com/b13media/mock
Modified Files:
Test_Mock.java
Log Message:
Added facility to setup behaviour of methods with side effect.
Setup methods do not have to be called.
Expected methods clear the method-called flag.
Index: Test_Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/nat/jmock/test/com/b13media/mock/Test_Mock.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Test_Mock.java 16 Oct 2002 13:12:59 -0000 1.5
+++ Test_Mock.java 16 Oct 2002 13:56:42 -0000 1.6
@@ -151,7 +151,7 @@
_mock.verify();
}
- public void testCallWithSideEffects() {
+ public void testExpectCallWithSideEffects() {
final StringBuffer buf = new StringBuffer();
_mock.expect(
new ExpectedCall( "sideEffect",
@@ -169,7 +169,22 @@
}
public void testNotAllMethodsCalled() {
- _mock.expectVoid( "noArg", Mock.NO_ARGS );
+ _mock.expectVoid( "noArgs", Mock.NO_ARGS );
+
+ try {
+ _mock.verify();
+ }
+ catch( AssertionFailedError ex ) {
+ return;
+ }
+
+ fail( "verify did not fail when all expected methods were not called" );
+ }
+
+ public void testCalledExpectationClearedBySubsequentExpecation() {
+ _mock.expectVoid( "noArgs", Mock.NO_ARGS );
+ _interface.noArgs();
+ _mock.expectVoid( "noArgs", Mock.NO_ARGS );
try {
_mock.verify();
@@ -178,7 +193,7 @@
return;
}
- fail( "verify did not fail when all methods were not called" );
+ fail( "verify did not fail when all expected methods were not called" );
}
public void testUnexpectedMethodThrowsWhenStrict() {
@@ -328,6 +343,8 @@
assertEquals( RESULT, _interface.objectTypes(null) );
assertEquals( RESULT, _interface.objectTypes(new Integer(0)) );
+
+ _mock.verify();
}
public void testSetupThrow() {
@@ -348,6 +365,42 @@
catch( IllegalArgumentException ex ) {
// expected
}
+
+ _mock.verify();
+ }
+
+ public void testSetupCallWithSideEffect() {
+ final StringBuffer buf = new StringBuffer();
+ _mock.setup( new ExpectedCall("sideEffect") {
+ public Object eval( Object[] args ) throws Throwable {
+ buf.append("hello");
+ return null;
+ }
+ } );
+
+ _interface.sideEffect( buf );
+ assertEquals( "hello", buf.toString() );
+ _mock.verify();
+ }
+
+ public void testSetupResultDoesNotRequireCall() {
+ _mock.setupResult( "objectTypes", "result" );
+ _mock.verify();
+ }
+
+ public void testSetupThrowDoesNotRequireCall() {
+ _mock.setupThrow( "objectTypes", new RuntimeException() );
+ _mock.verify();
+ }
+
+ public void testSetupCallWithSideEffectDoesNotRequireCall() {
+ _mock.setup( new ExpectedCall("sideEffect") {
+ public Object eval( Object[] args ) throws Throwable {
+ throw new RuntimeException("should not be called");
+ }
+ } );
+
+ _mock.verify();
}
public void testNoErrorWhenOrderedMethodsCalledInCorrectOrder() {
|