Home | History | Annotate | Download | only in chrono
      1 /*
      2  * Copyright (c) 2012, 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
     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.MONTH_OF_YEAR;
     62 import static java.time.temporal.ChronoField.YEAR;
     63 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
     64 import static org.testng.Assert.assertEquals;
     65 import static org.testng.Assert.assertFalse;
     66 import static org.testng.Assert.assertNotEquals;
     67 import static org.testng.Assert.assertTrue;
     68 import static org.testng.Assert.fail;
     69 
     70 import java.time.Clock;
     71 import java.time.DateTimeException;
     72 import java.time.LocalDate;
     73 import java.time.LocalDateTime;
     74 import java.time.Month;
     75 import java.time.Year;
     76 import java.time.ZoneId;
     77 import java.time.ZoneOffset;
     78 import java.time.chrono.ChronoLocalDate;
     79 import java.time.chrono.ChronoPeriod;
     80 import java.time.chrono.Chronology;
     81 import java.time.chrono.Era;
     82 import java.time.chrono.IsoChronology;
     83 import java.time.chrono.MinguoChronology;
     84 import java.time.chrono.MinguoDate;
     85 import java.time.chrono.ThaiBuddhistChronology;
     86 import java.time.chrono.ThaiBuddhistDate;
     87 import java.time.chrono.ThaiBuddhistEra;
     88 import java.time.format.ResolverStyle;
     89 import java.time.temporal.ChronoField;
     90 import java.time.temporal.ChronoUnit;
     91 import java.time.temporal.TemporalAdjusters;
     92 import java.time.temporal.TemporalField;
     93 import java.time.temporal.ValueRange;
     94 import java.util.HashMap;
     95 import java.util.List;
     96 import java.util.Locale;
     97 import java.util.Map;
     98 
     99 import org.testng.Assert;
    100 import org.testng.annotations.DataProvider;
    101 import org.testng.annotations.Test;
    102 
    103 /**
    104  * Test.
    105  */
    106 @Test
    107 public class TCKThaiBuddhistChronology {
    108 
    109     private static final int YDIFF = 543;
    110 
    111     //-----------------------------------------------------------------------
    112     // Chronology.of(String)
    113     //-----------------------------------------------------------------------
    114     @Test
    115     public void test_chrono_byName() {
    116         Chronology c = ThaiBuddhistChronology.INSTANCE;
    117         Chronology test = Chronology.of("ThaiBuddhist");
    118         Assert.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName");
    119         Assert.assertEquals(test.getId(), "ThaiBuddhist", "ID mismatch");
    120         Assert.assertEquals(test.getCalendarType(), "buddhist", "Type mismatch");
    121         Assert.assertEquals(test, c);
    122     }
    123 
    124     //-----------------------------------------------------------------------
    125     // Chronology.ofLocale(Locale)
    126     //-----------------------------------------------------------------------
    127     @Test
    128     public void test_chrono_byLocale_fullTag_thaiCalendarFromThai() {
    129         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("th-TH-u-ca-buddhist"));
    130         Assert.assertEquals(test.getId(), "ThaiBuddhist");
    131         Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
    132     }
    133 
    134     @Test
    135     public void test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere() {
    136         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-buddhist"));
    137         Assert.assertEquals(test.getId(), "ThaiBuddhist");
    138         Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
    139     }
    140 
    141     @Test
    142     public void test_chrono_byLocale_oldTH_noVariant() {  // deliberately different to Calendar
    143         Chronology test = Chronology.ofLocale(new Locale("th", "TH"));
    144         Assert.assertEquals(test.getId(), "ISO");
    145         Assert.assertEquals(test, IsoChronology.INSTANCE);
    146     }
    147 
    148     @Test
    149     public void test_chrono_byLocale_oldTH_variant() {
    150         Chronology test = Chronology.ofLocale(new Locale("th", "TH", "TH"));
    151         Assert.assertEquals(test.getId(), "ISO");
    152         Assert.assertEquals(test, IsoChronology.INSTANCE);
    153     }
    154 
    155     @Test
    156     public void test_chrono_byLocale_iso() {
    157         Assert.assertEquals(Chronology.ofLocale(new Locale("th", "TH")).getId(), "ISO");
    158         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH")).getId(), "ISO");
    159         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH-TH")).getId(), "ISO");
    160     }
    161 
    162     //-----------------------------------------------------------------------
    163     // creation, toLocalDate()
    164     //-----------------------------------------------------------------------
    165     @DataProvider(name="samples")
    166     Object[][] data_samples() {
    167         return new Object[][] {
    168             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)},
    169             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 2), LocalDate.of(1, 1, 2)},
    170             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 3), LocalDate.of(1, 1, 3)},
    171 
    172             {ThaiBuddhistChronology.INSTANCE.date(2 + YDIFF, 1, 1), LocalDate.of(2, 1, 1)},
    173             {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 1, 1), LocalDate.of(3, 1, 1)},
    174             {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 12, 6), LocalDate.of(3, 12, 6)},
    175             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 1, 1), LocalDate.of(4, 1, 1)},
    176             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 3), LocalDate.of(4, 7, 3)},
    177             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 4), LocalDate.of(4, 7, 4)},
    178             {ThaiBuddhistChronology.INSTANCE.date(5 + YDIFF, 1, 1), LocalDate.of(5, 1, 1)},
    179             {ThaiBuddhistChronology.INSTANCE.date(1662 + YDIFF, 3, 3), LocalDate.of(1662, 3, 3)},
    180             {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 28), LocalDate.of(1728, 10, 28)},
    181             {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 29), LocalDate.of(1728, 10, 29)},
    182             {ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), LocalDate.of(2012, 8, 29)},
    183 
    184             {ThaiBuddhistChronology.INSTANCE.dateYearDay(4 + YDIFF, 60), LocalDate.of(4, 2, 29)},
    185             {ThaiBuddhistChronology.INSTANCE.dateYearDay(400 + YDIFF, 60), LocalDate.of(400, 2, 29)},
    186             {ThaiBuddhistChronology.INSTANCE.dateYearDay(2000 + YDIFF, 60), LocalDate.of(2000, 2, 29)},
    187 
    188             {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 1916 + YDIFF, 60), LocalDate.of(1916, 2, 29)},
    189             {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BEFORE_BE, -1907 - YDIFF, 60), LocalDate.of(1908, 2, 29)},
    190             {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2000 + YDIFF, 60), LocalDate.of(2000, 2, 29)},
    191             {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2400 + YDIFF, 60), LocalDate.of(2400, 2, 29)},
    192 
    193             {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 1916 + YDIFF, 2, 29 ), LocalDate.of(1916, 2, 29)},
    194             {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BEFORE_BE, -1907 - YDIFF, 2, 29), LocalDate.of(1908, 2, 29)},
    195             {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2000 + YDIFF, 2, 29), LocalDate.of(2000, 2, 29)},
    196             {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2400 + YDIFF, 2, 29), LocalDate.of(2400, 2, 29)},
    197         };
    198     }
    199 
    200     @Test(dataProvider="samples")
    201     public void test_toLocalDate(ThaiBuddhistDate jdate, LocalDate iso) {
    202         assertEquals(LocalDate.from(jdate), iso);
    203     }
    204 
    205     @Test(dataProvider="samples")
    206     public void test_fromCalendrical(ThaiBuddhistDate jdate, LocalDate iso) {
    207         assertEquals(ThaiBuddhistChronology.INSTANCE.date(iso), jdate);
    208         assertEquals(ThaiBuddhistDate.from(iso), jdate);
    209     }
    210 
    211     @Test(dataProvider="samples")
    212     public void test_isEqual(ThaiBuddhistDate jdate, LocalDate iso) {
    213         assertTrue(jdate.isEqual(iso));
    214     }
    215 
    216     @Test(dataProvider="samples")
    217     public void test_date_equals(ThaiBuddhistDate jdate, LocalDate iso) {
    218         assertFalse(jdate.equals(iso));
    219         assertNotEquals(jdate.hashCode(), iso.hashCode());
    220     }
    221 
    222     @Test
    223     public void test_dateNow(){
    224         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now()) ;
    225         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(ZoneId.systemDefault())) ;
    226         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone())) ;
    227         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone().getZone())) ;
    228 
    229         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
    230         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
    231         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
    232 
    233         ZoneId zoneId = ZoneId.of("Europe/Paris");
    234         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
    235         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
    236         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId))) ;
    237         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId).getZone())) ;
    238 
    239         assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
    240     }
    241 
    242     @DataProvider(name="badDates")
    243     Object[][] data_badDates() {
    244         return new Object[][] {
    245             {1728, 0, 0},
    246 
    247             {1728, -1, 1},
    248             {1728, 0, 1},
    249             {1728, 14, 1},
    250             {1728, 15, 1},
    251 
    252             {1728, 1, -1},
    253             {1728, 1, 0},
    254             {1728, 1, 32},
    255 
    256             {1728, 12, -1},
    257             {1728, 12, 0},
    258             {1728, 12, 32},
    259 
    260             {3 + YDIFF, 2, 29},
    261             {600 + YDIFF, 2, 29},
    262             {1501 + YDIFF, 2, 29},
    263         };
    264     }
    265 
    266     @Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
    267     public void test_badDates(int year, int month, int dom) {
    268         ThaiBuddhistChronology.INSTANCE.date(year, month, dom);
    269     }
    270 
    271     //-----------------------------------------------------------------------
    272     // prolepticYear() and is LeapYear()
    273     //-----------------------------------------------------------------------
    274     @DataProvider(name="prolepticYear")
    275     Object[][] data_prolepticYear() {
    276         return new Object[][] {
    277             {1, ThaiBuddhistEra.BE, 4 + YDIFF, 4 + YDIFF, true},
    278             {1, ThaiBuddhistEra.BE, 7 + YDIFF, 7 + YDIFF, false},
    279             {1, ThaiBuddhistEra.BE, 8 + YDIFF, 8 + YDIFF, true},
    280             {1, ThaiBuddhistEra.BE, 1000 + YDIFF, 1000 + YDIFF, false},
    281             {1, ThaiBuddhistEra.BE, 2000 + YDIFF, 2000 + YDIFF, true},
    282             {1, ThaiBuddhistEra.BE, 0, 0, false},
    283             {1, ThaiBuddhistEra.BE, -4 + YDIFF, -4 + YDIFF, true},
    284             {1, ThaiBuddhistEra.BE, -7 + YDIFF, -7 + YDIFF, false},
    285             {1, ThaiBuddhistEra.BE, -100 + YDIFF, -100 + YDIFF, false},
    286             {1, ThaiBuddhistEra.BE, -800 + YDIFF, -800 + YDIFF, true},
    287 
    288             {0, ThaiBuddhistEra.BEFORE_BE, -3 - YDIFF, 4 + YDIFF, true},
    289             {0, ThaiBuddhistEra.BEFORE_BE, -6 - YDIFF, 7 + YDIFF, false},
    290             {0, ThaiBuddhistEra.BEFORE_BE, -7 - YDIFF, 8 + YDIFF, true},
    291             {0, ThaiBuddhistEra.BEFORE_BE, -999 - YDIFF, 1000 + YDIFF, false},
    292             {0, ThaiBuddhistEra.BEFORE_BE, -1999 - YDIFF, 2000 + YDIFF, true},
    293             {0, ThaiBuddhistEra.BEFORE_BE, 1, 0, false},
    294             {0, ThaiBuddhistEra.BEFORE_BE, 5 - YDIFF, -4 + YDIFF, true},
    295             {0, ThaiBuddhistEra.BEFORE_BE, 8 - YDIFF, -7 + YDIFF, false},
    296             {0, ThaiBuddhistEra.BEFORE_BE, 101 - YDIFF, -100 + YDIFF, false},
    297             {0, ThaiBuddhistEra.BEFORE_BE, 801 - YDIFF, -800 + YDIFF, true},
    298 
    299         };
    300     }
    301 
    302     @Test(dataProvider="prolepticYear")
    303     public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    304         Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue);
    305         assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
    306         assertEquals(eraObj, era);
    307         assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
    308     }
    309 
    310     @Test(dataProvider="prolepticYear")
    311     public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    312         assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
    313         assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());
    314 
    315         ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
    316         jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    317         if (isLeapYear) {
    318             assertEquals(jdate.lengthOfMonth(), 29);
    319         } else {
    320             assertEquals(jdate.lengthOfMonth(), 28);
    321         }
    322     }
    323 
    324     //-----------------------------------------------------------------------
    325     // Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
    326     //-----------------------------------------------------------------------
    327     @Test
    328     public void test_InvalidEras() {
    329         // Verify that the eras from every other Chronology are invalid
    330         for (Chronology chrono : Chronology.getAvailableChronologies()) {
    331             if (chrono instanceof ThaiBuddhistChronology) {
    332                 continue;
    333             }
    334             List<Era> eras = chrono.eras();
    335             for (Era era : eras) {
    336                 try {
    337                     ChronoLocalDate date = ThaiBuddhistChronology.INSTANCE.date(era, 1, 1, 1);
    338                     fail("ThaiBuddhistChronology.date did not throw ClassCastException for Era: " + era);
    339                 } catch (ClassCastException cex) {
    340                     ; // ignore expected exception
    341                 }
    342 
    343                 /* TODO: Test for missing ThaiBuddhistDate.of(Era, y, m, d) method.
    344                 try {
    345                     @SuppressWarnings("unused")
    346                     ThaiBuddhistDate jdate = ThaiBuddhistDate.of(era, 1, 1, 1);
    347                     fail("ThaiBuddhistDate.of did not throw ClassCastException for Era: " + era);
    348                 } catch (ClassCastException cex) {
    349                     ; // ignore expected exception
    350                 }
    351                 */
    352 
    353                 try {
    354                     @SuppressWarnings("unused")
    355                     int year = ThaiBuddhistChronology.INSTANCE.prolepticYear(era, 1);
    356                     fail("ThaiBuddhistChronology.prolepticYear did not throw ClassCastException for Era: " + era);
    357                 } catch (ClassCastException cex) {
    358                     ; // ignore expected exception
    359                 }            }
    360         }
    361     }
    362 
    363     //-----------------------------------------------------------------------
    364     // with(WithAdjuster)
    365     //-----------------------------------------------------------------------
    366     @Test
    367     public void test_adjust1() {
    368         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 10, 29);
    369         ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
    370         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31));
    371     }
    372 
    373     @Test
    374     public void test_adjust2() {
    375         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 12, 2);
    376         ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
    377         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31));
    378     }
    379 
    380     //-----------------------------------------------------------------------
    381     // withYear()
    382     //-----------------------------------------------------------------------
    383     @Test
    384     public void test_withYear_BE() {
    385         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
    386         ThaiBuddhistDate test = base.with(YEAR, 2554);
    387         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2554, 8, 29));
    388     }
    389 
    390     @Test
    391     public void test_withYear_BBE() {
    392         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
    393         ThaiBuddhistDate test = base.with(YEAR_OF_ERA, 2554);
    394         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2553, 8, 29));
    395     }
    396 
    397     //-----------------------------------------------------------------------
    398     // withEra()
    399     //-----------------------------------------------------------------------
    400     @Test
    401     public void test_withEra_BE() {
    402         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
    403         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue());
    404         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
    405     }
    406 
    407     @Test
    408     public void test_withEra_BBE() {
    409         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
    410         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BEFORE_BE.getValue());
    411         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29));
    412     }
    413 
    414     @Test
    415     public void test_withEra_swap() {
    416         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
    417         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue());
    418         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
    419     }
    420 
    421     //-----------------------------------------------------------------------
    422     // BuddhistDate.with(Local*)
    423     //-----------------------------------------------------------------------
    424     @Test
    425     public void test_adjust_toLocalDate() {
    426         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
    427         ThaiBuddhistDate test = jdate.with(LocalDate.of(2012, 7, 6));
    428         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 7, 6));
    429     }
    430 
    431     @Test(expectedExceptions=DateTimeException.class)
    432     public void test_adjust_toMonth() {
    433         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
    434         jdate.with(Month.APRIL);
    435     }
    436 
    437     //-----------------------------------------------------------------------
    438     // LocalDate.with(BuddhistDate)
    439     //-----------------------------------------------------------------------
    440     @Test
    441     public void test_LocalDate_adjustToBuddhistDate() {
    442         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
    443         LocalDate test = LocalDate.MIN.with(jdate);
    444         assertEquals(test, LocalDate.of(2012, 10, 29));
    445     }
    446 
    447     @Test
    448     public void test_LocalDateTime_adjustToBuddhistDate() {
    449         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
    450         LocalDateTime test = LocalDateTime.MIN.with(jdate);
    451         assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
    452     }
    453 
    454     //-----------------------------------------------------------------------
    455     // PeriodUntil()
    456     //-----------------------------------------------------------------------
    457     @Test
    458     public void test_periodUntilDate() {
    459         ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
    460         ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
    461         ChronoPeriod period = mdate1.until(mdate2);
    462         assertEquals(period, ThaiBuddhistChronology.INSTANCE.period(1, 1, 1));
    463     }
    464 
    465     @Test
    466     public void test_periodUntilUnit() {
    467         ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
    468         ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
    469         long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
    470         assertEquals(months, 13);
    471     }
    472 
    473     @Test
    474     public void test_periodUntilDiffChrono() {
    475         ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
    476         ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
    477         MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
    478         ChronoPeriod period = mdate1.until(ldate2);
    479         assertEquals(period, ThaiBuddhistChronology.INSTANCE.period(1, 1, 1));
    480     }
    481 
    482     //-----------------------------------------------------------------------
    483     // toString()
    484     //-----------------------------------------------------------------------
    485     @DataProvider(name="toString")
    486     Object[][] data_toString() {
    487         return new Object[][] {
    488             {ThaiBuddhistChronology.INSTANCE.date(544, 1, 1), "ThaiBuddhist BE 544-01-01"},
    489             {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 28), "ThaiBuddhist BE 2271-10-28"},
    490             {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 29), "ThaiBuddhist BE 2271-10-29"},
    491             {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 5), "ThaiBuddhist BE 2270-12-05"},
    492             {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 6), "ThaiBuddhist BE 2270-12-06"},
    493         };
    494     }
    495 
    496     @Test(dataProvider="toString")
    497     public void test_toString(ThaiBuddhistDate jdate, String expected) {
    498         assertEquals(jdate.toString(), expected);
    499     }
    500 
    501     //-----------------------------------------------------------------------
    502     // chronology range(ChronoField)
    503     //-----------------------------------------------------------------------
    504     @Test
    505     public void test_Chrono_range() {
    506         long minYear = LocalDate.MIN.getYear() + YDIFF;
    507         long maxYear = LocalDate.MAX.getYear() + YDIFF;
    508         assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR), ValueRange.of(minYear, maxYear));
    509         assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, -minYear + 1, maxYear));
    510 
    511         assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_MONTH), DAY_OF_MONTH.range());
    512         assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_YEAR), DAY_OF_YEAR.range());
    513         assertEquals(ThaiBuddhistChronology.INSTANCE.range(MONTH_OF_YEAR), MONTH_OF_YEAR.range());
    514     }
    515 
    516     //-----------------------------------------------------------------------
    517     // equals()
    518     //-----------------------------------------------------------------------
    519     @Test
    520     public void test_equals_true() {
    521         assertTrue(ThaiBuddhistChronology.INSTANCE.equals(ThaiBuddhistChronology.INSTANCE));
    522     }
    523 
    524     @Test
    525     public void test_equals_false() {
    526         assertFalse(ThaiBuddhistChronology.INSTANCE.equals(IsoChronology.INSTANCE));
    527     }
    528 
    529     //-----------------------------------------------------------------------
    530     //-----------------------------------------------------------------------
    531     @DataProvider(name = "resolve_yearOfEra")
    532     Object[][] data_resolve_yearOfEra() {
    533         return new Object[][] {
    534                 // era only
    535                 {ResolverStyle.STRICT, -1, null, null, null, null},
    536                 {ResolverStyle.SMART, -1, null, null, null, null},
    537                 {ResolverStyle.LENIENT, -1, null, null, null, null},
    538 
    539                 {ResolverStyle.STRICT, 0, null, null, ChronoField.ERA, 0},
    540                 {ResolverStyle.SMART, 0, null, null, ChronoField.ERA, 0},
    541                 {ResolverStyle.LENIENT, 0, null, null, ChronoField.ERA, 0},
    542 
    543                 {ResolverStyle.STRICT, 1, null, null, ChronoField.ERA, 1},
    544                 {ResolverStyle.SMART, 1, null, null, ChronoField.ERA, 1},
    545                 {ResolverStyle.LENIENT, 1, null, null, ChronoField.ERA, 1},
    546 
    547                 {ResolverStyle.STRICT, 2, null, null, null, null},
    548                 {ResolverStyle.SMART, 2, null, null, null, null},
    549                 {ResolverStyle.LENIENT, 2, null, null, null, null},
    550 
    551                 // era and year-of-era
    552                 {ResolverStyle.STRICT, -1, 2012, null, null, null},
    553                 {ResolverStyle.SMART, -1, 2012, null, null, null},
    554                 {ResolverStyle.LENIENT, -1, 2012, null, null, null},
    555 
    556                 {ResolverStyle.STRICT, 0, 2012, null, ChronoField.YEAR, -2011},
    557                 {ResolverStyle.SMART, 0, 2012, null, ChronoField.YEAR, -2011},
    558                 {ResolverStyle.LENIENT, 0, 2012, null, ChronoField.YEAR, -2011},
    559 
    560                 {ResolverStyle.STRICT, 1, 2012, null, ChronoField.YEAR, 2012},
    561                 {ResolverStyle.SMART, 1, 2012, null, ChronoField.YEAR, 2012},
    562                 {ResolverStyle.LENIENT, 1, 2012, null, ChronoField.YEAR, 2012},
    563 
    564                 {ResolverStyle.STRICT, 2, 2012, null, null, null},
    565                 {ResolverStyle.SMART, 2, 2012, null, null, null},
    566                 {ResolverStyle.LENIENT, 2, 2012, null, null, null},
    567 
    568                 // year-of-era only
    569                 {ResolverStyle.STRICT, null, 2012, null, ChronoField.YEAR_OF_ERA, 2012},
    570                 {ResolverStyle.SMART, null, 2012, null, ChronoField.YEAR, 2012},
    571                 {ResolverStyle.LENIENT, null, 2012, null, ChronoField.YEAR, 2012},
    572 
    573                 {ResolverStyle.STRICT, null, Integer.MAX_VALUE, null, null, null},
    574                 {ResolverStyle.SMART, null, Integer.MAX_VALUE, null, null, null},
    575                 {ResolverStyle.LENIENT, null, Integer.MAX_VALUE, null, ChronoField.YEAR, Integer.MAX_VALUE},
    576 
    577                 // year-of-era and year
    578                 {ResolverStyle.STRICT, null, 2012, 2012, ChronoField.YEAR, 2012},
    579                 {ResolverStyle.SMART, null, 2012, 2012, ChronoField.YEAR, 2012},
    580                 {ResolverStyle.LENIENT, null, 2012, 2012, ChronoField.YEAR, 2012},
    581 
    582                 {ResolverStyle.STRICT, null, 2012, -2011, ChronoField.YEAR, -2011},
    583                 {ResolverStyle.SMART, null, 2012, -2011, ChronoField.YEAR, -2011},
    584                 {ResolverStyle.LENIENT, null, 2012, -2011, ChronoField.YEAR, -2011},
    585 
    586                 {ResolverStyle.STRICT, null, 2012, 2013, null, null},
    587                 {ResolverStyle.SMART, null, 2012, 2013, null, null},
    588                 {ResolverStyle.LENIENT, null, 2012, 2013, null, null},
    589 
    590                 {ResolverStyle.STRICT, null, 2012, -2013, null, null},
    591                 {ResolverStyle.SMART, null, 2012, -2013, null, null},
    592                 {ResolverStyle.LENIENT, null, 2012, -2013, null, null},
    593         };
    594     }
    595 
    596     @Test(dataProvider = "resolve_yearOfEra")
    597     public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    598         Map<TemporalField, Long> fieldValues = new HashMap<>();
    599         if (e != null) {
    600             fieldValues.put(ChronoField.ERA, (long) e);
    601         }
    602         if (yoe != null) {
    603             fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    604         }
    605         if (y != null) {
    606             fieldValues.put(ChronoField.YEAR, (long) y);
    607         }
    608         if (field != null) {
    609             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
    610             assertEquals(date, null);
    611             assertEquals(fieldValues.get(field), (Long) expected.longValue());
    612             assertEquals(fieldValues.size(), 1);
    613         } else {
    614             try {
    615                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
    616                 fail("Should have failed");
    617             } catch (DateTimeException ex) {
    618                 // expected
    619             }
    620         }
    621     }
    622 
    623     //-----------------------------------------------------------------------
    624     //-----------------------------------------------------------------------
    625     @DataProvider(name = "resolve_ymd")
    626     Object[][] data_resolve_ymd() {
    627         return new Object[][] {
    628                 {YDIFF + 2012, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
    629                 {YDIFF + 2012, 1, -364, date(YDIFF + 2011, 1, 1), false, false},
    630                 {YDIFF + 2012, 1, -31, date(YDIFF + 2011, 11, 30), false, false},
    631                 {YDIFF + 2012, 1, -30, date(YDIFF + 2011, 12, 1), false, false},
    632                 {YDIFF + 2012, 1, -12, date(YDIFF + 2011, 12, 19), false, false},
    633                 {YDIFF + 2012, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
    634                 {YDIFF + 2012, 1, 27, date(YDIFF + 2012, 1, 27), true, true},
    635                 {YDIFF + 2012, 1, 28, date(YDIFF + 2012, 1, 28), true, true},
    636                 {YDIFF + 2012, 1, 29, date(YDIFF + 2012, 1, 29), true, true},
    637                 {YDIFF + 2012, 1, 30, date(YDIFF + 2012, 1, 30), true, true},
    638                 {YDIFF + 2012, 1, 31, date(YDIFF + 2012, 1, 31), true, true},
    639                 {YDIFF + 2012, 1, 59, date(YDIFF + 2012, 2, 28), false, false},
    640                 {YDIFF + 2012, 1, 60, date(YDIFF + 2012, 2, 29), false, false},
    641                 {YDIFF + 2012, 1, 61, date(YDIFF + 2012, 3, 1), false, false},
    642                 {YDIFF + 2012, 1, 365, date(YDIFF + 2012, 12, 30), false, false},
    643                 {YDIFF + 2012, 1, 366, date(YDIFF + 2012, 12, 31), false, false},
    644                 {YDIFF + 2012, 1, 367, date(YDIFF + 2013, 1, 1), false, false},
    645                 {YDIFF + 2012, 1, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
    646                 {YDIFF + 2012, 1, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
    647 
    648                 {YDIFF + 2012, 2, 1, date(YDIFF + 2012, 2, 1), true, true},
    649                 {YDIFF + 2012, 2, 28, date(YDIFF + 2012, 2, 28), true, true},
    650                 {YDIFF + 2012, 2, 29, date(YDIFF + 2012, 2, 29), true, true},
    651                 {YDIFF + 2012, 2, 30, date(YDIFF + 2012, 3, 1), date(YDIFF + 2012, 2, 29), false},
    652                 {YDIFF + 2012, 2, 31, date(YDIFF + 2012, 3, 2), date(YDIFF + 2012, 2, 29), false},
    653                 {YDIFF + 2012, 2, 32, date(YDIFF + 2012, 3, 3), false, false},
    654 
    655                 {YDIFF + 2012, -12, 1, date(YDIFF + 2010, 12, 1), false, false},
    656                 {YDIFF + 2012, -11, 1, date(YDIFF + 2011, 1, 1), false, false},
    657                 {YDIFF + 2012, -1, 1, date(YDIFF + 2011, 11, 1), false, false},
    658                 {YDIFF + 2012, 0, 1, date(YDIFF + 2011, 12, 1), false, false},
    659                 {YDIFF + 2012, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
    660                 {YDIFF + 2012, 12, 1, date(YDIFF + 2012, 12, 1), true, true},
    661                 {YDIFF + 2012, 13, 1, date(YDIFF + 2013, 1, 1), false, false},
    662                 {YDIFF + 2012, 24, 1, date(YDIFF + 2013, 12, 1), false, false},
    663                 {YDIFF + 2012, 25, 1, date(YDIFF + 2014, 1, 1), false, false},
    664 
    665                 {YDIFF + 2012, 6, -31, date(YDIFF + 2012, 4, 30), false, false},
    666                 {YDIFF + 2012, 6, -30, date(YDIFF + 2012, 5, 1), false, false},
    667                 {YDIFF + 2012, 6, -1, date(YDIFF + 2012, 5, 30), false, false},
    668                 {YDIFF + 2012, 6, 0, date(YDIFF + 2012, 5, 31), false, false},
    669                 {YDIFF + 2012, 6, 1, date(YDIFF + 2012, 6, 1), true, true},
    670                 {YDIFF + 2012, 6, 30, date(YDIFF + 2012, 6, 30), true, true},
    671                 {YDIFF + 2012, 6, 31, date(YDIFF + 2012, 7, 1), date(YDIFF + 2012, 6, 30), false},
    672                 {YDIFF + 2012, 6, 61, date(YDIFF + 2012, 7, 31), false, false},
    673                 {YDIFF + 2012, 6, 62, date(YDIFF + 2012, 8, 1), false, false},
    674 
    675                 {YDIFF + 2011, 2, 1, date(YDIFF + 2011, 2, 1), true, true},
    676                 {YDIFF + 2011, 2, 28, date(YDIFF + 2011, 2, 28), true, true},
    677                 {YDIFF + 2011, 2, 29, date(YDIFF + 2011, 3, 1), date(YDIFF + 2011, 2, 28), false},
    678                 {YDIFF + 2011, 2, 30, date(YDIFF + 2011, 3, 2), date(YDIFF + 2011, 2, 28), false},
    679                 {YDIFF + 2011, 2, 31, date(YDIFF + 2011, 3, 3), date(YDIFF + 2011, 2, 28), false},
    680                 {YDIFF + 2011, 2, 32, date(YDIFF + 2011, 3, 4), false, false},
    681         };
    682     }
    683 
    684     @Test(dataProvider = "resolve_ymd")
    685     public void test_resolve_ymd_lenient(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    686         Map<TemporalField, Long> fieldValues = new HashMap<>();
    687         fieldValues.put(ChronoField.YEAR, (long) y);
    688         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    689         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    690         ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
    691         assertEquals(date, expected);
    692         assertEquals(fieldValues.size(), 0);
    693     }
    694 
    695     @Test(dataProvider = "resolve_ymd")
    696     public void test_resolve_ymd_smart(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    697         Map<TemporalField, Long> fieldValues = new HashMap<>();
    698         fieldValues.put(ChronoField.YEAR, (long) y);
    699         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    700         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    701         if (Boolean.TRUE.equals(smart)) {
    702             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    703             assertEquals(date, expected);
    704             assertEquals(fieldValues.size(), 0);
    705         } else if (smart instanceof ThaiBuddhistDate) {
    706             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    707             assertEquals(date, smart);
    708         } else {
    709             try {
    710                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    711                 fail("Should have failed");
    712             } catch (DateTimeException ex) {
    713                 // expected
    714             }
    715         }
    716     }
    717 
    718     @Test(dataProvider = "resolve_ymd")
    719     public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    720         Map<TemporalField, Long> fieldValues = new HashMap<>();
    721         fieldValues.put(ChronoField.YEAR, (long) y);
    722         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    723         fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    724         if (strict) {
    725             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    726             assertEquals(date, expected);
    727             assertEquals(fieldValues.size(), 0);
    728         } else {
    729             try {
    730                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    731                 fail("Should have failed");
    732             } catch (DateTimeException ex) {
    733                 // expected
    734             }
    735         }
    736     }
    737 
    738     //-----------------------------------------------------------------------
    739     //-----------------------------------------------------------------------
    740     @DataProvider(name = "resolve_yd")
    741     Object[][] data_resolve_yd() {
    742         return new Object[][] {
    743                 {YDIFF + 2012, -365, date(YDIFF + 2010, 12, 31), false, false},
    744                 {YDIFF + 2012, -364, date(YDIFF + 2011, 1, 1), false, false},
    745                 {YDIFF + 2012, -31, date(YDIFF + 2011, 11, 30), false, false},
    746                 {YDIFF + 2012, -30, date(YDIFF + 2011, 12, 1), false, false},
    747                 {YDIFF + 2012, -12, date(YDIFF + 2011, 12, 19), false, false},
    748                 {YDIFF + 2012, -1, date(YDIFF + 2011, 12, 30), false, false},
    749                 {YDIFF + 2012, 0, date(YDIFF + 2011, 12, 31), false, false},
    750                 {YDIFF + 2012, 1, date(YDIFF + 2012, 1, 1), true, true},
    751                 {YDIFF + 2012, 2, date(YDIFF + 2012, 1, 2), true, true},
    752                 {YDIFF + 2012, 31, date(YDIFF + 2012, 1, 31), true, true},
    753                 {YDIFF + 2012, 32, date(YDIFF + 2012, 2, 1), true, true},
    754                 {YDIFF + 2012, 59, date(YDIFF + 2012, 2, 28), true, true},
    755                 {YDIFF + 2012, 60, date(YDIFF + 2012, 2, 29), true, true},
    756                 {YDIFF + 2012, 61, date(YDIFF + 2012, 3, 1), true, true},
    757                 {YDIFF + 2012, 365, date(YDIFF + 2012, 12, 30), true, true},
    758                 {YDIFF + 2012, 366, date(YDIFF + 2012, 12, 31), true, true},
    759                 {YDIFF + 2012, 367, date(YDIFF + 2013, 1, 1), false, false},
    760                 {YDIFF + 2012, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
    761                 {YDIFF + 2012, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
    762 
    763                 {YDIFF + 2011, 59, date(YDIFF + 2011, 2, 28), true, true},
    764                 {YDIFF + 2011, 60, date(YDIFF + 2011, 3, 1), true, true},
    765         };
    766     }
    767 
    768     @Test(dataProvider = "resolve_yd")
    769     public void test_resolve_yd_lenient(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    770         Map<TemporalField, Long> fieldValues = new HashMap<>();
    771         fieldValues.put(ChronoField.YEAR, (long) y);
    772         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    773         ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
    774         assertEquals(date, expected);
    775         assertEquals(fieldValues.size(), 0);
    776     }
    777 
    778     @Test(dataProvider = "resolve_yd")
    779     public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    780         Map<TemporalField, Long> fieldValues = new HashMap<>();
    781         fieldValues.put(ChronoField.YEAR, (long) y);
    782         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    783         if (smart) {
    784             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    785             assertEquals(date, expected);
    786             assertEquals(fieldValues.size(), 0);
    787         } else {
    788             try {
    789                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    790                 fail("Should have failed");
    791             } catch (DateTimeException ex) {
    792                 // expected
    793             }
    794         }
    795     }
    796 
    797     @Test(dataProvider = "resolve_yd")
    798     public void test_resolve_yd_strict(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    799         Map<TemporalField, Long> fieldValues = new HashMap<>();
    800         fieldValues.put(ChronoField.YEAR, (long) y);
    801         fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    802         if (strict) {
    803             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    804             assertEquals(date, expected);
    805             assertEquals(fieldValues.size(), 0);
    806         } else {
    807             try {
    808                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    809                 fail("Should have failed");
    810             } catch (DateTimeException ex) {
    811                 // expected
    812             }
    813         }
    814     }
    815 
    816     //-----------------------------------------------------------------------
    817     //-----------------------------------------------------------------------
    818     @DataProvider(name = "resolve_ymaa")
    819     Object[][] data_resolve_ymaa() {
    820         return new Object[][] {
    821                 {YDIFF + 2012, 1, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
    822                 {YDIFF + 2012, 1, 1, -364, date(YDIFF + 2011, 1, 1), false, false},
    823                 {YDIFF + 2012, 1, 1, -31, date(YDIFF + 2011, 11, 30), false, false},
    824                 {YDIFF + 2012, 1, 1, -30, date(YDIFF + 2011, 12, 1), false, false},
    825                 {YDIFF + 2012, 1, 1, -12, date(YDIFF + 2011, 12, 19), false, false},
    826                 {YDIFF + 2012, 1, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
    827                 {YDIFF + 2012, 1, 1, 59, date(YDIFF + 2012, 2, 28), false, false},
    828                 {YDIFF + 2012, 1, 1, 60, date(YDIFF + 2012, 2, 29), false, false},
    829                 {YDIFF + 2012, 1, 1, 61, date(YDIFF + 2012, 3, 1), false, false},
    830                 {YDIFF + 2012, 1, 1, 365, date(YDIFF + 2012, 12, 30), false, false},
    831                 {YDIFF + 2012, 1, 1, 366, date(YDIFF + 2012, 12, 31), false, false},
    832                 {YDIFF + 2012, 1, 1, 367, date(YDIFF + 2013, 1, 1), false, false},
    833                 {YDIFF + 2012, 1, 1, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
    834                 {YDIFF + 2012, 1, 1, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
    835 
    836                 {YDIFF + 2012, 2, 0, 1, date(YDIFF + 2012, 1, 25), false, false},
    837                 {YDIFF + 2012, 2, 0, 7, date(YDIFF + 2012, 1, 31), false, false},
    838                 {YDIFF + 2012, 2, 1, 1, date(YDIFF + 2012, 2, 1), true, true},
    839                 {YDIFF + 2012, 2, 1, 7, date(YDIFF + 2012, 2, 7), true, true},
    840                 {YDIFF + 2012, 2, 2, 1, date(YDIFF + 2012, 2, 8), true, true},
    841                 {YDIFF + 2012, 2, 2, 7, date(YDIFF + 2012, 2, 14), true, true},
    842                 {YDIFF + 2012, 2, 3, 1, date(YDIFF + 2012, 2, 15), true, true},
    843                 {YDIFF + 2012, 2, 3, 7, date(YDIFF + 2012, 2, 21), true, true},
    844                 {YDIFF + 2012, 2, 4, 1, date(YDIFF + 2012, 2, 22), true, true},
    845                 {YDIFF + 2012, 2, 4, 7, date(YDIFF + 2012, 2, 28), true, true},
    846                 {YDIFF + 2012, 2, 5, 1, date(YDIFF + 2012, 2, 29), true, true},
    847                 {YDIFF + 2012, 2, 5, 2, date(YDIFF + 2012, 3, 1), true, false},
    848                 {YDIFF + 2012, 2, 5, 7, date(YDIFF + 2012, 3, 6), true, false},
    849                 {YDIFF + 2012, 2, 6, 1, date(YDIFF + 2012, 3, 7), false, false},
    850                 {YDIFF + 2012, 2, 6, 7, date(YDIFF + 2012, 3, 13), false, false},
    851 
    852                 {YDIFF + 2012, 12, 1, 1, date(YDIFF + 2012, 12, 1), true, true},
    853                 {YDIFF + 2012, 12, 5, 1, date(YDIFF + 2012, 12, 29), true, true},
    854                 {YDIFF + 2012, 12, 5, 2, date(YDIFF + 2012, 12, 30), true, true},
    855                 {YDIFF + 2012, 12, 5, 3, date(YDIFF + 2012, 12, 31), true, true},
    856                 {YDIFF + 2012, 12, 5, 4, date(YDIFF + 2013, 1, 1), true, false},
    857                 {YDIFF + 2012, 12, 5, 7, date(YDIFF + 2013, 1, 4), true, false},
    858 
    859                 {YDIFF + 2012, -12, 1, 1, date(YDIFF + 2010, 12, 1), false, false},
    860                 {YDIFF + 2012, -11, 1, 1, date(YDIFF + 2011, 1, 1), false, false},
    861                 {YDIFF + 2012, -1, 1, 1, date(YDIFF + 2011, 11, 1), false, false},
    862                 {YDIFF + 2012, 0, 1, 1, date(YDIFF + 2011, 12, 1), false, false},
    863                 {YDIFF + 2012, 1, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
    864                 {YDIFF + 2012, 12, 1, 1, date(YDIFF + 2012, 12, 1), true, true},
    865                 {YDIFF + 2012, 13, 1, 1, date(YDIFF + 2013, 1, 1), false, false},
    866                 {YDIFF + 2012, 24, 1, 1, date(YDIFF + 2013, 12, 1), false, false},
    867                 {YDIFF + 2012, 25, 1, 1, date(YDIFF + 2014, 1, 1), false, false},
    868 
    869                 {YDIFF + 2011, 2, 1, 1, date(YDIFF + 2011, 2, 1), true, true},
    870                 {YDIFF + 2011, 2, 4, 7, date(YDIFF + 2011, 2, 28), true, true},
    871                 {YDIFF + 2011, 2, 5, 1, date(YDIFF + 2011, 3, 1), true, false},
    872         };
    873     }
    874 
    875     @Test(dataProvider = "resolve_ymaa")
    876     public void test_resolve_ymaa_lenient(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    877         Map<TemporalField, Long> fieldValues = new HashMap<>();
    878         fieldValues.put(ChronoField.YEAR, (long) y);
    879         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    880         fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    881         fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    882         ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
    883         assertEquals(date, expected);
    884         assertEquals(fieldValues.size(), 0);
    885     }
    886 
    887     @Test(dataProvider = "resolve_ymaa")
    888     public void test_resolve_ymaa_smart(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    889         Map<TemporalField, Long> fieldValues = new HashMap<>();
    890         fieldValues.put(ChronoField.YEAR, (long) y);
    891         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    892         fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    893         fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    894         if (smart) {
    895             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    896             assertEquals(date, expected);
    897             assertEquals(fieldValues.size(), 0);
    898         } else {
    899             try {
    900                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
    901                 fail("Should have failed");
    902             } catch (DateTimeException ex) {
    903                 // expected
    904             }
    905         }
    906     }
    907 
    908     @Test(dataProvider = "resolve_ymaa")
    909     public void test_resolve_ymaa_strict(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    910         Map<TemporalField, Long> fieldValues = new HashMap<>();
    911         fieldValues.put(ChronoField.YEAR, (long) y);
    912         fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    913         fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    914         fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    915         if (strict) {
    916             ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    917             assertEquals(date, expected);
    918             assertEquals(fieldValues.size(), 0);
    919         } else {
    920             try {
    921                 ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
    922                 fail("Should have failed");
    923             } catch (DateTimeException ex) {
    924                 // expected
    925             }
    926         }
    927     }
    928 
    929     //-----------------------------------------------------------------------
    930     private static ThaiBuddhistDate date(int y, int m, int d) {
    931         return ThaiBuddhistDate.of(y, m, d);
    932     }
    933 
    934 }
    935