From: Steve F. <sm...@us...> - 2003-10-05 09:28:21
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/functional/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv925/src/core/functional/test/mockobjects/dynamic Modified Files: MockTest.java Log Message: Converted Mock.matches() to use InvocationMocker. Added more functional tests Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/functional/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockTest.java 4 Oct 2003 22:54:48 -0000 1.2 +++ MockTest.java 5 Oct 2003 09:28:16 -0000 1.3 @@ -11,9 +11,11 @@ * High level test of dynamic mock class. */ public class MockTest extends TestCase { + public class TestException extends Exception {} public interface TargetType { - void noParams(); + void noParams() throws TestException; void oneParam(Object aParam); + String noParamsWithResult(); } private Mock mockTarget = new Mock(TargetType.class); @@ -30,7 +32,7 @@ assertEquals("Should have same name", "otherMock", otherMock.toString()); } - public void testPassesIfMockedMethodCalled() { + public void testPassesIfMockedMethodCalled() throws TestException { mockTarget.expect("noParams"); targetType.noParams(); @@ -49,7 +51,7 @@ fail("Should have thrown exception"); } - public void testFailsImmediatelyIfUnexpectedMethodCalled() { + public void testFailsImmediatelyIfUnexpectedMethodCalled() throws TestException { mockTarget.expect("notNoParams"); try { @@ -79,5 +81,18 @@ fail("Should have thrown exception"); } - + public void testCanReturnAResult() { + mockTarget.matchAndReturn("noParamsWithResult", "a result"); + + assertEquals("Should be returned result", "a result", targetType.noParamsWithResult()); + } + + public void testCanThrowAnExpection() { + mockTarget.matchAndThrow("noParams", new TestException()); + + try { + targetType.noParams(); + fail("Should have thrown text exception"); + } catch (TestException unused ) {}; + } } |