KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > stub > TestFailureStubTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.core.stub;
4
5 import junit.framework.AssertionFailedError;
6 import junit.framework.TestCase;
7 import org.jmock.core.Invocation;
8 import org.jmock.core.stub.TestFailureStub;
9 import test.jmock.core.testsupport.MethodFactory;
10
11
12 public class TestFailureStubTest
13         extends TestCase
14 {
15     static final String JavaDoc MESSAGE = "MESSAGE";
16
17     Invocation invocation;
18     TestFailureStub testFailureStub;
19
20     public void setUp() {
21         MethodFactory methodFactory = new MethodFactory();
22         invocation = new Invocation("INVOKED-OBJECT", methodFactory.newMethodReturning(void.class), new Object JavaDoc[0]);
23         testFailureStub = new TestFailureStub(MESSAGE);
24     }
25
26     public void testThrowsAssertionFailedErrorWhenInvoked() throws Throwable JavaDoc {
27         try {
28             testFailureStub.invoke(invocation);
29         }
30         catch (AssertionFailedError ex) {
31             assertEquals("should be error message from stub",
32                          MESSAGE, ex.getMessage());
33             return;
34         }
35         fail("expected AssertionFailedError");
36     }
37
38     public void testIncludesErrorMessageInDescription() {
39         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
40
41         testFailureStub.describeTo(buffer);
42
43         String JavaDoc description = buffer.toString();
44
45         assertTrue("contains error message in description",
46                    description.indexOf(MESSAGE) >= 0);
47     }
48 }
49
Popular Tags