1 3 package test.jmock.util; 4 5 import junit.framework.TestCase; 6 import org.jmock.util.Dummy; 7 import org.jmock.util.NotImplementedException; 8 9 10 public class DummyTest extends TestCase 11 { 12 private static final String DUMMY_NAME = "DUMMY NAME"; 13 14 interface ExampleInterface 15 { 16 void method1(); 17 } 18 19 public void testCanCreateDummyObjectsThatReturnANameFromString() { 20 Object dummy = Dummy.newDummy(DUMMY_NAME); 21 22 assertEquals("should return name from toString", 23 DUMMY_NAME, dummy.toString()); 24 } 25 26 public void testImplementsAGivenInterface() { 27 Object dummy = Dummy.newDummy(ExampleInterface.class); 28 29 assertTrue("should be instanceof ExampleInterface", 30 dummy instanceof ExampleInterface); 31 } 32 33 public void testCanBeGivenAnExplicitNameThatIsReturnedByToString() { 34 Object dummy = Dummy.newDummy(ExampleInterface.class, DUMMY_NAME); 35 36 assertEquals("should return name from toString", 37 DUMMY_NAME, dummy.toString()); 38 } 39 40 public void testGetsAUsefulDefaultName() { 41 Object dummy = Dummy.newDummy(ExampleInterface.class); 42 43 assertEquals("should return name from toString", 44 "dummyExampleInterface", dummy.toString()); 45 } 46 47 public void testImplementsEqualsByComparingObjectReferences() { 48 Object dummy = Dummy.newDummy(ExampleInterface.class); 49 50 assertTrue("should be equal to itself", dummy.equals(dummy)); 51 assertFalse("should not be equal to another object", dummy.equals(new Object ())); 52 } 53 54 public void testThrowsNotImplementedExceptionFromEveryMethod() { 55 ExampleInterface dummy = 56 (ExampleInterface)Dummy.newDummy(ExampleInterface.class, DUMMY_NAME); 57 58 try { 59 dummy.method1(); 60 fail("NotImplementedException expected from method1"); 61 } 62 catch (NotImplementedException ex) { 63 assertTrue("error message should contain name of dummy object", 64 ex.getMessage().indexOf(DUMMY_NAME) >= 0); 65 assertTrue("error message should contain name of invokedMethod", 66 ex.getMessage().indexOf("method1") >= 0); 67 } 68 } 69 } 70 | Popular Tags |