HashMapTest.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.apache.harmony.luni.tests.java.util; 18 19import java.util.HashMap; 20import java.util.Map; 21 22import junit.framework.TestCase; 23 24import org.apache.harmony.testframework.serialization.SerializationTest; 25 26public class HashMapTest extends TestCase { 27 class SubMap<K, V> extends HashMap<K, V> { 28 public SubMap(Map<? extends K, ? extends V> m) { 29 super(m); 30 } 31 32 public V put(K key, V value) { 33 throw new UnsupportedOperationException(); 34 } 35 } 36 37 /** 38 * @tests java.util.HashMap#HashMap(java.util.Map) 39 */ 40 public void test_ConstructorLjava_util_Map() { 41 HashMap map = new HashMap(); 42 map.put("a", "a"); 43 SubMap map2 = new SubMap(map); 44 assertTrue(map2.containsKey("a")); 45 assertTrue(map2.containsValue("a")); 46 } 47 48 /** 49 * @tests serialization/deserialization. 50 */ 51 public void testSerializationSelf() throws Exception { 52 HashMap<String, String> hm = new HashMap<String, String>(); 53 hm.put("key", "value"); 54 55 SerializationTest.verifySelf(hm); 56 57 // regression for HARMONY-1583 58 hm.put(null, "null"); 59 SerializationTest.verifySelf(hm); 60 } 61 62 /** 63 * @tests serialization/deserialization compatibility with RI. 64 */ 65 public void testSerializationCompatibility() throws Exception { 66 HashMap<String, String> hm = new HashMap<String, String>(); 67 hm.put("key", "value"); 68 69 SerializationTest.verifyGolden(this, hm); 70 } 71} 72