KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > atest > jmock > BadMethodNameAcceptanceTest


1 package atest.jmock;
2
3 import junit.framework.AssertionFailedError;
4 import org.jmock.MockObjectTestCase;
5 import org.jmock.Mock;
6 import org.jmock.expectation.AssertMo;
7
8
9 public class BadMethodNameAcceptanceTest extends MockObjectTestCase
10 {
11     private static final String JavaDoc INVALID_METHOD_NAME = "invalidMethodName()";
12     private static final String JavaDoc METHOD_NAME_NOT_IN_MOCKED_INTERFACE = "methodNameNotInMockedInterface";
13
14     public void testInvalidMethodNameCausesTestError() {
15         Mock mock = mock(Types.class);
16
17         try {
18             mock.stubs().method(INVALID_METHOD_NAME);
19         }
20         catch( IllegalArgumentException JavaDoc ex ) {
21             AssertMo.assertIncludes( "should contain invalid method name",
22                                      INVALID_METHOD_NAME, ex.getMessage() );
23             return;
24         }
25         fail("should have caused test error");
26     }
27
28     public void testMethodNameNotInMockedTypeCausesTestFailure() {
29         Mock mock = mock(Types.class);
30
31         try {
32             mock.stubs().method(METHOD_NAME_NOT_IN_MOCKED_INTERFACE);
33         }
34         catch( AssertionFailedError ex ) {
35             AssertMo.assertIncludes( "should contain invalid method name",
36                                      METHOD_NAME_NOT_IN_MOCKED_INTERFACE, ex.getMessage() );
37             return;
38         }
39         fail("should have caused test failure");
40     }
41 }
42
Popular Tags