1 16 package org.apache.commons.collections.keyvalue; 17 18 import java.util.Map ; 19 20 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.commons.collections.KeyValue; 24 25 33 public class TestDefaultMapEntry extends AbstractTestMapEntry { 34 35 public TestDefaultMapEntry(String testName) { 36 super(testName); 37 38 } 39 40 public static void main(String [] args) { 41 junit.textui.TestRunner.run(TestDefaultMapEntry.class); 42 } 43 44 public static Test suite() { 45 return new TestSuite(TestDefaultMapEntry.class); 46 } 47 48 54 public Map.Entry makeMapEntry() { 55 return new DefaultMapEntry(null, null); 56 } 57 58 63 public Map.Entry makeMapEntry(Object key, Object value) { 64 return new DefaultMapEntry(key, value); 65 } 66 67 72 public void testConstructors() { 73 Map.Entry entry = new DefaultMapEntry(key, value); 75 assertSame(key, entry.getKey()); 76 assertSame(value, entry.getValue()); 77 78 KeyValue pair = new DefaultKeyValue(key, value); 80 assertSame(key, pair.getKey()); 81 assertSame(value, pair.getValue()); 82 83 Map.Entry entry2 = new DefaultMapEntry(entry); 85 assertSame(key, entry2.getKey()); 86 assertSame(value, entry2.getValue()); 87 88 entry.setValue(null); 90 assertSame(value, entry2.getValue()); 91 } 92 93 public void testSelfReferenceHandling() { 94 Map.Entry entry = makeMapEntry(); 95 96 try { 97 entry.setValue(entry); 98 assertSame(entry, entry.getValue()); 99 100 } catch (Exception e) { 101 fail("This Map.Entry implementation supports value self-reference."); 102 } 103 } 104 105 } 106 | Popular Tags |