test/java/time/tck/java/time/chrono/TestThaiBuddhistChronology.java

Print this page




  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.calendar;
  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.assertTrue;
  67 
  68 import java.time.DateTimeException;
  69 import java.time.LocalDate;
  70 import java.time.LocalDateTime;
  71 import java.time.Month;
  72 import java.time.calendar.ThaiBuddhistChrono;
  73 import java.time.temporal.Chrono;
  74 import java.time.temporal.ChronoField;
  75 import java.time.temporal.ChronoLocalDate;



  76 import java.time.temporal.Adjusters;

  77 import java.time.temporal.ValueRange;
  78 import java.time.temporal.ISOChrono;
  79 
  80 import org.testng.Assert;
  81 import org.testng.annotations.DataProvider;
  82 import org.testng.annotations.Test;
  83 
  84 /**
  85  * Test.
  86  */
  87 @Test
  88 public class TestThaiBuddhistChrono {
  89 
  90     private static final int YDIFF = 543;
  91 
  92     //-----------------------------------------------------------------------
  93     // Chrono.ofName("ThaiBuddhist")  Lookup by name
  94     //-----------------------------------------------------------------------
  95     @Test(groups={"tck"})
  96     public void test_chrono_byName() {
  97         Chrono<ThaiBuddhistChrono> c = ThaiBuddhistChrono.INSTANCE;
  98         Chrono<?> test = Chrono.of("ThaiBuddhist");
  99         Assert.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName");
 100         Assert.assertEquals(test.getId(), "ThaiBuddhist", "ID mismatch");
 101         Assert.assertEquals(test.getCalendarType(), "buddhist", "Type mismatch");
 102         Assert.assertEquals(test, c);
 103     }
 104 
 105     //-----------------------------------------------------------------------






































 106     // creation, toLocalDate()
 107     //-----------------------------------------------------------------------
 108     @DataProvider(name="samples")
 109     Object[][] data_samples() {
 110         return new Object[][] {
 111             {ThaiBuddhistChrono.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)},
 112             {ThaiBuddhistChrono.INSTANCE.date(1 + YDIFF, 1, 2), LocalDate.of(1, 1, 2)},
 113             {ThaiBuddhistChrono.INSTANCE.date(1 + YDIFF, 1, 3), LocalDate.of(1, 1, 3)},
 114 
 115             {ThaiBuddhistChrono.INSTANCE.date(2 + YDIFF, 1, 1), LocalDate.of(2, 1, 1)},
 116             {ThaiBuddhistChrono.INSTANCE.date(3 + YDIFF, 1, 1), LocalDate.of(3, 1, 1)},
 117             {ThaiBuddhistChrono.INSTANCE.date(3 + YDIFF, 12, 6), LocalDate.of(3, 12, 6)},
 118             {ThaiBuddhistChrono.INSTANCE.date(4 + YDIFF, 1, 1), LocalDate.of(4, 1, 1)},
 119             {ThaiBuddhistChrono.INSTANCE.date(4 + YDIFF, 7, 3), LocalDate.of(4, 7, 3)},
 120             {ThaiBuddhistChrono.INSTANCE.date(4 + YDIFF, 7, 4), LocalDate.of(4, 7, 4)},
 121             {ThaiBuddhistChrono.INSTANCE.date(5 + YDIFF, 1, 1), LocalDate.of(5, 1, 1)},
 122             {ThaiBuddhistChrono.INSTANCE.date(1662 + YDIFF, 3, 3), LocalDate.of(1662, 3, 3)},
 123             {ThaiBuddhistChrono.INSTANCE.date(1728 + YDIFF, 10, 28), LocalDate.of(1728, 10, 28)},
 124             {ThaiBuddhistChrono.INSTANCE.date(1728 + YDIFF, 10, 29), LocalDate.of(1728, 10, 29)},
 125             {ThaiBuddhistChrono.INSTANCE.date(2555, 8, 29), LocalDate.of(2012, 8, 29)},





 126         };
 127     }
 128 
 129     @Test(dataProvider="samples", groups={"tck"})
 130     public void test_toLocalDate(ChronoLocalDate<ThaiBuddhistChrono> jdate, LocalDate iso) {
 131         assertEquals(LocalDate.from(jdate), iso);
 132     }
 133 
 134     @Test(dataProvider="samples", groups={"tck"})
 135     public void test_fromCalendrical(ChronoLocalDate<ThaiBuddhistChrono> jdate, LocalDate iso) {
 136         assertEquals(ThaiBuddhistChrono.INSTANCE.date(iso), jdate);
 137     }
 138 
 139     @DataProvider(name="badDates")
 140     Object[][] data_badDates() {
 141         return new Object[][] {
 142             {1728, 0, 0},
 143 
 144             {1728, -1, 1},
 145             {1728, 0, 1},
 146             {1728, 14, 1},
 147             {1728, 15, 1},
 148 
 149             {1728, 1, -1},
 150             {1728, 1, 0},
 151             {1728, 1, 32},
 152 
 153             {1728, 12, -1},
 154             {1728, 12, 0},
 155             {1728, 12, 32},




 156         };
 157     }
 158 
 159     @Test(dataProvider="badDates", groups={"tck"}, expectedExceptions=DateTimeException.class)
 160     public void test_badDates(int year, int month, int dom) {
 161         ThaiBuddhistChrono.INSTANCE.date(year, month, dom);









































 162     }
 163 
 164     //-----------------------------------------------------------------------
 165     // with(WithAdjuster)
 166     //-----------------------------------------------------------------------
 167     @Test(groups={"tck"})
 168     public void test_adjust1() {
 169         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(1728, 10, 29);
 170         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(Adjusters.lastDayOfMonth());
 171         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(1728, 10, 31));
 172     }
 173 
 174     @Test(groups={"tck"})
 175     public void test_adjust2() {
 176         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(1728, 12, 2);
 177         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(Adjusters.lastDayOfMonth());
 178         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(1728, 12, 31));
 179     }
 180 
 181     //-----------------------------------------------------------------------
 182     // withYear()
 183     //-----------------------------------------------------------------------
 184     @Test(groups={"tck"})
 185     public void test_withYear_BE() {
 186         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(2555, 8, 29);
 187         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(YEAR, 2554);
 188         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(2554, 8, 29));
 189     }
 190 
 191     @Test(groups={"tck"})
 192     public void test_withYear_BBE() {
 193         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(-2554, 8, 29);
 194         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(YEAR_OF_ERA, 2554);
 195         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(-2553, 8, 29));
 196     }
 197 
 198     //-----------------------------------------------------------------------
 199     // withEra()
 200     //-----------------------------------------------------------------------
 201     @Test(groups={"tck"})
 202     public void test_withEra_BE() {
 203         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(2555, 8, 29);
 204         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(ChronoField.ERA, ThaiBuddhistChrono.ERA_BE.getValue());
 205         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(2555, 8, 29));
 206     }
 207 
 208     @Test(groups={"tck"})
 209     public void test_withEra_BBE() {
 210         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(-2554, 8, 29);
 211         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(ChronoField.ERA, ThaiBuddhistChrono.ERA_BEFORE_BE.getValue());
 212         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(-2554, 8, 29));
 213     }
 214 
 215     @Test(groups={"tck"})
 216     public void test_withEra_swap() {
 217         ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(-2554, 8, 29);
 218         ChronoLocalDate<ThaiBuddhistChrono> test = base.with(ChronoField.ERA, ThaiBuddhistChrono.ERA_BE.getValue());
 219         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(2555, 8, 29));
 220     }
 221 
 222     //-----------------------------------------------------------------------
 223     // BuddhistDate.with(Local*)
 224     //-----------------------------------------------------------------------
 225     @Test(groups={"tck"})
 226     public void test_adjust_toLocalDate() {
 227         ChronoLocalDate<ThaiBuddhistChrono> jdate = ThaiBuddhistChrono.INSTANCE.date(1726, 1, 4);
 228         ChronoLocalDate<ThaiBuddhistChrono> test = jdate.with(LocalDate.of(2012, 7, 6));
 229         assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(2555, 7, 6));
 230     }
 231 
 232     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
 233     public void test_adjust_toMonth() {
 234         ChronoLocalDate<ThaiBuddhistChrono> jdate = ThaiBuddhistChrono.INSTANCE.date(1726, 1, 4);
 235         jdate.with(Month.APRIL);
 236     }
 237 
 238     //-----------------------------------------------------------------------
 239     // LocalDate.with(BuddhistDate)
 240     //-----------------------------------------------------------------------
 241     @Test(groups={"tck"})
 242     public void test_LocalDate_adjustToBuddhistDate() {
 243         ChronoLocalDate<ThaiBuddhistChrono> jdate = ThaiBuddhistChrono.INSTANCE.date(2555, 10, 29);
 244         LocalDate test = LocalDate.MIN.with(jdate);
 245         assertEquals(test, LocalDate.of(2012, 10, 29));
 246     }
 247 
 248     @Test(groups={"tck"})
 249     public void test_LocalDateTime_adjustToBuddhistDate() {
 250         ChronoLocalDate<ThaiBuddhistChrono> jdate = ThaiBuddhistChrono.INSTANCE.date(2555, 10, 29);
 251         LocalDateTime test = LocalDateTime.MIN.with(jdate);
 252         assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
 253     }
 254 
 255     //-----------------------------------------------------------------------
 256     // toString()
 257     //-----------------------------------------------------------------------
 258     @DataProvider(name="toString")
 259     Object[][] data_toString() {
 260         return new Object[][] {
 261             {ThaiBuddhistChrono.INSTANCE.date(544, 1, 1), "ThaiBuddhist BE 544-01-01"},
 262             {ThaiBuddhistChrono.INSTANCE.date(2271, 10, 28), "ThaiBuddhist BE 2271-10-28"},
 263             {ThaiBuddhistChrono.INSTANCE.date(2271, 10, 29), "ThaiBuddhist BE 2271-10-29"},
 264             {ThaiBuddhistChrono.INSTANCE.date(2270, 12, 5), "ThaiBuddhist BE 2270-12-05"},
 265             {ThaiBuddhistChrono.INSTANCE.date(2270, 12, 6), "ThaiBuddhist BE 2270-12-06"},
 266         };
 267     }
 268 
 269     @Test(dataProvider="toString", groups={"tck"})
 270     public void test_toString(ChronoLocalDate<ThaiBuddhistChrono> jdate, String expected) {
 271         assertEquals(jdate.toString(), expected);
 272     }
 273 
 274     //-----------------------------------------------------------------------
 275     // chronology range(ChronoField)
 276     //-----------------------------------------------------------------------
 277     @Test(groups={"tck"})
 278     public void test_Chrono_range() {
 279         long minYear = LocalDate.MIN.getYear() + YDIFF;
 280         long maxYear = LocalDate.MAX.getYear() + YDIFF;
 281         assertEquals(ThaiBuddhistChrono.INSTANCE.range(YEAR), ValueRange.of(minYear, maxYear));
 282         assertEquals(ThaiBuddhistChrono.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, -minYear + 1, maxYear));
 283 
 284         assertEquals(ThaiBuddhistChrono.INSTANCE.range(DAY_OF_MONTH), DAY_OF_MONTH.range());
 285         assertEquals(ThaiBuddhistChrono.INSTANCE.range(DAY_OF_YEAR), DAY_OF_YEAR.range());
 286         assertEquals(ThaiBuddhistChrono.INSTANCE.range(MONTH_OF_YEAR), MONTH_OF_YEAR.range());
 287     }
 288 
 289     //-----------------------------------------------------------------------
 290     // equals()
 291     //-----------------------------------------------------------------------
 292     @Test(groups="tck")
 293     public void test_equals_true() {
 294         assertTrue(ThaiBuddhistChrono.INSTANCE.equals(ThaiBuddhistChrono.INSTANCE));
 295     }
 296 
 297     @Test(groups="tck")
 298     public void test_equals_false() {
 299         assertFalse(ThaiBuddhistChrono.INSTANCE.equals(ISOChrono.INSTANCE));
 300     }
 301 
 302 }


  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.assertTrue;
  67 
  68 import java.time.DateTimeException;
  69 import java.time.LocalDate;
  70 import java.time.LocalDateTime;
  71 import java.time.Month;
  72 import java.time.Year;
  73 import java.time.chrono.ThaiBuddhistChronology;
  74 import java.time.chrono.ThaiBuddhistDate;
  75 import java.time.chrono.Chronology;
  76 import java.time.chrono.ChronoLocalDate;
  77 import java.time.chrono.Era;
  78 import java.time.chrono.IsoChronology;
  79 import java.time.temporal.Adjusters;
  80 import java.time.temporal.ChronoField;
  81 import java.time.temporal.ValueRange;
  82 import java.util.Locale;
  83 
  84 import org.testng.Assert;
  85 import org.testng.annotations.DataProvider;
  86 import org.testng.annotations.Test;
  87 
  88 /**
  89  * Test.
  90  */
  91 @Test
  92 public class TestThaiBuddhistChronology {
  93 
  94     private static final int YDIFF = 543;
  95 
  96     //-----------------------------------------------------------------------
  97     // Chronology.of(String)
  98     //-----------------------------------------------------------------------
  99     @Test
 100     public void test_chrono_byName() {
 101         Chronology c = ThaiBuddhistChronology.INSTANCE;
 102         Chronology test = Chronology.of("ThaiBuddhist");
 103         Assert.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName");
 104         Assert.assertEquals(test.getId(), "ThaiBuddhist", "ID mismatch");
 105         Assert.assertEquals(test.getCalendarType(), "buddhist", "Type mismatch");
 106         Assert.assertEquals(test, c);
 107     }
 108 
 109     //-----------------------------------------------------------------------
 110     // Chronology.ofLocale(Locale)
 111     //-----------------------------------------------------------------------
 112     @Test
 113     public void test_chrono_byLocale_fullTag_thaiCalendarFromThai() {
 114         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("th-TH-u-ca-buddhist"));
 115         Assert.assertEquals(test.getId(), "ThaiBuddhist");
 116         Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
 117     }
 118 
 119     @Test
 120     public void test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere() {
 121         Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-buddhist"));
 122         Assert.assertEquals(test.getId(), "ThaiBuddhist");
 123         Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
 124     }
 125 
 126     @Test
 127     public void test_chrono_byLocale_oldTH_noVariant() {  // deliberately different to Calendar
 128         Chronology test = Chronology.ofLocale(new Locale("th", "TH"));
 129         Assert.assertEquals(test.getId(), "ISO");
 130         Assert.assertEquals(test, IsoChronology.INSTANCE);
 131     }
 132 
 133     @Test
 134     public void test_chrono_byLocale_oldTH_variant() {
 135         Chronology test = Chronology.ofLocale(new Locale("th", "TH", "TH"));
 136         Assert.assertEquals(test.getId(), "ISO");
 137         Assert.assertEquals(test, IsoChronology.INSTANCE);
 138     }
 139 
 140     @Test
 141     public void test_chrono_byLocale_iso() {
 142         Assert.assertEquals(Chronology.ofLocale(new Locale("th", "TH")).getId(), "ISO");
 143         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH")).getId(), "ISO");
 144         Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH-TH")).getId(), "ISO");
 145     }
 146 
 147     //-----------------------------------------------------------------------
 148     // creation, toLocalDate()
 149     //-----------------------------------------------------------------------
 150     @DataProvider(name="samples")
 151     Object[][] data_samples() {
 152         return new Object[][] {
 153             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)},
 154             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 2), LocalDate.of(1, 1, 2)},
 155             {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 3), LocalDate.of(1, 1, 3)},
 156 
 157             {ThaiBuddhistChronology.INSTANCE.date(2 + YDIFF, 1, 1), LocalDate.of(2, 1, 1)},
 158             {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 1, 1), LocalDate.of(3, 1, 1)},
 159             {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 12, 6), LocalDate.of(3, 12, 6)},
 160             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 1, 1), LocalDate.of(4, 1, 1)},
 161             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 3), LocalDate.of(4, 7, 3)},
 162             {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 4), LocalDate.of(4, 7, 4)},
 163             {ThaiBuddhistChronology.INSTANCE.date(5 + YDIFF, 1, 1), LocalDate.of(5, 1, 1)},
 164             {ThaiBuddhistChronology.INSTANCE.date(1662 + YDIFF, 3, 3), LocalDate.of(1662, 3, 3)},
 165             {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 28), LocalDate.of(1728, 10, 28)},
 166             {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 29), LocalDate.of(1728, 10, 29)},
 167             {ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), LocalDate.of(2012, 8, 29)},
 168 
 169             {ThaiBuddhistChronology.INSTANCE.dateYearDay(4 + YDIFF, 60), LocalDate.of(4, 2, 29)},
 170             {ThaiBuddhistChronology.INSTANCE.dateYearDay(400 + YDIFF, 60), LocalDate.of(400, 2, 29)},
 171             {ThaiBuddhistChronology.INSTANCE.dateYearDay(2000 + YDIFF, 60), LocalDate.of(2000, 2, 29)},
 172 
 173         };
 174     }
 175 
 176     @Test(dataProvider="samples", groups={"tck"})
 177     public void test_toLocalDate(ThaiBuddhistDate jdate, LocalDate iso) {
 178         assertEquals(LocalDate.from(jdate), iso);
 179     }
 180 
 181     @Test(dataProvider="samples", groups={"tck"})
 182     public void test_fromCalendrical(ThaiBuddhistDate jdate, LocalDate iso) {
 183         assertEquals(ThaiBuddhistChronology.INSTANCE.date(iso), jdate);
 184     }
 185 
 186     @DataProvider(name="badDates")
 187     Object[][] data_badDates() {
 188         return new Object[][] {
 189             {1728, 0, 0},
 190 
 191             {1728, -1, 1},
 192             {1728, 0, 1},
 193             {1728, 14, 1},
 194             {1728, 15, 1},
 195 
 196             {1728, 1, -1},
 197             {1728, 1, 0},
 198             {1728, 1, 32},
 199 
 200             {1728, 12, -1},
 201             {1728, 12, 0},
 202             {1728, 12, 32},
 203 
 204             {3 + YDIFF, 2, 29},
 205             {600 + YDIFF, 2, 29},
 206             {1501 + YDIFF, 2, 29},
 207         };
 208     }
 209 
 210     @Test(dataProvider="badDates", groups={"tck"}, expectedExceptions=DateTimeException.class)
 211     public void test_badDates(int year, int month, int dom) {
 212         ThaiBuddhistChronology.INSTANCE.date(year, month, dom);
 213     }
 214 
 215   //-----------------------------------------------------------------------
 216   // prolepticYear() and is LeapYear()
 217   //-----------------------------------------------------------------------
 218   @DataProvider(name="prolepticYear")
 219   Object[][] data_prolepticYear() {
 220       return new Object[][] {
 221           {1, ThaiBuddhistChronology.ERA_BE, 4 + YDIFF, 4 + YDIFF, true},
 222           {1, ThaiBuddhistChronology.ERA_BE, 7 + YDIFF, 7 + YDIFF, false},
 223           {1, ThaiBuddhistChronology.ERA_BE, 8 + YDIFF, 8 + YDIFF, true},
 224           {1, ThaiBuddhistChronology.ERA_BE, 1000 + YDIFF, 1000 + YDIFF, false},
 225           {1, ThaiBuddhistChronology.ERA_BE, 2000 + YDIFF, 2000 + YDIFF, true},
 226           {1, ThaiBuddhistChronology.ERA_BE, 0, 0, false},
 227           {1, ThaiBuddhistChronology.ERA_BE, -4 + YDIFF, -4 + YDIFF, true},
 228           {1, ThaiBuddhistChronology.ERA_BE, -7 + YDIFF, -7 + YDIFF, false},
 229           {1, ThaiBuddhistChronology.ERA_BE, -100 + YDIFF, -100 + YDIFF, false},
 230           {1, ThaiBuddhistChronology.ERA_BE, -800 + YDIFF, -800 + YDIFF, true},
 231 
 232           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, -3 - YDIFF, 4 + YDIFF, true},
 233           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, -6 - YDIFF, 7 + YDIFF, false},
 234           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, -7 - YDIFF, 8 + YDIFF, true},
 235           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, -999 - YDIFF, 1000 + YDIFF, false},
 236           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, -1999 - YDIFF, 2000 + YDIFF, true},
 237           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, 1, 0, false},
 238           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, 5 - YDIFF, -4 + YDIFF, true},
 239           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, 8 - YDIFF, -7 + YDIFF, false},
 240           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, 101 - YDIFF, -100 + YDIFF, false},
 241           {0, ThaiBuddhistChronology.ERA_BEFORE_BE, 801 - YDIFF, -800 + YDIFF, true},
 242 
 243       };
 244   }
 245 
 246   @Test(dataProvider="prolepticYear", groups={"tck"})
 247   public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
 248       Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue) ;
 249       assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
 250       assertEquals(eraObj, era);
 251       assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
 252       assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
 253       assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap()) ;
 254   }
 255 
 256     //-----------------------------------------------------------------------
 257     // with(WithAdjuster)
 258     //-----------------------------------------------------------------------
 259     @Test(groups={"tck"})
 260     public void test_adjust1() {
 261         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 10, 29);
 262         ThaiBuddhistDate test = base.with(Adjusters.lastDayOfMonth());
 263         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31));
 264     }
 265 
 266     @Test(groups={"tck"})
 267     public void test_adjust2() {
 268         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 12, 2);
 269         ThaiBuddhistDate test = base.with(Adjusters.lastDayOfMonth());
 270         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31));
 271     }
 272 
 273     //-----------------------------------------------------------------------
 274     // withYear()
 275     //-----------------------------------------------------------------------
 276     @Test(groups={"tck"})
 277     public void test_withYear_BE() {
 278         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
 279         ThaiBuddhistDate test = base.with(YEAR, 2554);
 280         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2554, 8, 29));
 281     }
 282 
 283     @Test(groups={"tck"})
 284     public void test_withYear_BBE() {
 285         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
 286         ThaiBuddhistDate test = base.with(YEAR_OF_ERA, 2554);
 287         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2553, 8, 29));
 288     }
 289 
 290     //-----------------------------------------------------------------------
 291     // withEra()
 292     //-----------------------------------------------------------------------
 293     @Test(groups={"tck"})
 294     public void test_withEra_BE() {
 295         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
 296         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistChronology.ERA_BE.getValue());
 297         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
 298     }
 299 
 300     @Test(groups={"tck"})
 301     public void test_withEra_BBE() {
 302         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
 303         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistChronology.ERA_BEFORE_BE.getValue());
 304         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29));
 305     }
 306 
 307     @Test(groups={"tck"})
 308     public void test_withEra_swap() {
 309         ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
 310         ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistChronology.ERA_BE.getValue());
 311         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
 312     }
 313 
 314     //-----------------------------------------------------------------------
 315     // BuddhistDate.with(Local*)
 316     //-----------------------------------------------------------------------
 317     @Test(groups={"tck"})
 318     public void test_adjust_toLocalDate() {
 319         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
 320         ThaiBuddhistDate test = jdate.with(LocalDate.of(2012, 7, 6));
 321         assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 7, 6));
 322     }
 323 
 324     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
 325     public void test_adjust_toMonth() {
 326         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
 327         jdate.with(Month.APRIL);
 328     }
 329 
 330     //-----------------------------------------------------------------------
 331     // LocalDate.with(BuddhistDate)
 332     //-----------------------------------------------------------------------
 333     @Test(groups={"tck"})
 334     public void test_LocalDate_adjustToBuddhistDate() {
 335         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
 336         LocalDate test = LocalDate.MIN.with(jdate);
 337         assertEquals(test, LocalDate.of(2012, 10, 29));
 338     }
 339 
 340     @Test(groups={"tck"})
 341     public void test_LocalDateTime_adjustToBuddhistDate() {
 342         ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
 343         LocalDateTime test = LocalDateTime.MIN.with(jdate);
 344         assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
 345     }
 346 
 347     //-----------------------------------------------------------------------
 348     // toString()
 349     //-----------------------------------------------------------------------
 350     @DataProvider(name="toString")
 351     Object[][] data_toString() {
 352         return new Object[][] {
 353             {ThaiBuddhistChronology.INSTANCE.date(544, 1, 1), "ThaiBuddhist BE 544-01-01"},
 354             {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 28), "ThaiBuddhist BE 2271-10-28"},
 355             {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 29), "ThaiBuddhist BE 2271-10-29"},
 356             {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 5), "ThaiBuddhist BE 2270-12-05"},
 357             {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 6), "ThaiBuddhist BE 2270-12-06"},
 358         };
 359     }
 360 
 361     @Test(dataProvider="toString", groups={"tck"})
 362     public void test_toString(ThaiBuddhistDate jdate, String expected) {
 363         assertEquals(jdate.toString(), expected);
 364     }
 365 
 366     //-----------------------------------------------------------------------
 367     // chronology range(ChronoField)
 368     //-----------------------------------------------------------------------
 369     @Test(groups={"tck"})
 370     public void test_Chrono_range() {
 371         long minYear = LocalDate.MIN.getYear() + YDIFF;
 372         long maxYear = LocalDate.MAX.getYear() + YDIFF;
 373         assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR), ValueRange.of(minYear, maxYear));
 374         assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, -minYear + 1, maxYear));
 375 
 376         assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_MONTH), DAY_OF_MONTH.range());
 377         assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_YEAR), DAY_OF_YEAR.range());
 378         assertEquals(ThaiBuddhistChronology.INSTANCE.range(MONTH_OF_YEAR), MONTH_OF_YEAR.range());
 379     }
 380 
 381     //-----------------------------------------------------------------------
 382     // equals()
 383     //-----------------------------------------------------------------------
 384     @Test(groups="tck")
 385     public void test_equals_true() {
 386         assertTrue(ThaiBuddhistChronology.INSTANCE.equals(ThaiBuddhistChronology.INSTANCE));
 387     }
 388 
 389     @Test(groups="tck")
 390     public void test_equals_false() {
 391         assertFalse(ThaiBuddhistChronology.INSTANCE.equals(IsoChronology.INSTANCE));
 392     }
 393 
 394 }