1 /*
2 * Copyright (c) 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
41 @Test
42 public class TestJapaneseChronology {
43 private static final JapaneseChronology JAPANESE = JapaneseChronology.INSTANCE;
44 private static final Locale jaJPJP = Locale.forLanguageTag("ja-JP-u-ca-japanese");
45
46 @DataProvider(name="transitions")
47 Object[][] transitionData() {
48 return new Object[][] {
49 // Japanese era, yearOfEra, month, dayOfMonth, gregorianYear
50 { JapaneseEra.MEIJI, 6, 1, 1, 1873 },
51 // Meiji-Taisho transition isn't accurate. 1912-07-30 is the last day of Meiji
52 // and the first day of Taisho.
53 { JapaneseEra.MEIJI, 45, 7, 29, 1912 },
54 { JapaneseEra.TAISHO, 1, 7, 30, 1912 },
55 // Same for Taisho-Showa transition. 1926-12-25 is the last day of Taisho
56 // and the first day of Showa.
57 { JapaneseEra.TAISHO, 15, 12, 24, 1926 },
58 { JapaneseEra.SHOWA, 1, 12, 25, 1926 },
59 { JapaneseEra.SHOWA, 64, 1, 7, 1989 },
60 { JapaneseEra.HEISEI, 1, 1, 8, 1989 },
61 };
62 }
63
64 @DataProvider(name="day_year_data")
65 Object[][] dayYearData() {
66 return new Object[][] {
67 // Japanese era, yearOfEra, dayOfYear, month, dayOfMonth
68 { JapaneseEra.MEIJI, 45, 211, 7, 29 },
69 { JapaneseEra.TAISHO, 1, 1, 7, 30 },
70 { JapaneseEra.TAISHO, 2, 60, 3, 1 },
71 { JapaneseEra.TAISHO, 15, 358, 12, 24 },
72 { JapaneseEra.SHOWA, 1, 1, 12, 25 },
73 { JapaneseEra.SHOWA, 2, 8, 1, 8 },
74 { JapaneseEra.SHOWA, 64, 7, 1, 7 },
75 { JapaneseEra.HEISEI, 1, 1, 1, 8 },
76 { JapaneseEra.HEISEI, 2, 8, 1, 8 },
77 };
78 }
79
80 @DataProvider(name="range_data")
81 Object[][] rangeData() {
82 return new Object[][] {
83 // field, minSmallest, minLargest, maxSmallest, maxLargest
84 { ChronoField.ERA, -1, -1, 2, 2},
85 { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era
86 { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
87 { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
88 };
89 }
90
91 @DataProvider(name="invalid_dates")
92 Object[][] invalidDatesData() {
93 return new Object[][] {
94 // Japanese era, yearOfEra, month, dayOfMonth
95 { JapaneseEra.MEIJI, 6, 2, 29 },
96 { JapaneseEra.MEIJI, 45, 7, 30 },
97 { JapaneseEra.MEIJI, 46, 1, 1 },
98 { JapaneseEra.TAISHO, 1, 7, 29 },
99 { JapaneseEra.TAISHO, 2, 2, 29 },
100 { JapaneseEra.TAISHO, 15, 12, 25 },
101 { JapaneseEra.TAISHO, 16, 1, 1 },
102 { JapaneseEra.SHOWA, 1, 12, 24 },
103 { JapaneseEra.SHOWA, 2, 2, 29 },
104 { JapaneseEra.SHOWA, 64, 1, 8 },
105 { JapaneseEra.SHOWA, 65, 1, 1 },
106 { JapaneseEra.HEISEI, 1, 1, 7 },
107 { JapaneseEra.HEISEI, 1, 2, 29 },
108 { JapaneseEra.HEISEI, Year.MAX_VALUE, 12, 31 },
109 };
110 }
111
112 @DataProvider(name="invalid_eraYear")
113 Object[][] invalidEraYearData() {
114 return new Object[][] {
115 // Japanese era, yearOfEra
116 { JapaneseEra.MEIJI, -1 },
117 { JapaneseEra.MEIJI, 0 },
118 { JapaneseEra.MEIJI, 46 },
119 { JapaneseEra.TAISHO, -1 },
120 { JapaneseEra.TAISHO, 0 },
121 { JapaneseEra.TAISHO, 16 },
122 { JapaneseEra.SHOWA, -1 },
123 { JapaneseEra.SHOWA, 0 },
124 { JapaneseEra.SHOWA, 65 },
125 { JapaneseEra.HEISEI, -1 },
126 { JapaneseEra.HEISEI, 0 },
127 { JapaneseEra.HEISEI, Year.MAX_VALUE },
128 };
129 }
130
131 @DataProvider(name="invalid_day_year_data")
132 Object[][] invalidDayYearData() {
133 return new Object[][] {
134 // Japanese era, yearOfEra, dayOfYear
135 { JapaneseEra.MEIJI, 45, 240 },
136 { JapaneseEra.TAISHO, 1, 365 },
137 { JapaneseEra.TAISHO, 2, 366 },
138 { JapaneseEra.TAISHO, 15, 359 },
139 { JapaneseEra.SHOWA, 1, 8 },
140 { JapaneseEra.SHOWA, 2, 366 },
141 { JapaneseEra.SHOWA, 64, 8 },
142 { JapaneseEra.HEISEI, 1, 360 },
143 { JapaneseEra.HEISEI, 2, 366 },
144 };
145 }
146
147 @Test
148 public void test_ofLocale() {
149 // must be a singleton
150 assertEquals(Chronology.ofLocale(jaJPJP) == JAPANESE, true);
151 }
152
153 @Test(dataProvider="transitions")
154 public void test_transitions(JapaneseEra era, int yearOfEra, int month, int dayOfMonth, int gregorianYear) {
155 assertEquals(JAPANESE.prolepticYear(era, yearOfEra), gregorianYear);
156
157 JapaneseDate jdate1 = JapaneseDate.of(era, yearOfEra, month, dayOfMonth);
158 JapaneseDate jdate2 = JapaneseDate.of(gregorianYear, month, dayOfMonth);
159 assertEquals(jdate1, jdate2);
160 }
161
162 @Test(dataProvider="range_data")
163 public void test_range(ChronoField field, int minSmallest, int minLargest, int maxSmallest, int maxLargest) {
|
1 /*
2 * Copyright (c) 2013, 2019, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
41 @Test
42 public class TestJapaneseChronology {
43 private static final JapaneseChronology JAPANESE = JapaneseChronology.INSTANCE;
44 private static final Locale jaJPJP = Locale.forLanguageTag("ja-JP-u-ca-japanese");
45
46 @DataProvider(name="transitions")
47 Object[][] transitionData() {
48 return new Object[][] {
49 // Japanese era, yearOfEra, month, dayOfMonth, gregorianYear
50 { JapaneseEra.MEIJI, 6, 1, 1, 1873 },
51 // Meiji-Taisho transition isn't accurate. 1912-07-30 is the last day of Meiji
52 // and the first day of Taisho.
53 { JapaneseEra.MEIJI, 45, 7, 29, 1912 },
54 { JapaneseEra.TAISHO, 1, 7, 30, 1912 },
55 // Same for Taisho-Showa transition. 1926-12-25 is the last day of Taisho
56 // and the first day of Showa.
57 { JapaneseEra.TAISHO, 15, 12, 24, 1926 },
58 { JapaneseEra.SHOWA, 1, 12, 25, 1926 },
59 { JapaneseEra.SHOWA, 64, 1, 7, 1989 },
60 { JapaneseEra.HEISEI, 1, 1, 8, 1989 },
61 { JapaneseEra.HEISEI, 31, 4, 30, 2019 },
62 { JapaneseEra.of(3), 1, 5, 1, 2019 }, // NEWERA
63 };
64 }
65
66 @DataProvider(name="day_year_data")
67 Object[][] dayYearData() {
68 return new Object[][] {
69 // Japanese era, yearOfEra, dayOfYear, month, dayOfMonth
70 { JapaneseEra.MEIJI, 45, 211, 7, 29 },
71 { JapaneseEra.TAISHO, 1, 1, 7, 30 },
72 { JapaneseEra.TAISHO, 2, 60, 3, 1 },
73 { JapaneseEra.TAISHO, 15, 358, 12, 24 },
74 { JapaneseEra.SHOWA, 1, 1, 12, 25 },
75 { JapaneseEra.SHOWA, 2, 8, 1, 8 },
76 { JapaneseEra.SHOWA, 64, 7, 1, 7 },
77 { JapaneseEra.HEISEI, 1, 1, 1, 8 },
78 { JapaneseEra.HEISEI, 2, 8, 1, 8 },
79 { JapaneseEra.HEISEI, 31, 120, 4, 30 },
80 { JapaneseEra.of(3), 1, 1, 5, 1 }, // NEWERA
81 };
82 }
83
84 @DataProvider(name="range_data")
85 Object[][] rangeData() {
86 return new Object[][] {
87 // field, minSmallest, minLargest, maxSmallest, maxLargest
88 { ChronoField.ERA, -1, -1, 3, 3},
89 { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-2019}, // depends on the current era
90 { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
91 { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
92 };
93 }
94
95 @DataProvider(name="invalid_dates")
96 Object[][] invalidDatesData() {
97 return new Object[][] {
98 // Japanese era, yearOfEra, month, dayOfMonth
99 { JapaneseEra.MEIJI, 6, 2, 29 },
100 { JapaneseEra.MEIJI, 45, 7, 30 },
101 { JapaneseEra.MEIJI, 46, 1, 1 },
102 { JapaneseEra.TAISHO, 1, 7, 29 },
103 { JapaneseEra.TAISHO, 2, 2, 29 },
104 { JapaneseEra.TAISHO, 15, 12, 25 },
105 { JapaneseEra.TAISHO, 16, 1, 1 },
106 { JapaneseEra.SHOWA, 1, 12, 24 },
107 { JapaneseEra.SHOWA, 2, 2, 29 },
108 { JapaneseEra.SHOWA, 64, 1, 8 },
109 { JapaneseEra.SHOWA, 65, 1, 1 },
110 { JapaneseEra.HEISEI, 1, 1, 7 },
111 { JapaneseEra.HEISEI, 1, 2, 29 },
112 { JapaneseEra.HEISEI, 31, 5, 1 },
113 { JapaneseEra.of(3), 1, 4, 30 }, // NEWERA
114 { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 }, // NEWERA
115 };
116 }
117
118 @DataProvider(name="invalid_eraYear")
119 Object[][] invalidEraYearData() {
120 return new Object[][] {
121 // Japanese era, yearOfEra
122 { JapaneseEra.MEIJI, -1 },
123 { JapaneseEra.MEIJI, 0 },
124 { JapaneseEra.MEIJI, 46 },
125 { JapaneseEra.TAISHO, -1 },
126 { JapaneseEra.TAISHO, 0 },
127 { JapaneseEra.TAISHO, 16 },
128 { JapaneseEra.SHOWA, -1 },
129 { JapaneseEra.SHOWA, 0 },
130 { JapaneseEra.SHOWA, 65 },
131 { JapaneseEra.HEISEI, -1 },
132 { JapaneseEra.HEISEI, 0 },
133 { JapaneseEra.HEISEI, 32 },
134 { JapaneseEra.of(3), -1 }, // NEWERA
135 { JapaneseEra.of(3), 0 }, // NEWERA
136 { JapaneseEra.of(3), Year.MAX_VALUE }, // NEWERA
137 };
138 }
139
140 @DataProvider(name="invalid_day_year_data")
141 Object[][] invalidDayYearData() {
142 return new Object[][] {
143 // Japanese era, yearOfEra, dayOfYear
144 { JapaneseEra.MEIJI, 45, 240 },
145 { JapaneseEra.TAISHO, 1, 365 },
146 { JapaneseEra.TAISHO, 2, 366 },
147 { JapaneseEra.TAISHO, 15, 359 },
148 { JapaneseEra.SHOWA, 1, 8 },
149 { JapaneseEra.SHOWA, 2, 366 },
150 { JapaneseEra.SHOWA, 64, 8 },
151 { JapaneseEra.HEISEI, 1, 360 },
152 { JapaneseEra.HEISEI, 2, 366 },
153 { JapaneseEra.HEISEI, 31, 121 },
154 { JapaneseEra.of(3), 1, 246 }, // NEWERA
155 { JapaneseEra.of(3), 2, 367 }, // NEWERA
156 };
157 }
158
159 @Test
160 public void test_ofLocale() {
161 // must be a singleton
162 assertEquals(Chronology.ofLocale(jaJPJP) == JAPANESE, true);
163 }
164
165 @Test(dataProvider="transitions")
166 public void test_transitions(JapaneseEra era, int yearOfEra, int month, int dayOfMonth, int gregorianYear) {
167 assertEquals(JAPANESE.prolepticYear(era, yearOfEra), gregorianYear);
168
169 JapaneseDate jdate1 = JapaneseDate.of(era, yearOfEra, month, dayOfMonth);
170 JapaneseDate jdate2 = JapaneseDate.of(gregorianYear, month, dayOfMonth);
171 assertEquals(jdate1, jdate2);
172 }
173
174 @Test(dataProvider="range_data")
175 public void test_range(ChronoField field, int minSmallest, int minLargest, int maxSmallest, int maxLargest) {
|