|
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8206120 |
|
27 * @summary Test whether lenient era is accepted in JapaneseImperialCalendar |
|
28 * @run testng/othervm JapaneseLenientEraTest |
|
29 */ |
|
30 |
|
31 import java.text.DateFormat; |
|
32 import java.text.SimpleDateFormat; |
|
33 import java.util.Calendar; |
|
34 import java.util.Date; |
|
35 import java.util.Locale; |
|
36 |
|
37 import org.testng.annotations.DataProvider; |
|
38 import org.testng.annotations.Test; |
|
39 import static org.testng.Assert.assertEquals; |
|
40 |
|
41 @Test |
|
42 public class JapaneseLenientEraTest { |
|
43 |
|
44 @DataProvider(name="lenientEra") |
|
45 Object[][] names() { |
|
46 return new Object[][] { |
|
47 // lenient era/year, strict era/year |
|
48 { "Meiji 123", "Heisei 2" }, |
|
49 { "Sh\u014dwa 65", "Heisei 2" }, |
|
50 { "Heisei 32", "NewEra 2" }, // NewEra |
|
51 }; |
|
52 } |
|
53 |
|
54 @Test(dataProvider="lenientEra") |
|
55 public void testLenientEra(String lenient, String strict) throws Exception { |
|
56 Calendar c = new Calendar.Builder() |
|
57 .setCalendarType("japanese") |
|
58 .build(); |
|
59 DateFormat df = new SimpleDateFormat("GGGG y-M-d", Locale.ROOT); |
|
60 df.setCalendar(c); |
|
61 Date lenDate = df.parse(lenient + "-01-01"); |
|
62 df.setLenient(false); |
|
63 Date strDate = df.parse(strict + "-01-01"); |
|
64 assertEquals(lenDate, strDate); |
|
65 } |
|
66 } |