Path: blob/master/test/jdk/java/util/Calendar/SupplementalJapaneseEraTestRun.java
41149 views
/*1* Copyright (c) 2014, 2019, 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 8048123 8054214 817342326* @summary Test for jdk.calendar.japanese.supplemental.era support27* @library /test/lib28* @build SupplementalJapaneseEraTest29* @run testng/othervm SupplementalJapaneseEraTestRun30*/3132import java.util.Calendar;33import java.util.List;34import java.util.Locale;35import java.util.TimeZone;36import static java.util.Calendar.*;3738import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.JDKToolLauncher;40import jdk.test.lib.Utils;4142import org.testng.annotations.DataProvider;43import org.testng.annotations.Test;4445public class SupplementalJapaneseEraTestRun {46@DataProvider(name = "validprop")47Object[][] validPropertyData() {48return new Object[][] {49//Tests with valid property values50{"name=SupEra,abbr=S.E.,since="},51{"name = SupEra, abbr = S.E., since = "},52};53}5455@DataProvider(name = "invalidprop")56Object[][] invalidPropertyData() {57return new Object[][] {58//Tests with invalid property values59{"=SupEra,abbr=S.E.,since="},60{"=,abbr=S.E.,since="},61{"name,abbr=S.E.,since="},62{"abbr=S.E.,since="},63{"name=SupEra,since="},64{"name=,abbr=S.E.,since"},65{"name=SupEra,abbr=,since="},66{"name=SupEra,abbr=S.E."},67{"name=SupEra,abbr=S.E.,since=0"},68//since=9223372036854775808 the number means Long.MAX_VALUE+169{"name=SupEra,abbr=S.E.,since=9223372036854775808"},70};71}7273@Test(dataProvider = "validprop")74public void ValidPropertyValuesTest(String prop)75throws Throwable {76//get the start time of the fictional next era77String startTime = getStartTime();78testRun(prop + startTime, List.of("-t"));79}8081@Test(dataProvider = "invalidprop")82public void InvalidPropertyValuesTest(String prop)83throws Throwable {84//get the start time of the fictional next era85String startTime = getStartTime();86//get the name of the current era to be used to confirm that87//invalid property values are ignored.88String currentEra = getCurrentEra();89testRun(prop + startTime, List.of("-b", currentEra));90}9192private static void testRun(String property, List<String> javaParam)93throws Throwable{94JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");95launcher.addToolArg("-ea")96.addToolArg("-esa")97.addToolArg("-cp")98.addToolArg(Utils.TEST_CLASS_PATH)99.addToolArg("-Djdk.calendar.japanese.supplemental.era=" + property)100.addToolArg("SupplementalJapaneseEraTest");101for (String para: javaParam) {102launcher.addToolArg(para);103}104int exitCode = ProcessTools.executeCommand(launcher.getCommand())105.getExitValue();106System.out.println(property + ":pass");107if (exitCode != 0) {108System.out.println(property + ":fail");109throw new RuntimeException("Unexpected exit code: " + exitCode);110}111}112113private static String getStartTime(){114Calendar cal = new Calendar.Builder().setCalendarType("japanese")115.setTimeZone(TimeZone.getTimeZone("GMT")).setFields(ERA, 5)116.setDate(200, FEBRUARY, 11).build();117return String.valueOf(cal.getTimeInMillis());118}119120private static String getCurrentEra(){121Calendar jcal = new Calendar.Builder()122.setCalendarType("japanese")123.setFields(YEAR, 1, DAY_OF_YEAR, 1)124.build();125return jcal.getDisplayName(ERA, LONG, Locale.US);126}127}128129130