Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/TimeZone/OldIDMappingTest.java
38821 views
/*1* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* See OldMappingTest.sh25*/2627import java.lang.reflect.*;28import java.util.*;2930public class OldIDMappingTest {31private static final String MAPPING_PROPERTY_NAME = "sun.timezone.ids.oldmapping";32private static final Map<String, String> newmap = new HashMap<String, String>();33static {34// Add known new mappings35newmap.put("EST", "EST");36newmap.put("MST", "MST");37newmap.put("HST", "HST");38}3940public static void main(String[] args) {41boolean useOldMapping = true;42String arg = args[0];43if (arg.equals("-new")) {44useOldMapping = false;45} else if (arg.equals("-old")) {46useOldMapping = true;47} else {48throw new RuntimeException("-old or -new must be specified; got " + arg);49}5051Map<String, String> oldmap = TzIDOldMapping.MAP;52String prop = System.getProperty(MAPPING_PROPERTY_NAME);53System.out.println(MAPPING_PROPERTY_NAME + "=" + prop);5455// Try the test multiple times with modifying TimeZones to56// make sure TimeZone instances for the old mapping are57// properly copied (defensive copy).58for (int count = 0; count < 3; count++) {59for (String id : oldmap.keySet()) {60TimeZone tzAlias = TimeZone.getTimeZone(id);61TimeZone tz = TimeZone.getTimeZone(oldmap.get(id));62if (useOldMapping) {63if (!tzAlias.hasSameRules(tz)) {64throw new RuntimeException("OLDMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "65+ id + " isn't an alias of " + oldmap.get(id));66}67if (count == 0) {68System.out.println(" " + id + " => " + oldmap.get(id));69}70tzAlias.setRawOffset(tzAlias.getRawOffset() * count);71} else {72if (!newmap.containsKey(id)) {73// ignore ids not contained in the new map74if (count == 0) {75System.out.println(" " + id + " => " + oldmap.get(id));76}77tzAlias.setRawOffset(tzAlias.getRawOffset() * count);78continue;79}80if (tzAlias.hasSameRules(tz)) {81throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "82+ id + " is an alias of " + oldmap.get(id));83}84tz = TimeZone.getTimeZone(newmap.get(id));85if (!tzAlias.hasSameRules(tz)) {86throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME + "=" + prop + ": "87+ id + " isn't an alias of " + newmap.get(id));88}89if (count == 0) {90System.out.println(" " + id + " => " + newmap.get(id));91}92tzAlias.setRawOffset(tzAlias.getRawOffset() * count);93}94}95}96}97}9899100