1 package test.mockobjects; 2 3 import junit.awtui.TestRunner; 4 import junit.framework.*; 5 import com.mockobjects.*; 6 import com.mockobjects.util.*; 7 8 11 12 public class TestExpectationMap extends TestCaseMo { 13 private static final Class THIS = TestExpectationMap.class; 14 15 public TestExpectationMap(String name) { 16 super(name); 17 } 18 19 public static void main(String [] args) { 20 TestRunner.run(THIS); 21 } 22 23 public void testExpectMissingEntry() { 24 ExpectationMap map = new ExpectationMap("map"); 25 26 map.addExpectedMissing("key"); 27 assertEquals("one entry", null, map.get("key")); 28 map.verify(); 29 } 30 31 public void testExpectNullEntry() { 32 33 ExpectationMap map = new ExpectationMap("map"); 34 35 try { 36 map.addExpected("key", null); 37 assertEquals("one entry", null, map.get("key")); 38 map.verify(); 39 } catch (NullPointerException ex) { 40 AssertMo.assertStartsWith( 41 "Should be JDK 1.1.7A", 42 "1.1", 43 System.getProperty("java.version")); 44 } 45 } 46 47 public void testExpectOneEntry() { 48 ExpectationMap map = new ExpectationMap("map"); 49 50 map.addExpected("key", "value"); 51 assertEquals("one entry", "value", map.get("key")); 52 map.verify(); 53 } 54 55 public void testExpectTwoEntries() { 56 ExpectationMap map = new ExpectationMap("map"); 57 58 map.addExpected("key", "value"); 59 map.addExpected("key1", "value1"); 60 61 assertEquals("two entries", "value", map.get("key")); 62 assertEquals("two entries", "value1", map.get("key1")); 63 map.verify(); 64 } 65 66 public void testFailOneEntry() { 67 try { 68 ExpectationMap map = new ExpectationMap("map"); 69 map.setExpectNothing(); 70 map.get("key"); 71 } catch (AssertionFailedError ex) { 72 return; 73 } 74 fail("should fail one entry"); 75 } 76 77 public void testFailOnVerify() { 78 ExpectationMap map = new ExpectationMap("map"); 79 map.setExpectNothing(); 80 map.setFailOnVerify(); 81 map.get("key"); 82 83 try { 84 map.verify(); 85 } catch (AssertionFailedError ex) { 86 return; 87 } 88 fail("should fail one entry"); 89 } 90 91 public void testOverwriteEntry() { 92 ExpectationMap map = new ExpectationMap("map"); 93 94 map.addExpected("key", "value"); 95 map.addExpected("key", "value1"); 96 97 assertEquals("overwrite entry", "value1", map.get("key")); 98 map.verify(); 99 } 100 } 101 | Popular Tags |