Path: blob/master/test/jdk/java/util/Locale/Bug8154797.java
41149 views
/*1* Copyright (c) 2016, 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* @test25* @bug 815479726* @modules java.base/sun.util.locale.provider27* java.base/sun.util.resources28* jdk.localedata29* @summary Test for checking HourFormat and GmtFormat resources are retrieved from30* COMPAT and CLDR Providers.31*/3233import java.util.HashMap;34import java.util.Locale;35import java.util.Map;36import java.util.ResourceBundle;37import sun.util.locale.provider.LocaleProviderAdapter.Type;38import sun.util.locale.provider.LocaleProviderAdapter;3940public class Bug8154797 {41static Map<String, String> expectedResourcesMap = new HashMap<>();42static final String GMT_RESOURCE_KEY = "timezone.gmtFormat";43static final String HMT_RESOURCE_KEY = "timezone.hourFormat";44static final String GMT = "Gmt";45static final String HMT = "Hmt";4647static void generateExpectedValues() {48expectedResourcesMap.put("FR" + GMT, "UTC{0}");49expectedResourcesMap.put("FR" + HMT, "+HH:mm;\u2212HH:mm");50expectedResourcesMap.put("FI" + HMT, "+H.mm;-H.mm");51expectedResourcesMap.put("FI" + GMT, "UTC{0}");52/* For root locale, en_US, de_DE, hi_IN, ja_JP,Root locale resources53* should be returned.54*/55expectedResourcesMap.put(GMT, "GMT{0}"); //Root locale resource56expectedResourcesMap.put(HMT, "+HH:mm;-HH:mm"); //Root locale resource57}5859static void compareResources(Locale loc) {60String mapKeyHourFormat = HMT, mapKeyGmtFormat = GMT;61ResourceBundle compatBundle, cldrBundle;62compatBundle = LocaleProviderAdapter.forJRE().getLocaleResources(loc)63.getJavaTimeFormatData();64cldrBundle = LocaleProviderAdapter.forType(Type.CLDR)65.getLocaleResources(loc).getJavaTimeFormatData();66if (loc.getCountry() == "FR" || loc.getCountry() == "FI") {67mapKeyHourFormat = loc.getCountry() + HMT;68mapKeyGmtFormat = loc.getCountry() + GMT;69}7071if (!(expectedResourcesMap.get(mapKeyGmtFormat)72.equals(compatBundle.getString(GMT_RESOURCE_KEY))73&& expectedResourcesMap.get(mapKeyHourFormat)74.equals(compatBundle.getString(HMT_RESOURCE_KEY))75&& expectedResourcesMap.get(mapKeyGmtFormat)76.equals(cldrBundle.getString(GMT_RESOURCE_KEY))77&& expectedResourcesMap.get(mapKeyHourFormat)78.equals(cldrBundle.getString(HMT_RESOURCE_KEY)))) {7980throw new RuntimeException("Retrieved resource does not match with "81+ " expected string for Locale " + compatBundle.getLocale());8283}8485}8687public static void main(String args[]) {88Bug8154797.generateExpectedValues();89Locale[] locArr = {new Locale("hi", "IN"), Locale.UK, new Locale("fi", "FI"),90Locale.ROOT, Locale.GERMAN, Locale.JAPANESE,91Locale.ENGLISH, Locale.FRANCE};92for (Locale loc : locArr) {93Bug8154797.compareResources(loc);94}95}9697}9899100101