Path: blob/master/test/jdk/java/util/Calendar/JapaneseLenientEraTest.java
41149 views
/*1* Copyright (c) 2018, 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 820612026* @summary Test whether lenient era is accepted in JapaneseImperialCalendar27* @run testng/othervm JapaneseLenientEraTest28*/2930import java.text.DateFormat;31import java.text.SimpleDateFormat;32import java.util.Calendar;33import java.util.Date;34import java.util.Locale;3536import org.testng.annotations.DataProvider;37import org.testng.annotations.Test;38import static org.testng.Assert.assertEquals;3940@Test41public class JapaneseLenientEraTest {4243@DataProvider(name="lenientEra")44Object[][] names() {45return new Object[][] {46// lenient era/year, strict era/year47{ "Meiji 123", "Heisei 2" },48{ "Sh\u014dwa 65", "Heisei 2" },49{ "Heisei 32", "Reiwa 2" },50};51}5253@Test(dataProvider="lenientEra")54public void testLenientEra(String lenient, String strict) throws Exception {55Calendar c = new Calendar.Builder()56.setCalendarType("japanese")57.build();58DateFormat df = new SimpleDateFormat("GGGG y-M-d", Locale.ROOT);59df.setCalendar(c);60Date lenDate = df.parse(lenient + "-01-01");61df.setLenient(false);62Date strDate = df.parse(strict + "-01-01");63assertEquals(lenDate, strDate);64}65}666768