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 import org.apache.commons.collections.Unmodifiable; 25 26 34 public class TestUnmodifiableMapEntry extends AbstractTestMapEntry { 35 36 public TestUnmodifiableMapEntry(String testName) { 37 super(testName); 38 39 } 40 41 public static void main(String [] args) { 42 junit.textui.TestRunner.run(TestUnmodifiableMapEntry.class); 43 } 44 45 public static Test suite() { 46 return new TestSuite(TestUnmodifiableMapEntry.class); 47 } 48 49 55 public Map.Entry makeMapEntry() { 56 return new UnmodifiableMapEntry(null, null); 57 } 58 59 64 public Map.Entry makeMapEntry(Object key, Object value) { 65 return new UnmodifiableMapEntry(key, value); 66 } 67 68 73 public void testConstructors() { 74 Map.Entry entry = new UnmodifiableMapEntry(key, value); 76 assertSame(key, entry.getKey()); 77 assertSame(value, entry.getValue()); 78 79 KeyValue pair = new DefaultKeyValue(key, value); 81 entry = new UnmodifiableMapEntry(pair); 82 assertSame(key, entry.getKey()); 83 assertSame(value, entry.getValue()); 84 85 Map.Entry entry2 = new UnmodifiableMapEntry(entry); 87 assertSame(key, entry2.getKey()); 88 assertSame(value, entry2.getValue()); 89 90 assertTrue(entry instanceof Unmodifiable); 91 } 92 93 public void testAccessorsAndMutators() { 94 Map.Entry entry = makeMapEntry(key, value); 95 96 assertSame(key, entry.getKey()); 97 assertSame(value, entry.getValue()); 98 99 entry = makeMapEntry(null, null); 101 assertSame(null, entry.getKey()); 102 assertSame(null, entry.getValue()); 103 } 104 105 public void testSelfReferenceHandling() { 106 } 108 109 public void testUnmodifiable() { 110 Map.Entry entry = makeMapEntry(); 111 try { 112 entry.setValue(null); 113 fail(); 114 115 } catch (UnsupportedOperationException ex) {} 116 } 117 118 } 119 | Popular Tags |