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 dalvik.annotation.TestTargets;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26import java.util.HashMap;
27import java.util.Map;
28
29import org.apache.harmony.testframework.serialization.SerializationTest;
30
31@TestTargetClass(HashMap.class)
32public class HashMapTest extends TestCase {
33    class SubMap<K, V> extends HashMap<K, V> {
34        public SubMap(Map<? extends K, ? extends V> m) {
35            super(m);
36        }
37
38        public V put(K key, V value) {
39            throw new UnsupportedOperationException();
40        }
41    }
42
43    /**
44     * @tests java.util.HashMap#HashMap(java.util.Map)
45     */
46    @TestTargetNew(
47        level = TestLevel.PARTIAL_COMPLETE,
48        notes = "NullPointerException is not verified.",
49        method = "HashMap",
50        args = {java.util.Map.class}
51    )
52    public void test_ConstructorLjava_util_Map() {
53        HashMap map = new HashMap();
54        map.put("a", "a");
55        SubMap map2 = new SubMap(map);
56        assertTrue(map2.containsKey("a"));
57        assertTrue(map2.containsValue("a"));
58    }
59
60    /**
61     * @tests serialization/deserialization.
62     */
63    @TestTargetNew(
64        level = TestLevel.COMPLETE,
65        notes = "",
66        method = "!SerializationSelf",
67        args = {}
68    )
69    public void testSerializationSelf() throws Exception {
70        HashMap<String, String> hm = new HashMap<String, String>();
71        hm.put("key", "value");
72
73        SerializationTest.verifySelf(hm);
74
75        //  regression for HARMONY-1583
76        hm.put(null, "null");
77        SerializationTest.verifySelf(hm);
78    }
79
80    /**
81     * @tests serialization/deserialization compatibility with RI.
82     */
83    @TestTargetNew(
84        level = TestLevel.COMPLETE,
85        notes = "",
86        method = "!SerializationGolden",
87        args = {}
88    )
89    public void testSerializationCompatibility() throws Exception {
90        HashMap<String, String> hm = new HashMap<String, String>();
91        hm.put("key", "value");
92
93        SerializationTest.verifyGolden(this, hm);
94    }
95}
96