1 /*
2  o Copyright (c) 2012, 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
23  * questions.
24  */
25 
26 /*
27  * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
28  *
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions are met:
33  *
34  *  * Redistributions of source code must retain the above copyright notice,
35  *    this list of conditions and the following disclaimer.
36  *
37  *  * Redistributions in binary form must reproduce the above copyright notice,
38  *    this list of conditions and the following disclaimer in the documentation
39  *    and/or other materials provided with the distribution.
40  *
41  *  * Neither the name of JSR-310 nor the names of its contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
50  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
52  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
53  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
54  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  */
57 package tck.java.time.chrono;
58 
59 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
60 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
61 import static java.time.temporal.ChronoField.EPOCH_DAY;
62 import static java.time.temporal.ChronoField.ERA;
63 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
64 import static java.time.temporal.ChronoField.YEAR;
65 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
66 import static org.testng.Assert.assertEquals;
67 import static org.testng.Assert.assertFalse;
68 import static org.testng.Assert.assertNotEquals;
69 import static org.testng.Assert.assertTrue;
70 import static org.testng.Assert.fail;
71 
72 import java.time.Clock;
73 import java.time.DateTimeException;
74 import java.time.LocalDate;
75 import java.time.LocalDateTime;
76 import java.time.Month;
77 import java.time.Period;
78 import java.time.Year;
79 import java.time.ZoneId;
80 import java.time.ZoneOffset;
81 import java.time.chrono.ChronoLocalDate;
82 import java.time.chrono.ChronoPeriod;
83 import java.time.chrono.Chronology;
84 import java.time.chrono.Era;
85 import java.time.chrono.IsoChronology;
86 import java.time.chrono.JapaneseChronology;
87 import java.time.chrono.JapaneseDate;
88 import java.time.chrono.JapaneseEra;
89 import java.time.chrono.MinguoChronology;
90 import java.time.chrono.MinguoDate;
91 import java.time.chrono.ThaiBuddhistChronology;
92 import java.time.format.ResolverStyle;
93 import java.time.temporal.ChronoField;
94 import java.time.temporal.ChronoUnit;
95 import java.time.temporal.TemporalAdjusters;
96 import java.time.temporal.TemporalField;
97 import java.time.temporal.TemporalQueries;
98 import java.time.temporal.ValueRange;
99 
100 import java.util.HashMap;
101 import java.util.List;
102 import java.util.Locale;
103 import java.util.Map;
104 
105 import org.testng.Assert;
106 import org.testng.annotations.DataProvider;
107 import org.testng.annotations.Test;
108 
109 /**
110  * Test.
111  */
112 @Test
113 public class TCKJapaneseChronology {
114 
115     // Year differences from Gregorian years.
116     private static final int YDIFF_REIWA = 2018;
117     private static final int YDIFF_HEISEI = 1988;
118     private static final int YDIFF_MEIJI = 1867;
119     private static final int YDIFF_SHOWA = 1925;
120     private static final int YDIFF_TAISHO = 1911;
121 
122     //-----------------------------------------------------------------------
123     // Chronology.of(String)
124     //-----------------------------------------------------------------------
125     @Test
test_chrono_byName()126     public void test_chrono_byName() {
127         Chronology c = JapaneseChronology.INSTANCE;
128         Chronology test = Chronology.of("Japanese");
129         Assert.assertNotNull(test, "The Japanese calendar could not be found byName");
130         Assert.assertEquals(test.getId(), "Japanese", "ID mismatch");
131         Assert.assertEquals(test.getCalendarType(), "japanese", "Type mismatch");
132         Assert.assertEquals(test, c);
133     }
134 
135     //-----------------------------------------------------------------------
136     // Chronology.ofLocale(Locale)
137     //-----------------------------------------------------------------------
138     @Test
test_chrono_byLocale_fullTag_japaneseCalendarFromJapan()139     public void test_chrono_byLocale_fullTag_japaneseCalendarFromJapan() {
140         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("ja-JP-u-ca-japanese"));
141         Assert.assertEquals(test.getId(), "Japanese");
142         Assert.assertEquals(test, JapaneseChronology.INSTANCE);
143     }
144 
145     @Test
test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere()146     public void test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere() {
147         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-japanese"));
148         Assert.assertEquals(test.getId(), "Japanese");
149         Assert.assertEquals(test, JapaneseChronology.INSTANCE);
150     }
151 
152     @Test
test_chrono_byLocale_oldJP_noVariant()153     public void test_chrono_byLocale_oldJP_noVariant() {
154         Chronology test = Chronology.ofLocale(new Locale("ja", "JP"));
155         Assert.assertEquals(test.getId(), "ISO");
156         Assert.assertEquals(test, IsoChronology.INSTANCE);
157     }
158 
159     @Test
test_chrono_byLocale_oldJP_variant()160     public void test_chrono_byLocale_oldJP_variant() {
161         Chronology test = Chronology.ofLocale(new Locale("ja", "JP", "JP"));
162         Assert.assertEquals(test.getId(), "Japanese");
163         Assert.assertEquals(test, JapaneseChronology.INSTANCE);
164     }
165 
166     @Test
test_chrono_byLocale_iso()167     public void test_chrono_byLocale_iso() {
168         Assert.assertEquals(Chronology.ofLocale(new Locale("ja", "JP")).getId(), "ISO");
169         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId(), "ISO");
170         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId(), "ISO");
171     }
172 
173     //-----------------------------------------------------------------------
174     // creation and cross-checks
175     //-----------------------------------------------------------------------
176     @DataProvider(name="createByEra")
data_createByEra()177     Object[][] data_createByEra() {
178         return new Object[][] {
179                 {JapaneseEra.REIWA, 2020 - YDIFF_REIWA, 2, 29, 60, LocalDate.of(2020, 2, 29)},
180                 {JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)},
181                 {JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)},
182                 {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
183                 {JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 12, 25, 360, LocalDate.of(1928, 12, 25)},
184                 {JapaneseEra.TAISHO, 1916 - YDIFF_TAISHO, 7, 30, 212, LocalDate.of(1916, 7, 30)},
185                 {JapaneseEra.MEIJI, 6, 1, 1, 1, LocalDate.of(1873, 1, 1)},
186                 {JapaneseEra.MEIJI, 45, 7, 29, 211, LocalDate.of(1912, 7, 29)},
187                 {JapaneseEra.TAISHO, 1, 7, 30, 1, LocalDate.of(1912, 7, 30)},
188                 {JapaneseEra.TAISHO, 15, 12, 24, 358, LocalDate.of(1926, 12, 24)},
189                 {JapaneseEra.SHOWA, 1, 12, 25, 1, LocalDate.of(1926, 12, 25)},
190                 {JapaneseEra.SHOWA, 64, 1, 7, 7, LocalDate.of(1989, 1, 7)},
191                 {JapaneseEra.HEISEI, 1, 1, 8, 1, LocalDate.of(1989, 1, 8)},
192         };
193     }
194 
195     @Test(dataProvider="createByEra")
test_createEymd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)196     public void test_createEymd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
197         JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(era, yoe, moy, dom);
198         JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
199         assertEquals(dateByChronoFactory, dateByDateFactory);
200         assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
201     }
202 
203     @Test(dataProvider="createByEra")
test_createEyd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)204     public void test_createEyd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
205         JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(era, yoe, doy);
206         JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
207         assertEquals(dateByChronoFactory, dateByDateFactory);
208         assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
209     }
210 
211     @Test(dataProvider="createByEra")
test_createByEra_isEqual(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)212     public void test_createByEra_isEqual(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
213         JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
214         assertEquals(test.isEqual(iso), true);
215         assertEquals(iso.isEqual(test), true);
216     }
217 
218     @Test(dataProvider="createByEra")
test_createByEra_chronologyTemporalFactory(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)219     public void test_createByEra_chronologyTemporalFactory(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
220         JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
221         assertEquals(IsoChronology.INSTANCE.date(test), iso);
222         assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
223     }
224 
225     @Test(dataProvider="createByEra")
test_createByEra_dateFrom(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)226     public void test_createByEra_dateFrom(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
227         JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
228         assertEquals(LocalDate.from(test), iso);
229         assertEquals(JapaneseDate.from(iso), test);
230     }
231 
232     @Test(dataProvider="createByEra")
test_createByEra_query(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)233     public void test_createByEra_query(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
234         JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
235         assertEquals(test.query(TemporalQueries.localDate()), iso);
236     }
237 
238     @Test(dataProvider="createByEra")
test_createByEra_epochDay(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso)239     public void test_createByEra_epochDay(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
240         JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
241         assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
242         assertEquals(test.toEpochDay(), iso.toEpochDay());
243     }
244 
245     //-----------------------------------------------------------------------
246     @DataProvider(name="createByProleptic")
data_createByProleptic()247     Object[][] data_createByProleptic() {
248         return new Object[][] {
249                 {1928, 2, 28, 59, LocalDate.of(1928, 2, 28)},
250                 {1928, 2, 29, 60, LocalDate.of(1928, 2, 29)},
251 
252                 {1873, 9, 7, 250, LocalDate.of(1873, 9, 7)},
253                 {1873, 9, 8, 251, LocalDate.of(1873, 9, 8)},
254                 {1912, 7, 29, 211, LocalDate.of(1912, 7, 29)},
255                 {1912, 7, 30, 212, LocalDate.of(1912, 7, 30)},
256                 {1926, 12, 24, 358, LocalDate.of(1926, 12, 24)},
257                 {1926, 12, 25, 359, LocalDate.of(1926, 12, 25)},
258                 {1989, 1, 7, 7, LocalDate.of(1989, 1, 7)},
259                 {1989, 1, 8, 8, LocalDate.of(1989, 1, 8)},
260         };
261     }
262 
263     @Test(dataProvider="createByProleptic")
test_createYmd(int y, int moy, int dom, int doy, LocalDate iso)264     public void test_createYmd(int y, int moy, int dom, int doy, LocalDate iso) {
265         JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(y, moy, dom);
266         JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
267         assertEquals(dateByChronoFactory, dateByDateFactory);
268         assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
269     }
270 
271     @Test(dataProvider="createByProleptic")
test_createYd(int y, int moy, int dom, int doy, LocalDate iso)272     public void test_createYd(int y, int moy, int dom, int doy, LocalDate iso) {
273         JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(y, doy);
274         JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
275         assertEquals(dateByChronoFactory, dateByDateFactory);
276         assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
277     }
278 
279     @Test(dataProvider="createByProleptic")
test_createByProleptic_isEqual(int y, int moy, int dom, int doy, LocalDate iso)280     public void test_createByProleptic_isEqual(int y, int moy, int dom, int doy, LocalDate iso) {
281         JapaneseDate test = JapaneseDate.of(y, moy, dom);
282         assertEquals(test.isEqual(iso), true);
283         assertEquals(iso.isEqual(test), true);
284     }
285 
286     @Test(dataProvider="createByProleptic")
test_createByProleptic_chronologyTemporalFactory(int y, int moy, int dom, int doy, LocalDate iso)287     public void test_createByProleptic_chronologyTemporalFactory(int y, int moy, int dom, int doy, LocalDate iso) {
288         JapaneseDate test = JapaneseDate.of(y, moy, dom);
289         assertEquals(IsoChronology.INSTANCE.date(test), iso);
290         assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
291     }
292 
293     @Test(dataProvider="createByProleptic")
test_createByProleptic_dateFrom(int y, int moy, int dom, int doy, LocalDate iso)294     public void test_createByProleptic_dateFrom(int y, int moy, int dom, int doy, LocalDate iso) {
295         JapaneseDate test = JapaneseDate.of(y, moy, dom);
296         assertEquals(LocalDate.from(test), iso);
297         assertEquals(JapaneseDate.from(iso), test);
298     }
299 
300     @Test(dataProvider="createByProleptic")
test_createByProleptic_query(int y, int moy, int dom, int doy, LocalDate iso)301     public void test_createByProleptic_query(int y, int moy, int dom, int doy, LocalDate iso) {
302         JapaneseDate test = JapaneseDate.of(y, moy, dom);
303         assertEquals(test.query(TemporalQueries.localDate()), iso);
304     }
305 
306     @Test(dataProvider="createByProleptic")
test_createByProleptic_epochDay(int y, int moy, int dom, int doy, LocalDate iso)307     public void test_createByProleptic_epochDay(int y, int moy, int dom, int doy, LocalDate iso) {
308         JapaneseDate test = JapaneseDate.of(y, moy, dom);
309         assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
310         assertEquals(test.toEpochDay(), iso.toEpochDay());
311     }
312 
313     //-----------------------------------------------------------------------
314     @Test
test_dateNow()315     public void test_dateNow(){
316         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now()) ;
317         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(ZoneId.systemDefault())) ;
318         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone())) ;
319         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone().getZone())) ;
320 
321         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
322         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
323         assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
324 
325         ZoneId zoneId = ZoneId.of("Europe/Paris");
326         assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
327         assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
328         assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId))) ;
329         assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId).getZone())) ;
330 
331         assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
332     }
333 
334     //-----------------------------------------------------------------------
335     @DataProvider(name="badDates")
data_badDates()336     Object[][] data_badDates() {
337         return new Object[][] {
338             {1928, 0, 0},
339 
340             {1928, -1, 1},
341             {1928, 0, 1},
342             {1928, 14, 1},
343             {1928, 15, 1},
344 
345             {1928, 1, -1},
346             {1928, 1, 0},
347             {1928, 1, 32},
348 
349             {1928, 12, -1},
350             {1928, 12, 0},
351             {1928, 12, 32},
352 
353             {1725, 2, 29},
354             {500, 2, 29},
355             {2100, 2, 29},
356 
357             {1872, 12, 31},     // Last day of MEIJI 5
358         };
359     }
360 
361     @Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
test_badDates(int year, int month, int dom)362     public void test_badDates(int year, int month, int dom) {
363         JapaneseChronology.INSTANCE.date(year, month, dom);
364     }
365 
366     //-----------------------------------------------------------------------
367     // prolepticYear() and is LeapYear()
368     //-----------------------------------------------------------------------
369     @DataProvider(name="prolepticYear")
data_prolepticYear()370     Object[][] data_prolepticYear() {
371         return new Object[][] {
372                 {3, JapaneseEra.REIWA, 1, 1 + YDIFF_REIWA, false},
373                 {3, JapaneseEra.REIWA, 102, 102 + YDIFF_REIWA, true},
374 
375                 {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
376                 {2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true},
377 
378                 {-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true},
379                 {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
380 
381                 {1, JapaneseEra.SHOWA, 1, 1 + YDIFF_SHOWA, false},
382                 {1, JapaneseEra.SHOWA, 7, 7 + YDIFF_SHOWA, true},
383 
384                 {0, JapaneseEra.TAISHO, 1, 1 + YDIFF_TAISHO, true},
385                 {0, JapaneseEra.TAISHO, 4, 4 + YDIFF_TAISHO, false},
386         };
387     }
388 
389     @Test(dataProvider="prolepticYear")
test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear)390     public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
391         Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
392         assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
393         assertEquals(eraObj, era);
394         assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
395     }
396 
397     @Test(dataProvider="prolepticYear")
test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear)398     public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
399         assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
400         assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());
401 
402         JapaneseDate jdate = JapaneseDate.now();
403         jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
404         if (isLeapYear) {
405             assertEquals(jdate.lengthOfMonth(), 29);
406         } else {
407             assertEquals(jdate.lengthOfMonth(), 28);
408         }
409     }
410 
411     @DataProvider(name="prolepticYearError")
data_prolepticYearError()412     Object[][] data_prolepticYearError() {
413         return new Object[][] {
414                 {JapaneseEra.MEIJI, 100},
415                 {JapaneseEra.MEIJI, 0},
416                 {JapaneseEra.MEIJI, -10},
417 
418                 {JapaneseEra.SHOWA, 100},
419                 {JapaneseEra.SHOWA, 0},
420                 {JapaneseEra.SHOWA, -10},
421 
422                 {JapaneseEra.TAISHO, 100},
423                 {JapaneseEra.TAISHO, 0},
424                 {JapaneseEra.TAISHO, -10},
425         };
426     }
427 
428     @Test(dataProvider="prolepticYearError", expectedExceptions=DateTimeException.class)
test_prolepticYearError(Era era, int yearOfEra)429     public void test_prolepticYearError(Era era, int yearOfEra) {
430         JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra);
431     }
432 
433     //-----------------------------------------------------------------------
434     // Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
435     //-----------------------------------------------------------------------
436     @Test
test_InvalidEras()437     public void test_InvalidEras() {
438         // Verify that the eras from every other Chronology are invalid
439         for (Chronology chrono : Chronology.getAvailableChronologies()) {
440             if (chrono instanceof JapaneseChronology) {
441                 continue;
442             }
443             List<Era> eras = chrono.eras();
444             for (Era era : eras) {
445                 try {
446                     ChronoLocalDate date = JapaneseChronology.INSTANCE.date(era, 1, 1, 1);
447                     fail("JapaneseChronology.date did not throw ClassCastException for Era: " + era);
448                 } catch (ClassCastException cex) {
449                     ; // ignore expected exception
450                 }
451                 try {
452                     @SuppressWarnings("unused")
453                     int year = JapaneseChronology.INSTANCE.prolepticYear(era, 1);
454                     fail("JapaneseChronology.prolepticYear did not throw ClassCastException for Era: " + era);
455                 } catch (ClassCastException cex) {
456                     ; // ignore expected exception
457                 }
458 
459             }
460         }
461     }
462 
463     //-----------------------------------------------------------------------
464     // get(TemporalField)
465     //-----------------------------------------------------------------------
466     @Test
test_getLong()467     public void test_getLong() {
468         JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
469         assertEquals(base.getLong(ERA), JapaneseEra.SHOWA.getValue());
470         assertEquals(base.getLong(YEAR), 1988L);
471         assertEquals(base.getLong(YEAR_OF_ERA), 63L);
472         assertEquals(base.getLong(MONTH_OF_YEAR), 6L);
473         assertEquals(base.getLong(DAY_OF_MONTH), 30L);
474     }
475 
476     //-----------------------------------------------------------------------
477     // with(TemporalField, long)
478     //-----------------------------------------------------------------------
479     @Test
test_with_TemporalField_long()480     public void test_with_TemporalField_long() {
481         JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
482         JapaneseDate test = base.with(YEAR, 1987);
483         assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 62, 6, 30));
484 
485         test = test.with(YEAR_OF_ERA, 2);
486         assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 2, 6, 30));
487 
488         test = test.with(ERA, JapaneseEra.HEISEI.getValue());
489         assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 6, 30));
490 
491         test = test.with(MONTH_OF_YEAR, 3);
492         assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 30));
493 
494         test = test.with(DAY_OF_MONTH, 4);
495         assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 4));
496     }
497 
498     //-----------------------------------------------------------------------
499     // with(WithAdjuster)
500     //-----------------------------------------------------------------------
501     @Test
test_adjust1()502     public void test_adjust1() {
503         JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 10, 29);
504         JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
505         assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 10, 31));
506     }
507 
508     @Test
test_adjust2()509     public void test_adjust2() {
510         JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 12, 2);
511         JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
512         assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 12, 31));
513     }
514 
515     //-----------------------------------------------------------------------
516     // JapaneseDate.with(Local*)
517     //-----------------------------------------------------------------------
518     @Test
test_adjust_toLocalDate()519     public void test_adjust_toLocalDate() {
520         JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
521         JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6));
522         assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6));
523     }
524 
525     @Test(expectedExceptions=DateTimeException.class)
test_adjust_toMonth()526     public void test_adjust_toMonth() {
527         JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
528         jdate.with(Month.APRIL);
529     }
530 
531     //-----------------------------------------------------------------------
532     // LocalDate.with(JapaneseDate)
533     //-----------------------------------------------------------------------
534     @Test
test_LocalDate_adjustToJapaneseDate()535     public void test_LocalDate_adjustToJapaneseDate() {
536         JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
537         LocalDate test = LocalDate.MIN.with(jdate);
538         assertEquals(test, LocalDate.of(1928, 10, 29));
539     }
540 
541     @Test
test_LocalDateTime_adjustToJapaneseDate()542     public void test_LocalDateTime_adjustToJapaneseDate() {
543         JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
544         LocalDateTime test = LocalDateTime.MIN.with(jdate);
545         assertEquals(test, LocalDateTime.of(1928, 10, 29, 0, 0));
546     }
547 
548     //-----------------------------------------------------------------------
549     // Check Japanese Eras
550     //-----------------------------------------------------------------------
551     @DataProvider(name="japaneseEras")
data_japanseseEras()552     Object[][] data_japanseseEras() {
553         return new Object[][] {
554             { JapaneseEra.MEIJI, -1, "Meiji"},
555             { JapaneseEra.TAISHO, 0, "Taisho"},
556             { JapaneseEra.SHOWA, 1, "Showa"},
557             { JapaneseEra.HEISEI, 2, "Heisei"},
558             { JapaneseEra.REIWA, 3, "Reiwa"},
559         };
560     }
561 
562     @Test(dataProvider="japaneseEras")
test_Japanese_Eras(Era era, int eraValue, String name)563     public void test_Japanese_Eras(Era era, int eraValue, String name) {
564         assertEquals(era.getValue(), eraValue, "EraValue");
565         assertEquals(era.toString(), name, "Era Name");
566         assertEquals(era, JapaneseChronology.INSTANCE.eraOf(eraValue), "JapaneseChronology.eraOf()");
567         List<Era> eras = JapaneseChronology.INSTANCE.eras();
568         assertTrue(eras.contains(era), "Era is not present in JapaneseChronology.INSTANCE.eras()");
569     }
570 
571     @Test
test_Japanese_badEras()572     public void test_Japanese_badEras() {
573         int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000};
574         for (int badEra : badEras) {
575             try {
576                 Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
577                 fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
578             } catch (DateTimeException ex) {
579                 // ignore expected exception
580             }
581         }
582     }
583 
584     @Test(dataProvider="japaneseEras")
test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name)585     public void test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name) {
586         JapaneseEra actualEra = JapaneseEra.valueOf(name);
587         assertEquals(actualEra, expectedEra, "JapaneseEra.valueOf(name)");
588 
589         actualEra = JapaneseEra.of(eraValue);
590         assertEquals(actualEra, expectedEra, "JapaneseEra.of(value)");
591 
592         String string = actualEra.toString();
593         assertEquals(string, name, "JapaneseEra.toString()");
594     }
595 
596     @Test
test_JapaneseEra_values()597     public void test_JapaneseEra_values() {
598         JapaneseEra[] actualEras = JapaneseEra.values();
599         Object[][] erasInfo = data_japanseseEras();
600         assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");
601 
602         for (int i = 0; i < erasInfo.length; i++) {
603             Object[] eraInfo = erasInfo[i];
604             assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
605         }
606     }
607 
608     @Test
test_JapaneseChronology_eras()609     public void test_JapaneseChronology_eras() {
610         List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
611         Object[][] erasInfo = data_japanseseEras();
612         assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");
613 
614         for (int i = 0; i < erasInfo.length; i++) {
615             Object[] eraInfo = erasInfo[i];
616             assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
617         }
618     }
619 
620     //-----------------------------------------------------------------------
621     // PeriodUntil()
622     //-----------------------------------------------------------------------
623     @Test
test_periodUntilDate()624     public void test_periodUntilDate() {
625         JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
626         JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
627         ChronoPeriod period = mdate1.until(mdate2);
628         assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
629     }
630 
631     @Test
test_periodUntilUnit()632     public void test_periodUntilUnit() {
633         JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
634         JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
635         long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
636         assertEquals(months, 13);
637     }
638 
639     @Test
test_periodUntilDiffChrono()640     public void test_periodUntilDiffChrono() {
641         JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
642         JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
643         MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
644         ChronoPeriod period = mdate1.until(ldate2);
645         assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
646     }
647 
648     //-----------------------------------------------------------------------
649     // JapaneseChronology.dateYearDay, getDayOfYear
650     //-----------------------------------------------------------------------
651     @Test
test_getDayOfYear()652     public void test_getDayOfYear() {
653         // Test all the Eras
654         for (JapaneseEra era : JapaneseEra.values()) {
655             int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1;  // Until Era supports range(YEAR_OF_ERA)
656             JapaneseDate hd1 = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, 1);
657             ValueRange range = hd1.range(DAY_OF_YEAR);
658             assertEquals(range.getMaximum(), hd1.lengthOfYear(), "lengthOfYear should match range.getMaximum()");
659 
660             for (int i = 1; i <= hd1.lengthOfYear(); i++) {
661                 JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, i);
662                 int doy = hd.get(DAY_OF_YEAR);
663                 assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
664             }
665         }
666     }
667 
668     // TODO(http://b/118623814): Re-enable this test.
669     @Test(enabled = false)
test_withDayOfYear()670     public void test_withDayOfYear() {
671         JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(1990, 1);
672         for (int i = 1; i <= hd.lengthOfYear(); i++) {
673             JapaneseDate hd2 = hd.with(DAY_OF_YEAR, i);
674             int doy = hd2.get(DAY_OF_YEAR);
675             assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
676         }
677     }
678 
679     //-----------------------------------------------------------------------
680     // toString()
681     //-----------------------------------------------------------------------
682     @DataProvider(name="toString")
data_toString()683     Object[][] data_toString() {
684         return new Object[][] {
685             {JapaneseChronology.INSTANCE.date(1873, 12,  5), "Japanese Meiji 6-12-05"},
686             {JapaneseChronology.INSTANCE.date(1873, 12,  6), "Japanese Meiji 6-12-06"},
687             {JapaneseChronology.INSTANCE.date(1873,  9,  8), "Japanese Meiji 6-09-08"},
688             {JapaneseChronology.INSTANCE.date(1912,  7, 29), "Japanese Meiji 45-07-29"},
689             {JapaneseChronology.INSTANCE.date(1912,  7, 30), "Japanese Taisho 1-07-30"},
690             {JapaneseChronology.INSTANCE.date(1926, 12, 24), "Japanese Taisho 15-12-24"},
691             {JapaneseChronology.INSTANCE.date(1926, 12, 25), "Japanese Showa 1-12-25"},
692             {JapaneseChronology.INSTANCE.date(1989,  1,  7), "Japanese Showa 64-01-07"},
693             {JapaneseChronology.INSTANCE.date(1989,  1,  8), "Japanese Heisei 1-01-08"},
694             {JapaneseChronology.INSTANCE.date(2012, 12,  6), "Japanese Heisei 24-12-06"},
695             {JapaneseChronology.INSTANCE.date(2020,  1,  6), "Japanese Reiwa 2-01-06"},
696         };
697     }
698 
699     @Test(dataProvider="toString")
test_toString(JapaneseDate jdate, String expected)700     public void test_toString(JapaneseDate jdate, String expected) {
701         assertEquals(jdate.toString(), expected);
702     }
703 
704     //-----------------------------------------------------------------------
705     // equals()
706     //-----------------------------------------------------------------------
707     @Test
test_equals_true()708     public void test_equals_true() {
709         assertTrue(JapaneseChronology.INSTANCE.equals(JapaneseChronology.INSTANCE));
710     }
711 
712     @Test
test_equals_false()713     public void test_equals_false() {
714         assertFalse(JapaneseChronology.INSTANCE.equals(IsoChronology.INSTANCE));
715     }
716 
717     //-----------------------------------------------------------------------
718     //-----------------------------------------------------------------------
719     @DataProvider(name = "resolve_styleByEra")
data_resolve_styleByEra()720     Object[][] data_resolve_styleByEra() {
721         Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
722         int i = 0;
723         for (ResolverStyle style : ResolverStyle.values()) {
724             for (JapaneseEra era : JapaneseEra.values()) {
725                 result[i++] = new Object[] {style, era};
726             }
727         }
728         return result;
729     }
730 
731     @Test(dataProvider = "resolve_styleByEra")
test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, JapaneseEra era)732     public void test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, JapaneseEra era) {
733         Map<TemporalField, Long> fieldValues = new HashMap<>();
734         fieldValues.put(ChronoField.ERA, (long) era.getValue());
735         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
736         assertEquals(date, null);
737         assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
738         assertEquals(fieldValues.size(), 1);
739     }
740 
741     @Test(dataProvider = "resolve_styleByEra")
test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, JapaneseEra era)742     public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, JapaneseEra era) {
743         Map<TemporalField, Long> fieldValues = new HashMap<>();
744         fieldValues.put(ChronoField.ERA, (long) era.getValue());
745         fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
746         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
747         assertEquals(date, null);
748         assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
749         assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
750         assertEquals(fieldValues.size(), 2);
751     }
752 
753     @Test(dataProvider = "resolve_styleByEra")
test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, JapaneseEra era)754     public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, JapaneseEra era) {
755         Map<TemporalField, Long> fieldValues = new HashMap<>();
756         fieldValues.put(ChronoField.ERA, (long) era.getValue());
757         fieldValues.put(ChronoField.YEAR, 1L);
758         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
759         assertEquals(date, null);
760         assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
761         assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1L);
762         assertEquals(fieldValues.size(), 2);
763     }
764 
765     @DataProvider(name = "resolve_styles")
data_resolve_styles()766     Object[][] data_resolve_styles() {
767         Object[][] result = new Object[ResolverStyle.values().length][];
768         int i = 0;
769         for (ResolverStyle style : ResolverStyle.values()) {
770             result[i++] = new Object[] {style};
771         }
772         return result;
773     }
774 
775     @Test(dataProvider = "resolve_styles")
test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style)776     public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
777         Map<TemporalField, Long> fieldValues = new HashMap<>();
778         fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
779         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
780         assertEquals(date, null);
781         assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
782         assertEquals(fieldValues.size(), 1);
783     }
784 
785     @Test(dataProvider = "resolve_styles")
test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style)786     public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
787         Map<TemporalField, Long> fieldValues = new HashMap<>();
788         fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
789         fieldValues.put(ChronoField.YEAR, 2012L);
790         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
791         assertEquals(date, null);
792         assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
793         assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 2012L);
794         assertEquals(fieldValues.size(), 2);
795     }
796 
test_resolve_yearOfEra_eraOnly_invalidTooSmall()797     public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
798         for (ResolverStyle style : ResolverStyle.values()) {
799             Map<TemporalField, Long> fieldValues = new HashMap<>();
800             fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
801             try {
802                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
803                 fail("Should have failed: " + style);
804             } catch (DateTimeException ex) {
805                 // expected
806             }
807         }
808     }
809 
test_resolve_yearOfEra_eraOnly_invalidTooLarge()810     public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
811         for (ResolverStyle style : ResolverStyle.values()) {
812             Map<TemporalField, Long> fieldValues = new HashMap<>();
813             fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L);
814             try {
815                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
816                 fail("Should have failed: " + style);
817             } catch (DateTimeException ex) {
818                 // expected
819             }
820         }
821     }
822 
823     //-----------------------------------------------------------------------
824     //-----------------------------------------------------------------------
825     @DataProvider(name = "resolve_ymd")
data_resolve_ymd()826     Object[][] data_resolve_ymd() {
827         return new Object[][] {
828                 {2012, 1, -365, date(2010, 12, 31), false, false},
829                 {2012, 1, -364, date(2011, 1, 1), false, false},
830                 {2012, 1, -31, date(2011, 11, 30), false, false},
831                 {2012, 1, -30, date(2011, 12, 1), false, false},
832                 {2012, 1, -12, date(2011, 12, 19), false, false},
833                 {2012, 1, 1, date(2012, 1, 1), true, true},
834                 {2012, 1, 59, date(2012, 2, 28), false, false},
835                 {2012, 1, 60, date(2012, 2, 29), false, false},
836                 {2012, 1, 61, date(2012, 3, 1), false, false},
837                 {2012, 1, 365, date(2012, 12, 30), false, false},
838                 {2012, 1, 366, date(2012, 12, 31), false, false},
839                 {2012, 1, 367, date(2013, 1, 1), false, false},
840                 {2012, 1, 367 + 364, date(2013, 12, 31), false, false},
841                 {2012, 1, 367 + 365, date(2014, 1, 1), false, false},
842 
843                 {2012, 2, 1, date(2012, 2, 1), true, true},
844                 {2012, 2, 28, date(2012, 2, 28), true, true},
845                 {2012, 2, 29, date(2012, 2, 29), true, true},
846                 {2012, 2, 30, date(2012, 3, 1), date(2012, 2, 29), false},
847                 {2012, 2, 31, date(2012, 3, 2), date(2012, 2, 29), false},
848                 {2012, 2, 32, date(2012, 3, 3), false, false},
849 
850                 {2012, -12, 1, date(2010, 12, 1), false, false},
851                 {2012, -11, 1, date(2011, 1, 1), false, false},
852                 {2012, -1, 1, date(2011, 11, 1), false, false},
853                 {2012, 0, 1, date(2011, 12, 1), false, false},
854                 {2012, 1, 1, date(2012, 1, 1), true, true},
855                 {2012, 12, 1, date(2012, 12, 1), true, true},
856                 {2012, 13, 1, date(2013, 1, 1), false, false},
857                 {2012, 24, 1, date(2013, 12, 1), false, false},
858                 {2012, 25, 1, date(2014, 1, 1), false, false},
859 
860                 {2012, 6, -31, date(2012, 4, 30), false, false},
861                 {2012, 6, -30, date(2012, 5, 1), false, false},
862                 {2012, 6, -1, date(2012, 5, 30), false, false},
863                 {2012, 6, 0, date(2012, 5, 31), false, false},
864                 {2012, 6, 1, date(2012, 6, 1), true, true},
865                 {2012, 6, 30, date(2012, 6, 30), true, true},
866                 {2012, 6, 31, date(2012, 7, 1), date(2012, 6, 30), false},
867                 {2012, 6, 61, date(2012, 7, 31), false, false},
868                 {2012, 6, 62, date(2012, 8, 1), false, false},
869 
870                 {2011, 2, 1, date(2011, 2, 1), true, true},
871                 {2011, 2, 28, date(2011, 2, 28), true, true},
872                 {2011, 2, 29, date(2011, 3, 1), date(2011, 2, 28), false},
873                 {2011, 2, 30, date(2011, 3, 2), date(2011, 2, 28), false},
874                 {2011, 2, 31, date(2011, 3, 3), date(2011, 2, 28), false},
875                 {2011, 2, 32, date(2011, 3, 4), false, false},
876         };
877     }
878 
879     @Test(dataProvider = "resolve_ymd")
test_resolve_ymd_lenient(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict)880     public void test_resolve_ymd_lenient(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
881         Map<TemporalField, Long> fieldValues = new HashMap<>();
882         fieldValues.put(ChronoField.YEAR, (long) y);
883         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
884         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
885         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
886         assertEquals(date, expected);
887         assertEquals(fieldValues.size(), 0);
888     }
889 
890     @Test(dataProvider = "resolve_ymd")
test_resolve_ymd_smart(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict)891     public void test_resolve_ymd_smart(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
892         Map<TemporalField, Long> fieldValues = new HashMap<>();
893         fieldValues.put(ChronoField.YEAR, (long) y);
894         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
895         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
896         if (Boolean.TRUE.equals(smart)) {
897             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
898             assertEquals(date, expected);
899             assertEquals(fieldValues.size(), 0);
900         } else if (smart instanceof JapaneseDate) {
901             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
902             assertEquals(date, smart);
903         } else {
904             try {
905                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
906                 fail("Should have failed");
907             } catch (DateTimeException ex) {
908                 // expected
909             }
910         }
911     }
912 
913     @Test(dataProvider = "resolve_ymd")
test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict)914     public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
915         Map<TemporalField, Long> fieldValues = new HashMap<>();
916         fieldValues.put(ChronoField.YEAR, (long) y);
917         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
918         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
919         if (strict) {
920             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
921             assertEquals(date, expected);
922             assertEquals(fieldValues.size(), 0);
923         } else {
924             try {
925                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
926                 fail("Should have failed");
927             } catch (DateTimeException ex) {
928                 // expected
929             }
930         }
931     }
932 
933     //-----------------------------------------------------------------------
934     //-----------------------------------------------------------------------
935     @DataProvider(name = "resolve_yd")
data_resolve_yd()936     Object[][] data_resolve_yd() {
937         return new Object[][] {
938                 {2012, -365, date(2010, 12, 31), false, false},
939                 {2012, -364, date(2011, 1, 1), false, false},
940                 {2012, -31, date(2011, 11, 30), false, false},
941                 {2012, -30, date(2011, 12, 1), false, false},
942                 {2012, -12, date(2011, 12, 19), false, false},
943                 {2012, -1, date(2011, 12, 30), false, false},
944                 {2012, 0, date(2011, 12, 31), false, false},
945                 {2012, 1, date(2012, 1, 1), true, true},
946                 {2012, 2, date(2012, 1, 2), true, true},
947                 {2012, 31, date(2012, 1, 31), true, true},
948                 {2012, 32, date(2012, 2, 1), true, true},
949                 {2012, 59, date(2012, 2, 28), true, true},
950                 {2012, 60, date(2012, 2, 29), true, true},
951                 {2012, 61, date(2012, 3, 1), true, true},
952                 {2012, 365, date(2012, 12, 30), true, true},
953                 {2012, 366, date(2012, 12, 31), true, true},
954                 {2012, 367, date(2013, 1, 1), false, false},
955                 {2012, 367 + 364, date(2013, 12, 31), false, false},
956                 {2012, 367 + 365, date(2014, 1, 1), false, false},
957 
958                 {2011, 59, date(2011, 2, 28), true, true},
959                 {2011, 60, date(2011, 3, 1), true, true},
960         };
961     }
962 
963     @Test(dataProvider = "resolve_yd")
test_resolve_yd_lenient(int y, int d, JapaneseDate expected, boolean smart, boolean strict)964     public void test_resolve_yd_lenient(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
965         Map<TemporalField, Long> fieldValues = new HashMap<>();
966         fieldValues.put(ChronoField.YEAR, (long) y);
967         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
968         JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
969         assertEquals(date, expected);
970         assertEquals(fieldValues.size(), 0);
971     }
972 
973     @Test(dataProvider = "resolve_yd")
test_resolve_yd_smart(int y, int d, JapaneseDate expected, boolean smart, boolean strict)974     public void test_resolve_yd_smart(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
975         Map<TemporalField, Long> fieldValues = new HashMap<>();
976         fieldValues.put(ChronoField.YEAR, (long) y);
977         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
978         if (smart) {
979             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
980             assertEquals(date, expected);
981             assertEquals(fieldValues.size(), 0);
982         } else {
983             try {
984                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
985                 fail("Should have failed");
986             } catch (DateTimeException ex) {
987                 // expected
988             }
989         }
990     }
991 
992     @Test(dataProvider = "resolve_yd")
test_resolve_yd_strict(int y, int d, JapaneseDate expected, boolean smart, boolean strict)993     public void test_resolve_yd_strict(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
994         Map<TemporalField, Long> fieldValues = new HashMap<>();
995         fieldValues.put(ChronoField.YEAR, (long) y);
996         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
997         if (strict) {
998             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
999             assertEquals(date, expected);
1000             assertEquals(fieldValues.size(), 0);
1001         } else {
1002             try {
1003                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
1004                 fail("Should have failed");
1005             } catch (DateTimeException ex) {
1006                 // expected
1007             }
1008         }
1009     }
1010 
1011     //-----------------------------------------------------------------------
1012     //-----------------------------------------------------------------------
1013     @DataProvider(name = "resolve_eymd")
data_resolve_eymd()1014     Object[][] data_resolve_eymd() {
1015         return new Object[][] {
1016                 // lenient
1017                 {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 1, date(1989, 1, 1)},  // SHOWA, not HEISEI
1018                 {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 7, date(1989, 1, 7)},  // SHOWA, not HEISEI
1019                 {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
1020                 {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
1021                 {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
1022 
1023                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
1024                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
1025                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 8, date(1989, 1, 8)},  // HEISEI, not SHOWA
1026                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 12, 31, date(1989, 12, 31)},  // HEISEI, not SHOWA
1027                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 65, 1, 1, date(1990, 1, 1)},  // HEISEI, not SHOWA
1028 
1029                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -366, date(1987, 12, 31)},
1030                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -365, date(1988, 1, 1)},
1031                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -31, date(1988, 11, 30)},
1032                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -30, date(1988, 12, 1)},
1033                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 0, date(1988, 12, 31)},
1034                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
1035                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 27, date(1989, 1, 27)},
1036                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 28, date(1989, 1, 28)},
1037                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 29, date(1989, 1, 29)},
1038                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 30, date(1989, 1, 30)},
1039                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 31, date(1989, 1, 31)},
1040                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 32, date(1989, 2, 1)},
1041                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 58, date(1989, 2, 27)},
1042                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 59, date(1989, 2, 28)},
1043                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 60, date(1989, 3, 1)},
1044                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 365, date(1989, 12, 31)},
1045                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 366, date(1990, 1, 1)},
1046 
1047                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 1, date(1988, 1, 1)},
1048                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 31, date(1988, 1, 31)},
1049                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 32, date(1988, 2, 1)},
1050                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 58, date(1988, 2, 27)},
1051                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 59, date(1988, 2, 28)},
1052                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 60, date(1988, 2, 29)},
1053                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 61, date(1988, 3, 1)},
1054 
1055                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 1, date(1989, 2, 1)},
1056                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 28, date(1989, 2, 28)},
1057                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 29, date(1989, 3, 1)},
1058 
1059                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
1060                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
1061                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
1062                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 30, date(1988, 3, 1)},
1063 
1064                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, -11, 1, date(1986, 1, 1)},
1065                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, -1, 1, date(1986, 11, 1)},
1066                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, 0, 1, date(1986, 12, 1)},
1067                 {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, 13, 1, date(1988, 1, 1)},
1068 
1069                 // smart
1070                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 0, 1, 1, null},
1071                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 1, date(1989, 1, 1)},  // SHOWA, not HEISEI
1072                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 7, date(1989, 1, 7)},  // SHOWA, not HEISEI
1073                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
1074                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
1075                 {ResolverStyle.SMART, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
1076 
1077                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
1078                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
1079                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 8, date(1989, 1, 8)},  // HEISEI, not SHOWA
1080                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 12, 31, date(1989, 12, 31)},  // HEISEI, not SHOWA
1081                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 65, 1, 1, null},  // HEISEI, not SHOWA
1082 
1083                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 0, null},
1084                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 1, date(1987, 1, 1)},
1085                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 27, date(1987, 1, 27)},
1086                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 28, date(1987, 1, 28)},
1087                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 29, date(1987, 1, 29)},
1088                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 30, date(1987, 1, 30)},
1089                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 31, date(1987, 1, 31)},
1090                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 32, null},
1091 
1092                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 0, null},
1093                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 1, date(1987, 2, 1)},
1094                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 27, date(1987, 2, 27)},
1095                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 28, date(1987, 2, 28)},
1096                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 29, date(1987, 2, 28)},
1097                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 30, date(1987, 2, 28)},
1098                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 31, date(1987, 2, 28)},
1099                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 32, null},
1100 
1101                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 0, null},
1102                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
1103                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 27, date(1988, 2, 27)},
1104                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
1105                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
1106                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 30, date(1988, 2, 29)},
1107                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 31, date(1988, 2, 29)},
1108                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 32, null},
1109 
1110                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, -12, 1, null},
1111                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, -1, 1, null},
1112                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 0, 1, null},
1113                 {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 13, 1, null},
1114 
1115                 // strict
1116                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 0, 1, 1, null},
1117                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 1, null},  // SHOWA, not HEISEI
1118                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 7, null},  // SHOWA, not HEISEI
1119                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
1120                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
1121                 {ResolverStyle.STRICT, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
1122 
1123                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
1124                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
1125                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 8, null},  // HEISEI, not SHOWA
1126                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 12, 31, null},  // HEISEI, not SHOWA
1127                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 65, 1, 1, null},  // HEISEI, not SHOWA
1128 
1129                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 0, null},
1130                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 1, date(1987, 1, 1)},
1131                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 27, date(1987, 1, 27)},
1132                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 28, date(1987, 1, 28)},
1133                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 29, date(1987, 1, 29)},
1134                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 30, date(1987, 1, 30)},
1135                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 31, date(1987, 1, 31)},
1136                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 32, null},
1137 
1138                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 0, null},
1139                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 1, date(1987, 2, 1)},
1140                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 27, date(1987, 2, 27)},
1141                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 28, date(1987, 2, 28)},
1142                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 29, null},
1143                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 30, null},
1144                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 31, null},
1145                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 32, null},
1146 
1147                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 0, null},
1148                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
1149                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 27, date(1988, 2, 27)},
1150                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
1151                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
1152                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 30, null},
1153                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 31, null},
1154                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 32, null},
1155 
1156                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, -12, 1, null},
1157                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, -1, 1, null},
1158                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 0, 1, null},
1159                 {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 13, 1, null},
1160         };
1161     }
1162 
1163     @Test(dataProvider = "resolve_eymd")
test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected)1164     public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
1165         Map<TemporalField, Long> fieldValues = new HashMap<>();
1166         fieldValues.put(ChronoField.ERA, (long) era.getValue());
1167         fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
1168         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
1169         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
1170         if (expected != null) {
1171             JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
1172             assertEquals(date, expected);
1173             assertEquals(fieldValues.size(), 0);
1174         } else {
1175             try {
1176                 JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
1177                 fail("Should have failed");
1178             } catch (DateTimeException ex) {
1179                 // expected
1180             }
1181         }
1182     }
1183 
1184     //-----------------------------------------------------------------------
date(int y, int m, int d)1185     private static JapaneseDate date(int y, int m, int d) {
1186         return JapaneseDate.of(y, m, d);
1187     }
1188 
1189 }
1190