Code example for AbstractMap.SimpleImmutableEntry

0
 
import tests.util.SerializationTester; 
 
public class SimpleImmutableEntryTest extends TestCase {
    public void test_SimpleImmutableEntry_Constructor_K_V() throws Exception { 
        new AbstractMap.SimpleImmutableEntry<Integer, String>(1,"test");
        new AbstractMap.SimpleImmutableEntry(null,null);        
    } 
     
    public void test_SimpleImmutableEntry_Constructor_LEntry() throws Exception { 
        Map map = new TreeMap();
        map.put(1, "test");
        Entry entryToPut = (Entry)map.entrySet().iterator().next();
        Entry testEntry = new AbstractMap.SimpleImmutableEntry(entryToPut);
        assertEquals(1,testEntry.getKey());
        assertEquals("test",testEntry.getValue());
        map.clear();
        map.put(null, null);
        entryToPut = (Entry)map.entrySet().iterator().next();
        testEntry = new AbstractMap.SimpleImmutableEntry(entryToPut);
        assertNull(testEntry.getKey());