1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */ 2 package org.jmock.expectation; 3 4 import junit.framework.AssertionFailedError; 5 import org.jmock.AbstractTestCase; 6 7 public class TestExpectationMap extends AbstractTestCase { 8 9 public void testExpectMissingEntry() { 10 ExpectationMap map = new ExpectationMap("map"); 11 12 map.addExpectedMissing("key"); 13 assertEquals("one entry", null, map.get("key")); 14 map.verify(); 15 } 16 17 public void testExpectNullEntry() { 18 19 ExpectationMap map = new ExpectationMap("map"); 20 21 try { 22 map.addExpected("key", null); 23 assertEquals("one entry", null, map.get("key")); 24 map.verify(); 25 } catch (NullPointerException ex) { 26 AssertMo.assertStartsWith( 27 "Should be JDK 1.1.7A", 28 "1.1", 29 System.getProperty("java.version")); 30 } 31 } 32 33 public void testExpectOneEntry() { 34 ExpectationMap map = new ExpectationMap("map"); 35 36 map.addExpected("key", "value"); 37 assertEquals("one entry", "value", map.get("key")); 38 map.verify(); 39 } 40 41 public void testExpectTwoEntries() { 42 ExpectationMap map = new ExpectationMap("map"); 43 44 map.addExpected("key", "value"); 45 map.addExpected("key1", "value1"); 46 47 assertEquals("two entries", "value", map.get("key")); 48 assertEquals("two entries", "value1", map.get("key1")); 49 map.verify(); 50 } 51 52 public void testFailOneEntry() { 53 try { 54 ExpectationMap map = new ExpectationMap("map"); 55 map.setExpectNothing(); 56 map.get("key"); 57 } catch (AssertionFailedError ex) { 58 return; 59 } 60 fail("should fail one entry"); 61 } 62 63 public void testFailOnVerify() { 64 ExpectationMap map = new ExpectationMap("map"); 65 map.setExpectNothing(); 66 map.setFailOnVerify(); 67 map.get("key"); 68 69 try { 70 map.verify(); 71 } catch (AssertionFailedError ex) { 72 return; 73 } 74 fail("should fail one entry"); 75 } 76 77 public void testOverwriteEntry() { 78 ExpectationMap map = new ExpectationMap("map"); 79 80 map.addExpected("key", "value"); 81 map.addExpected("key", "value1"); 82 83 assertEquals("overwrite entry", "value1", map.get("key")); 84 map.verify(); 85 } 86 }

This page was automatically generated by Maven