1 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 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 [0]); 23 testFailureStub = new TestFailureStub(MESSAGE); 24 } 25 26 public void testThrowsAssertionFailedErrorWhenInvoked() throws Throwable { 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 buffer = new StringBuffer (); 40 41 testFailureStub.describeTo(buffer); 42 43 String description = buffer.toString(); 44 45 assertTrue("contains error message in description", 46 description.indexOf(MESSAGE) >= 0); 47 } 48 } 49 | Popular Tags |