0N/A/*
2362N/A * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
605N/A * @bug 4631471 4921212 4994637
0N/A * @summary Tests HashMap encoding
0N/A * @author Sergey Malenkov
0N/A */
0N/A
0N/Aimport java.util.HashMap;
0N/Aimport java.util.Map;
0N/A
0N/Apublic final class java_util_HashMap extends AbstractTest<Map<String, String>> {
0N/A public static void main(String[] args) {
0N/A new java_util_HashMap().test(true);
0N/A }
0N/A
605N/A @Override
0N/A protected Map<String, String> getObject() {
605N/A Map<String, String> map = new HashMap<String, String>();
605N/A map.put(null, null);
605N/A map.put("key", "value");
605N/A map.put("key-null", "null-value");
605N/A map.put("way", "remove");
605N/A return map;
0N/A }
0N/A
605N/A @Override
0N/A protected Map<String, String> getAnotherObject() {
0N/A Map<String, String> map = new HashMap<String, String>();
0N/A map.put(null, "null-value");
0N/A map.put("key", "value");
0N/A map.put("key-null", null);
0N/A return map;
0N/A }
0N/A
605N/A @Override
0N/A protected void validate(Map<String, String> before, Map<String, String> after) {
0N/A super.validate(before, after);
0N/A validate(before);
0N/A validate(after);
0N/A }
0N/A
0N/A private static void validate(Map<String, String> map) {
605N/A switch (map.size()) {
605N/A case 3:
0N/A validate(map, null, "null-value");
0N/A validate(map, "key", "value");
0N/A validate(map, "key-null", null);
605N/A break;
605N/A case 4:
605N/A validate(map, null, null);
605N/A validate(map, "key", "value");
605N/A validate(map, "key-null", "null-value");
605N/A validate(map, "way", "remove");
605N/A break;
0N/A }
0N/A }
0N/A
0N/A private static void validate(Map<String, String> map, String key, String value) {
0N/A if (!map.containsKey(key))
0N/A throw new Error("There are no key: " + key);
0N/A
0N/A if (!map.containsValue(value))
0N/A throw new Error("There are no value: " + value);
0N/A
0N/A if (!isEqual(value, map.get(key)))
0N/A throw new Error("There are no entry: " + key + ", " + value);
0N/A }
0N/A
0N/A private static boolean isEqual(String str1, String str2) {
0N/A return (str1 == null)
0N/A ? str2 == null
0N/A : str1.equals(str2);
0N/A }
0N/A}