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.assertTrue; 67 import static org.testng.Assert.fail; 68 69 import java.time.Clock; 70 import java.time.DateTimeException; 71 import java.time.LocalDate; 72 import java.time.LocalDateTime; 73 import java.time.Month; 74 import java.time.Period; 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.Chronology; 80 import java.time.chrono.Era; 81 import java.time.chrono.IsoChronology; 82 import java.time.chrono.MinguoChronology; 83 import java.time.chrono.MinguoDate; 84 import java.time.chrono.ThaiBuddhistChronology; 85 import java.time.chrono.ThaiBuddhistDate; 86 import java.time.chrono.ThaiBuddhistEra; 87 import java.time.temporal.ChronoField; 88 import java.time.temporal.ChronoUnit; 89 import java.time.temporal.TemporalAdjuster; 90 import java.time.temporal.ValueRange; 91 import java.util.List; 92 import java.util.Locale; 93 94 import org.testng.Assert; 95 import org.testng.annotations.DataProvider; 96 import org.testng.annotations.Test; 97 98 /** 99 * Test. 100 */ 101 @Test 102 public class TCKThaiBuddhistChronology { 103 104 private static final int YDIFF = 543; 105 106 //----------------------------------------------------------------------- 107 // Chronology.of(String) 108 //----------------------------------------------------------------------- 109 @Test 110 public void test_chrono_byName() { 111 Chronology c = ThaiBuddhistChronology.INSTANCE; 112 Chronology test = Chronology.of("ThaiBuddhist"); 113 Assert.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName"); 114 Assert.assertEquals(test.getId(), "ThaiBuddhist", "ID mismatch"); 115 Assert.assertEquals(test.getCalendarType(), "buddhist", "Type mismatch"); 116 Assert.assertEquals(test, c); 117 } 118 119 //----------------------------------------------------------------------- 120 // Chronology.ofLocale(Locale) 121 //----------------------------------------------------------------------- 122 @Test 123 public void test_chrono_byLocale_fullTag_thaiCalendarFromThai() { 124 Chronology test = Chronology.ofLocale(Locale.forLanguageTag("th-TH-u-ca-buddhist")); 125 Assert.assertEquals(test.getId(), "ThaiBuddhist"); 126 Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE); 127 } 128 129 @Test 130 public void test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere() { 131 Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-buddhist")); 132 Assert.assertEquals(test.getId(), "ThaiBuddhist"); 133 Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE); 134 } 135 136 @Test 137 public void test_chrono_byLocale_oldTH_noVariant() { // deliberately different to Calendar 138 Chronology test = Chronology.ofLocale(new Locale("th", "TH")); 139 Assert.assertEquals(test.getId(), "ISO"); 140 Assert.assertEquals(test, IsoChronology.INSTANCE); 141 } 142 143 @Test 144 public void test_chrono_byLocale_oldTH_variant() { 145 Chronology test = Chronology.ofLocale(new Locale("th", "TH", "TH")); 146 Assert.assertEquals(test.getId(), "ISO"); 147 Assert.assertEquals(test, IsoChronology.INSTANCE); 148 } 149 150 @Test 151 public void test_chrono_byLocale_iso() { 152 Assert.assertEquals(Chronology.ofLocale(new Locale("th", "TH")).getId(), "ISO"); 153 Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH")).getId(), "ISO"); 154 Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH-TH")).getId(), "ISO"); 155 } 156 157 //----------------------------------------------------------------------- 158 // creation, toLocalDate() 159 //----------------------------------------------------------------------- 160 @DataProvider(name="samples") 161 Object[][] data_samples() { 162 return new Object[][] { 163 {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)}, 164 {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 2), LocalDate.of(1, 1, 2)}, 165 {ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 3), LocalDate.of(1, 1, 3)}, 166 167 {ThaiBuddhistChronology.INSTANCE.date(2 + YDIFF, 1, 1), LocalDate.of(2, 1, 1)}, 168 {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 1, 1), LocalDate.of(3, 1, 1)}, 169 {ThaiBuddhistChronology.INSTANCE.date(3 + YDIFF, 12, 6), LocalDate.of(3, 12, 6)}, 170 {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 1, 1), LocalDate.of(4, 1, 1)}, 171 {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 3), LocalDate.of(4, 7, 3)}, 172 {ThaiBuddhistChronology.INSTANCE.date(4 + YDIFF, 7, 4), LocalDate.of(4, 7, 4)}, 173 {ThaiBuddhistChronology.INSTANCE.date(5 + YDIFF, 1, 1), LocalDate.of(5, 1, 1)}, 174 {ThaiBuddhistChronology.INSTANCE.date(1662 + YDIFF, 3, 3), LocalDate.of(1662, 3, 3)}, 175 {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 28), LocalDate.of(1728, 10, 28)}, 176 {ThaiBuddhistChronology.INSTANCE.date(1728 + YDIFF, 10, 29), LocalDate.of(1728, 10, 29)}, 177 {ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), LocalDate.of(2012, 8, 29)}, 178 179 {ThaiBuddhistChronology.INSTANCE.dateYearDay(4 + YDIFF, 60), LocalDate.of(4, 2, 29)}, 180 {ThaiBuddhistChronology.INSTANCE.dateYearDay(400 + YDIFF, 60), LocalDate.of(400, 2, 29)}, 181 {ThaiBuddhistChronology.INSTANCE.dateYearDay(2000 + YDIFF, 60), LocalDate.of(2000, 2, 29)}, 182 183 {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 1916 + YDIFF, 60), LocalDate.of(1916, 2, 29)}, 184 {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BEFORE_BE, -1907 - YDIFF, 60), LocalDate.of(1908, 2, 29)}, 185 {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2000 + YDIFF, 60), LocalDate.of(2000, 2, 29)}, 186 {ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2400 + YDIFF, 60), LocalDate.of(2400, 2, 29)}, 187 188 {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 1916 + YDIFF, 2, 29 ), LocalDate.of(1916, 2, 29)}, 189 {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BEFORE_BE, -1907 - YDIFF, 2, 29), LocalDate.of(1908, 2, 29)}, 190 {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2000 + YDIFF, 2, 29), LocalDate.of(2000, 2, 29)}, 191 {ThaiBuddhistChronology.INSTANCE.date(ThaiBuddhistEra.BE, 2400 + YDIFF, 2, 29), LocalDate.of(2400, 2, 29)}, 192 }; 193 } 194 195 @Test(dataProvider="samples") 196 public void test_toLocalDate(ThaiBuddhistDate jdate, LocalDate iso) { 197 assertEquals(LocalDate.from(jdate), iso); 198 } 199 200 @Test(dataProvider="samples") 201 public void test_fromCalendrical(ThaiBuddhistDate jdate, LocalDate iso) { 202 assertEquals(ThaiBuddhistChronology.INSTANCE.date(iso), jdate); 203 } 204 205 @Test 206 public void test_dateNow(){ 207 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now()) ; 208 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(ZoneId.systemDefault())) ; 209 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone())) ; 210 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone().getZone())) ; 211 212 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ; 213 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ; 214 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ; 215 216 ZoneId zoneId = ZoneId.of("Europe/Paris"); 217 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId))) ; 218 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ; 219 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId))) ; 220 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId).getZone())) ; 221 222 assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemUTC())) ; 223 } 224 225 @DataProvider(name="badDates") 226 Object[][] data_badDates() { 227 return new Object[][] { 228 {1728, 0, 0}, 229 230 {1728, -1, 1}, 231 {1728, 0, 1}, 232 {1728, 14, 1}, 233 {1728, 15, 1}, 234 235 {1728, 1, -1}, 236 {1728, 1, 0}, 237 {1728, 1, 32}, 238 239 {1728, 12, -1}, 240 {1728, 12, 0}, 241 {1728, 12, 32}, 242 243 {3 + YDIFF, 2, 29}, 244 {600 + YDIFF, 2, 29}, 245 {1501 + YDIFF, 2, 29}, 246 }; 247 } 248 249 @Test(dataProvider="badDates", expectedExceptions=DateTimeException.class) 250 public void test_badDates(int year, int month, int dom) { 251 ThaiBuddhistChronology.INSTANCE.date(year, month, dom); 252 } 253 254 //----------------------------------------------------------------------- 255 // prolepticYear() and is LeapYear() 256 //----------------------------------------------------------------------- 257 @DataProvider(name="prolepticYear") 258 Object[][] data_prolepticYear() { 259 return new Object[][] { 260 {1, ThaiBuddhistEra.BE, 4 + YDIFF, 4 + YDIFF, true}, 261 {1, ThaiBuddhistEra.BE, 7 + YDIFF, 7 + YDIFF, false}, 262 {1, ThaiBuddhistEra.BE, 8 + YDIFF, 8 + YDIFF, true}, 263 {1, ThaiBuddhistEra.BE, 1000 + YDIFF, 1000 + YDIFF, false}, 264 {1, ThaiBuddhistEra.BE, 2000 + YDIFF, 2000 + YDIFF, true}, 265 {1, ThaiBuddhistEra.BE, 0, 0, false}, 266 {1, ThaiBuddhistEra.BE, -4 + YDIFF, -4 + YDIFF, true}, 267 {1, ThaiBuddhistEra.BE, -7 + YDIFF, -7 + YDIFF, false}, 268 {1, ThaiBuddhistEra.BE, -100 + YDIFF, -100 + YDIFF, false}, 269 {1, ThaiBuddhistEra.BE, -800 + YDIFF, -800 + YDIFF, true}, 270 271 {0, ThaiBuddhistEra.BEFORE_BE, -3 - YDIFF, 4 + YDIFF, true}, 272 {0, ThaiBuddhistEra.BEFORE_BE, -6 - YDIFF, 7 + YDIFF, false}, 273 {0, ThaiBuddhistEra.BEFORE_BE, -7 - YDIFF, 8 + YDIFF, true}, 274 {0, ThaiBuddhistEra.BEFORE_BE, -999 - YDIFF, 1000 + YDIFF, false}, 275 {0, ThaiBuddhistEra.BEFORE_BE, -1999 - YDIFF, 2000 + YDIFF, true}, 276 {0, ThaiBuddhistEra.BEFORE_BE, 1, 0, false}, 277 {0, ThaiBuddhistEra.BEFORE_BE, 5 - YDIFF, -4 + YDIFF, true}, 278 {0, ThaiBuddhistEra.BEFORE_BE, 8 - YDIFF, -7 + YDIFF, false}, 279 {0, ThaiBuddhistEra.BEFORE_BE, 101 - YDIFF, -100 + YDIFF, false}, 280 {0, ThaiBuddhistEra.BEFORE_BE, 801 - YDIFF, -800 + YDIFF, true}, 281 282 }; 283 } 284 285 @Test(dataProvider="prolepticYear") 286 public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) { 287 Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue) ; 288 assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj)); 289 assertEquals(eraObj, era); 290 assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear); 291 assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ; 292 assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap()) ; 293 } 294 295 //----------------------------------------------------------------------- 296 // Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...) 297 //----------------------------------------------------------------------- 298 @Test 299 public void test_InvalidEras() { 300 // Verify that the eras from every other Chronology are invalid 301 for (Chronology chrono : Chronology.getAvailableChronologies()) { 302 if (chrono instanceof ThaiBuddhistChronology) { 303 continue; 304 } 305 List<Era> eras = chrono.eras(); 306 for (Era era : eras) { 307 try { 308 ChronoLocalDate date = ThaiBuddhistChronology.INSTANCE.date(era, 1, 1, 1); 309 fail("ThaiBuddhistChronology.date did not throw ClassCastException for Era: " + era); 310 } catch (ClassCastException cex) { 311 ; // ignore expected exception 312 } 313 314 /* TODO: Test for missing ThaiBuddhistDate.of(Era, y, m, d) method. 315 try { 316 @SuppressWarnings("unused") 317 ThaiBuddhistDate jdate = ThaiBuddhistDate.of(era, 1, 1, 1); 318 fail("ThaiBuddhistDate.of did not throw ClassCastException for Era: " + era); 319 } catch (ClassCastException cex) { 320 ; // ignore expected exception 321 } 322 */ 323 324 try { 325 @SuppressWarnings("unused") 326 int year = ThaiBuddhistChronology.INSTANCE.prolepticYear(era, 1); 327 fail("ThaiBuddhistChronology.prolepticYear did not throw ClassCastException for Era: " + era); 328 } catch (ClassCastException cex) { 329 ; // ignore expected exception 330 } } 331 } 332 } 333 334 //----------------------------------------------------------------------- 335 // with(WithAdjuster) 336 //----------------------------------------------------------------------- 337 @Test 338 public void test_adjust1() { 339 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 10, 29); 340 ThaiBuddhistDate test = base.with(TemporalAdjuster.lastDayOfMonth()); 341 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31)); 342 } 343 344 @Test 345 public void test_adjust2() { 346 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 12, 2); 347 ThaiBuddhistDate test = base.with(TemporalAdjuster.lastDayOfMonth()); 348 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31)); 349 } 350 351 //----------------------------------------------------------------------- 352 // withYear() 353 //----------------------------------------------------------------------- 354 @Test 355 public void test_withYear_BE() { 356 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29); 357 ThaiBuddhistDate test = base.with(YEAR, 2554); 358 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2554, 8, 29)); 359 } 360 361 @Test 362 public void test_withYear_BBE() { 363 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29); 364 ThaiBuddhistDate test = base.with(YEAR_OF_ERA, 2554); 365 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2553, 8, 29)); 366 } 367 368 //----------------------------------------------------------------------- 369 // withEra() 370 //----------------------------------------------------------------------- 371 @Test 372 public void test_withEra_BE() { 373 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29); 374 ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue()); 375 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29)); 376 } 377 378 @Test 379 public void test_withEra_BBE() { 380 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29); 381 ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BEFORE_BE.getValue()); 382 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29)); 383 } 384 385 @Test 386 public void test_withEra_swap() { 387 ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29); 388 ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue()); 389 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29)); 390 } 391 392 //----------------------------------------------------------------------- 393 // BuddhistDate.with(Local*) 394 //----------------------------------------------------------------------- 395 @Test 396 public void test_adjust_toLocalDate() { 397 ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4); 398 ThaiBuddhistDate test = jdate.with(LocalDate.of(2012, 7, 6)); 399 assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 7, 6)); 400 } 401 402 @Test(expectedExceptions=DateTimeException.class) 403 public void test_adjust_toMonth() { 404 ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4); 405 jdate.with(Month.APRIL); 406 } 407 408 //----------------------------------------------------------------------- 409 // LocalDate.with(BuddhistDate) 410 //----------------------------------------------------------------------- 411 @Test 412 public void test_LocalDate_adjustToBuddhistDate() { 413 ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29); 414 LocalDate test = LocalDate.MIN.with(jdate); 415 assertEquals(test, LocalDate.of(2012, 10, 29)); 416 } 417 418 @Test 419 public void test_LocalDateTime_adjustToBuddhistDate() { 420 ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29); 421 LocalDateTime test = LocalDateTime.MIN.with(jdate); 422 assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0)); 423 } 424 425 //----------------------------------------------------------------------- 426 // PeriodUntil() 427 //----------------------------------------------------------------------- 428 @Test 429 public void test_periodUntilDate() { 430 ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1); 431 ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2); 432 Period period = mdate1.periodUntil(mdate2); 433 assertEquals(period, Period.of(1, 1, 1)); 434 } 435 436 @Test 437 public void test_periodUntilUnit() { 438 ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1); 439 ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2); 440 long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS); 441 assertEquals(months, 13); 442 } 443 444 @Test 445 public void test_periodUntilDiffChrono() { 446 ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1); 447 ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2); 448 MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2); 449 Period period = mdate1.periodUntil(ldate2); 450 assertEquals(period, Period.of(1, 1, 1)); 451 } 452 453 //----------------------------------------------------------------------- 454 // toString() 455 //----------------------------------------------------------------------- 456 @DataProvider(name="toString") 457 Object[][] data_toString() { 458 return new Object[][] { 459 {ThaiBuddhistChronology.INSTANCE.date(544, 1, 1), "ThaiBuddhist BE 544-01-01"}, 460 {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 28), "ThaiBuddhist BE 2271-10-28"}, 461 {ThaiBuddhistChronology.INSTANCE.date(2271, 10, 29), "ThaiBuddhist BE 2271-10-29"}, 462 {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 5), "ThaiBuddhist BE 2270-12-05"}, 463 {ThaiBuddhistChronology.INSTANCE.date(2270, 12, 6), "ThaiBuddhist BE 2270-12-06"}, 464 }; 465 } 466 467 @Test(dataProvider="toString") 468 public void test_toString(ThaiBuddhistDate jdate, String expected) { 469 assertEquals(jdate.toString(), expected); 470 } 471 472 //----------------------------------------------------------------------- 473 // chronology range(ChronoField) 474 //----------------------------------------------------------------------- 475 @Test 476 public void test_Chrono_range() { 477 long minYear = LocalDate.MIN.getYear() + YDIFF; 478 long maxYear = LocalDate.MAX.getYear() + YDIFF; 479 assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR), ValueRange.of(minYear, maxYear)); 480 assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, -minYear + 1, maxYear)); 481 482 assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_MONTH), DAY_OF_MONTH.range()); 483 assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_YEAR), DAY_OF_YEAR.range()); 484 assertEquals(ThaiBuddhistChronology.INSTANCE.range(MONTH_OF_YEAR), MONTH_OF_YEAR.range()); 485 } 486 487 //----------------------------------------------------------------------- 488 // equals() 489 //----------------------------------------------------------------------- 490 @Test 491 public void test_equals_true() { 492 assertTrue(ThaiBuddhistChronology.INSTANCE.equals(ThaiBuddhistChronology.INSTANCE)); 493 } 494 495 @Test 496 public void test_equals_false() { 497 assertFalse(ThaiBuddhistChronology.INSTANCE.equals(IsoChronology.INSTANCE)); 498 } 499 500 }