11/*
2- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2828 * java.base/sun.util.resources
2929 * jdk.localedata
3030 * @summary Test for checking HourFormat and GmtFormat resources are retrieved from
31- * COMPAT and CLDR Providers.
31+ * COMPAT and CLDR Providers.
32+ * @run junit CompareProviderFormats
3233*/
3334
3435import java .util .HashMap ;
3536import java .util .Locale ;
3637import java .util .Map ;
3738import java .util .ResourceBundle ;
39+ import java .util .stream .Stream ;
40+
3841import sun .util .locale .provider .LocaleProviderAdapter .Type ;
3942import sun .util .locale .provider .LocaleProviderAdapter ;
4043
41- public class Bug8154797 {
44+ import org .junit .jupiter .api .BeforeAll ;
45+ import org .junit .jupiter .params .ParameterizedTest ;
46+ import org .junit .jupiter .params .provider .MethodSource ;
47+
48+ public class CompareProviderFormats {
4249 static Map <String , String > expectedResourcesMap = new HashMap <>();
4350 static final String GMT_RESOURCE_KEY = "timezone.gmtFormat" ;
4451 static final String HMT_RESOURCE_KEY = "timezone.hourFormat" ;
4552 static final String GMT = "Gmt" ;
4653 static final String HMT = "Hmt" ;
4754
48- static void generateExpectedValues () {
55+ /**
56+ * Fill the expectedResourcesMap with the desired key / values
57+ */
58+ @ BeforeAll
59+ static void populateResourcesMap () {
4960 expectedResourcesMap .put ("FR" + GMT , "UTC{0}" );
5061 expectedResourcesMap .put ("FR" + HMT , "+HH:mm;\u2212 HH:mm" );
5162 expectedResourcesMap .put ("FI" + HMT , "+H.mm;-H.mm" );
5263 expectedResourcesMap .put ("FI" + GMT , "UTC{0}" );
53- /* For root locale, en_US, de_DE, hi_IN, ja_JP,Root locale resources
54- * should be returned.
64+ /* For root locale, en_US, de_DE, hi_IN, ja_JP, Root locale resources
65+ * should be returned.
5566 */
56- expectedResourcesMap .put (GMT , "GMT{0}" ); //Root locale resource
57- expectedResourcesMap .put (HMT , "+HH:mm;-HH:mm" ); //Root locale resource
67+ expectedResourcesMap .put (GMT , "GMT{0}" ); // Root locale resource
68+ expectedResourcesMap .put (HMT , "+HH:mm;-HH:mm" ); // Root locale resource
69+ }
70+
71+ /**
72+ * For each locale, ensure that the returned resources for gmt and hmt match
73+ * the expected resources for both COMPAT and CLDR
74+ */
75+ @ ParameterizedTest
76+ @ MethodSource ("localeProvider" )
77+ public void compareResourcesTest (Locale loc ) {
78+ compareResources (loc );
5879 }
5980
60- static void compareResources (Locale loc ) {
81+ private void compareResources (Locale loc ) {
6182 String mapKeyHourFormat = HMT , mapKeyGmtFormat = GMT ;
6283 ResourceBundle compatBundle , cldrBundle ;
6384 compatBundle = LocaleProviderAdapter .forJRE ().getLocaleResources (loc )
6485 .getJavaTimeFormatData ();
6586 cldrBundle = LocaleProviderAdapter .forType (Type .CLDR )
6687 .getLocaleResources (loc ).getJavaTimeFormatData ();
67- if (loc .getCountry () == "FR" || loc .getCountry () == "FI" ) {
88+
89+ if (loc .getCountry ().equals ("FR" ) || loc .getCountry ().equals ("FI" )) {
6890 mapKeyHourFormat = loc .getCountry () + HMT ;
6991 mapKeyGmtFormat = loc .getCountry () + GMT ;
7092 }
@@ -77,23 +99,17 @@ static void compareResources(Locale loc) {
7799 .equals (cldrBundle .getString (GMT_RESOURCE_KEY ))
78100 && expectedResourcesMap .get (mapKeyHourFormat )
79101 .equals (cldrBundle .getString (HMT_RESOURCE_KEY )))) {
80-
81102 throw new RuntimeException ("Retrieved resource does not match with "
82103 + " expected string for Locale " + compatBundle .getLocale ());
83-
84104 }
85-
86105 }
87106
88- public static void main (String args []) {
89- Bug8154797 .generateExpectedValues ();
90- Locale [] locArr = {new Locale ("hi" , "IN" ), Locale .UK , new Locale ("fi" , "FI" ),
91- Locale .ROOT , Locale .GERMAN , Locale .JAPANESE ,
92- Locale .ENGLISH , Locale .FRANCE };
93- for (Locale loc : locArr ) {
94- Bug8154797 .compareResources (loc );
95- }
107+ private static Stream <Locale > localeProvider () {
108+ return Stream .of (
109+ new Locale ("hi" , "IN" ),
110+ Locale .UK , new Locale ("fi" , "FI" ),
111+ Locale .ROOT , Locale .GERMAN , Locale .JAPANESE ,
112+ Locale .ENGLISH , Locale .FRANCE
113+ );
96114 }
97-
98115}
99-
0 commit comments