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.ERA; 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.DateTimeException; 70 import java.time.LocalDate; 71 import java.time.LocalDateTime; 72 import java.time.Month; 73 import java.time.Period; 74 import java.time.Year; 75 import java.time.chrono.ChronoLocalDate; 76 import java.time.chrono.Chronology; 77 import java.time.chrono.Era; 78 import java.time.chrono.IsoChronology; 79 import java.time.chrono.JapaneseChronology; 80 import java.time.chrono.JapaneseDate; 81 import java.time.chrono.JapaneseEra; 82 import java.time.chrono.MinguoChronology; 83 import java.time.chrono.MinguoDate; 84 import java.time.temporal.ChronoUnit; 85 import java.time.temporal.TemporalAdjuster; 86 import java.util.List; 87 import java.util.Locale; 88 89 import org.testng.Assert; 90 import org.testng.annotations.DataProvider; 91 import org.testng.annotations.Test; 92 93 /** 94 * Test. 95 */ 96 @Test 97 public class TCKJapaneseChronology { 98 private static final int YDIFF_HEISEI = 1988; 99 private static final int YDIFF_MEIJI = 1867; 100 private static final int YDIFF_SHOWA = 1925; 101 private static final int YDIFF_TAISHO = 1911; 102 103 //----------------------------------------------------------------------- 104 // Chronology.of(String) 105 //----------------------------------------------------------------------- 106 @Test 107 public void test_chrono_byName() { 108 Chronology c = JapaneseChronology.INSTANCE; 109 Chronology test = Chronology.of("Japanese"); 110 Assert.assertNotNull(test, "The Japanese calendar could not be found byName"); 111 Assert.assertEquals(test.getId(), "Japanese", "ID mismatch"); 112 Assert.assertEquals(test.getCalendarType(), "japanese", "Type mismatch"); 113 Assert.assertEquals(test, c); 114 } 115 116 //----------------------------------------------------------------------- 117 // Chronology.ofLocale(Locale) 118 //----------------------------------------------------------------------- 119 @Test 120 public void test_chrono_byLocale_fullTag_japaneseCalendarFromJapan() { 121 Chronology test = Chronology.ofLocale(Locale.forLanguageTag("ja-JP-u-ca-japanese")); 122 Assert.assertEquals(test.getId(), "Japanese"); 123 Assert.assertEquals(test, JapaneseChronology.INSTANCE); 124 } 125 126 @Test 127 public void test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere() { 128 Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-japanese")); 129 Assert.assertEquals(test.getId(), "Japanese"); 130 Assert.assertEquals(test, JapaneseChronology.INSTANCE); 131 } 132 133 @Test 134 public void test_chrono_byLocale_oldJP_noVariant() { 135 Chronology test = Chronology.ofLocale(new Locale("ja", "JP")); 136 Assert.assertEquals(test.getId(), "ISO"); 137 Assert.assertEquals(test, IsoChronology.INSTANCE); 138 } 139 140 @Test 141 public void test_chrono_byLocale_oldJP_variant() { 142 Chronology test = Chronology.ofLocale(new Locale("ja", "JP", "JP")); 143 Assert.assertEquals(test.getId(), "Japanese"); 144 Assert.assertEquals(test, JapaneseChronology.INSTANCE); 145 } 146 147 @Test 148 public void test_chrono_byLocale_iso() { 149 Assert.assertEquals(Chronology.ofLocale(new Locale("ja", "JP")).getId(), "ISO"); 150 Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId(), "ISO"); 151 Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId(), "ISO"); 152 } 153 154 //----------------------------------------------------------------------- 155 // creation, toLocalDate() 156 //----------------------------------------------------------------------- 157 @DataProvider(name="samples") 158 Object[][] data_samples() { 159 return new Object[][] { 160 {JapaneseChronology.INSTANCE.date(1, 1, 1), LocalDate.of(1, 1, 1)}, 161 {JapaneseChronology.INSTANCE.date(1, 1, 2), LocalDate.of(1, 1, 2)}, 162 {JapaneseChronology.INSTANCE.date(1, 1, 3), LocalDate.of(1, 1, 3)}, 163 164 {JapaneseChronology.INSTANCE.date(2, 1, 1), LocalDate.of(2, 1, 1)}, 165 {JapaneseChronology.INSTANCE.date(3, 1, 1), LocalDate.of(3, 1, 1)}, 166 {JapaneseChronology.INSTANCE.date(3, 12, 6), LocalDate.of(3, 12, 6)}, 167 {JapaneseChronology.INSTANCE.date(4, 1, 1), LocalDate.of(4, 1, 1)}, 168 {JapaneseChronology.INSTANCE.date(4, 7, 3), LocalDate.of(4, 7, 3)}, 169 {JapaneseChronology.INSTANCE.date(4, 7, 4), LocalDate.of(4, 7, 4)}, 170 {JapaneseChronology.INSTANCE.date(5, 1, 1), LocalDate.of(5, 1, 1)}, 171 {JapaneseChronology.INSTANCE.date(1662, 3, 3), LocalDate.of(1662, 3, 3)}, 172 {JapaneseChronology.INSTANCE.date(1728, 10, 28), LocalDate.of(1728, 10, 28)}, 173 {JapaneseChronology.INSTANCE.date(1728, 10, 29), LocalDate.of(1728, 10, 29)}, 174 175 {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29), LocalDate.of(1996, 2, 29)}, 176 {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29), LocalDate.of(2000, 2, 29)}, 177 {JapaneseChronology.INSTANCE.date(JapaneseEra.MEIJI, 1868 - YDIFF_MEIJI, 2, 29), LocalDate.of(1868, 2, 29)}, 178 {JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 12, 25), LocalDate.of(1928, 12, 25)}, 179 {JapaneseChronology.INSTANCE.date(JapaneseEra.TAISHO, 1912 - YDIFF_TAISHO, 7, 30), LocalDate.of(1912, 7, 30)}, 180 181 {JapaneseChronology.INSTANCE.dateYearDay(1996, 60), LocalDate.of(1996, 2, 29)}, 182 {JapaneseChronology.INSTANCE.dateYearDay(1868, 60), LocalDate.of(1868, 2, 29)}, 183 {JapaneseChronology.INSTANCE.dateYearDay(1928, 60), LocalDate.of(1928, 2, 29)}, 184 {JapaneseChronology.INSTANCE.dateYearDay(1912, 60), LocalDate.of(1912, 2, 29)}, 185 }; 186 } 187 188 @Test(dataProvider="samples") 189 public void test_toLocalDate(JapaneseDate jdate, LocalDate iso) { 190 assertEquals(LocalDate.from(jdate), iso); 191 } 192 193 @Test(dataProvider="samples") 194 public void test_fromCalendrical(JapaneseDate jdate, LocalDate iso) { 195 assertEquals(JapaneseChronology.INSTANCE.date(iso), jdate); 196 } 197 198 @DataProvider(name="badDates") 199 Object[][] data_badDates() { 200 return new Object[][] { 201 {1728, 0, 0}, 202 203 {1728, -1, 1}, 204 {1728, 0, 1}, 205 {1728, 14, 1}, 206 {1728, 15, 1}, 207 208 {1728, 1, -1}, 209 {1728, 1, 0}, 210 {1728, 1, 32}, 211 212 {1728, 12, -1}, 213 {1728, 12, 0}, 214 {1728, 12, 32}, 215 216 {1725, 2, 29}, 217 {500, 2, 29}, 218 {2100, 2, 29}, 219 }; 220 } 221 222 @Test(dataProvider="badDates", expectedExceptions=DateTimeException.class) 223 public void test_badDates(int year, int month, int dom) { 224 JapaneseChronology.INSTANCE.date(year, month, dom); 225 } 226 227 //----------------------------------------------------------------------- 228 // prolepticYear() and is LeapYear() 229 //----------------------------------------------------------------------- 230 @DataProvider(name="prolepticYear") 231 Object[][] data_prolepticYear() { 232 return new Object[][] { 233 {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false}, 234 {2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true}, 235 {2, JapaneseEra.HEISEI, 0, YDIFF_HEISEI, true}, 236 {2, JapaneseEra.HEISEI, -10, -10 + YDIFF_HEISEI, false}, 237 238 {-1, JapaneseEra.MEIJI, 1, 1 + YDIFF_MEIJI, true}, 239 {-1, JapaneseEra.MEIJI, 4, 4 + YDIFF_MEIJI, false}, 240 241 {1, JapaneseEra.SHOWA, 1, 1 + YDIFF_SHOWA, false}, 242 {1, JapaneseEra.SHOWA, 7, 7 + YDIFF_SHOWA, true}, 243 244 {0, JapaneseEra.TAISHO, 1, 1 + YDIFF_TAISHO, true}, 245 {0, JapaneseEra.TAISHO, 4, 4 + YDIFF_TAISHO, false}, 246 }; 247 } 248 249 @Test(dataProvider="prolepticYear") 250 public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) { 251 Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue) ; 252 assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj)); 253 assertEquals(eraObj, era); 254 assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear); 255 assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ; 256 assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap()) ; 257 } 258 259 @DataProvider(name="prolepticYearError") 260 Object[][] data_prolepticYearError() { 261 return new Object[][] { 262 {JapaneseEra.MEIJI, 100}, 263 {JapaneseEra.MEIJI, 0}, 264 {JapaneseEra.MEIJI, -10}, 265 266 {JapaneseEra.SHOWA, 100}, 267 {JapaneseEra.SHOWA, 0}, 268 {JapaneseEra.SHOWA, -10}, 269 270 {JapaneseEra.TAISHO, 100}, 271 {JapaneseEra.TAISHO, 0}, 272 {JapaneseEra.TAISHO, -10}, 273 }; 274 } 275 276 @Test(dataProvider="prolepticYearError", expectedExceptions=DateTimeException.class) 277 public void test_prolepticYearError(Era era, int yearOfEra) { 278 JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra); 279 } 280 281 //----------------------------------------------------------------------- 282 // Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...) 283 //----------------------------------------------------------------------- 284 @Test 285 public void test_InvalidEras() { 286 // Verify that the eras from every other Chronology are invalid 287 for (Chronology chrono : Chronology.getAvailableChronologies()) { 288 if (chrono instanceof JapaneseChronology) { 289 continue; 290 } 291 List<Era> eras = chrono.eras(); 292 for (Era era : eras) { 293 try { 294 ChronoLocalDate date = JapaneseChronology.INSTANCE.date(era, 1, 1, 1); 295 fail("JapaneseChronology.date did not throw ClassCastException for Era: " + era); 296 } catch (ClassCastException cex) { 297 ; // ignore expected exception 298 } 299 300 try { 301 @SuppressWarnings("unused") 302 JapaneseDate jdate = JapaneseDate.of(era, 1, 1, 1); 303 fail("JapaneseDate.of did not throw ClassCastException for Era: " + era); 304 } catch (ClassCastException cex) { 305 ; // ignore expected exception 306 } 307 308 try { 309 @SuppressWarnings("unused") 310 int year = JapaneseChronology.INSTANCE.prolepticYear(era, 1); 311 fail("JapaneseChronology.prolepticYear did not throw ClassCastException for Era: " + era); 312 } catch (ClassCastException cex) { 313 ; // ignore expected exception 314 } 315 316 } 317 } 318 } 319 320 //----------------------------------------------------------------------- 321 // get(TemporalField) 322 //----------------------------------------------------------------------- 323 @Test 324 public void test_getLong() { 325 JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30); 326 assertEquals(base.getLong(ERA), JapaneseEra.SHOWA.getValue()); 327 assertEquals(base.getLong(YEAR), 1988L); 328 assertEquals(base.getLong(YEAR_OF_ERA), 63L); 329 assertEquals(base.getLong(MONTH_OF_YEAR), 6L); 330 assertEquals(base.getLong(DAY_OF_MONTH), 30L); 331 } 332 333 //----------------------------------------------------------------------- 334 // with(TemporalField, long) 335 //----------------------------------------------------------------------- 336 @Test 337 public void test_with_TemporalField_long() { 338 JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30); 339 JapaneseDate test = base.with(YEAR, 1987); 340 assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 62, 6, 30)); 341 342 test = test.with(YEAR_OF_ERA, 2); 343 assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 2, 6, 30)); 344 345 test = test.with(ERA, JapaneseEra.HEISEI.getValue()); 346 assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 6, 30)); 347 348 test = test.with(MONTH_OF_YEAR, 3); 349 assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 30)); 350 351 test = test.with(DAY_OF_MONTH, 4); 352 assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 4)); 353 } 354 355 //----------------------------------------------------------------------- 356 // with(WithAdjuster) 357 //----------------------------------------------------------------------- 358 @Test 359 public void test_adjust1() { 360 JapaneseDate base = JapaneseChronology.INSTANCE.date(1728, 10, 29); 361 JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth()); 362 assertEquals(test, JapaneseChronology.INSTANCE.date(1728, 10, 31)); 363 } 364 365 @Test 366 public void test_adjust2() { 367 JapaneseDate base = JapaneseChronology.INSTANCE.date(1728, 12, 2); 368 JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth()); 369 assertEquals(test, JapaneseChronology.INSTANCE.date(1728, 12, 31)); 370 } 371 372 //----------------------------------------------------------------------- 373 // JapaneseDate.with(Local*) 374 //----------------------------------------------------------------------- 375 @Test 376 public void test_adjust_toLocalDate() { 377 JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4); 378 JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6)); 379 assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6)); 380 } 381 382 @Test(expectedExceptions=DateTimeException.class) 383 public void test_adjust_toMonth() { 384 JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4); 385 jdate.with(Month.APRIL); 386 } 387 388 //----------------------------------------------------------------------- 389 // LocalDate.with(JapaneseDate) 390 //----------------------------------------------------------------------- 391 @Test 392 public void test_LocalDate_adjustToJapaneseDate() { 393 JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1728, 10, 29); 394 LocalDate test = LocalDate.MIN.with(jdate); 395 assertEquals(test, LocalDate.of(1728, 10, 29)); 396 } 397 398 @Test 399 public void test_LocalDateTime_adjustToJapaneseDate() { 400 JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1728, 10, 29); 401 LocalDateTime test = LocalDateTime.MIN.with(jdate); 402 assertEquals(test, LocalDateTime.of(1728, 10, 29, 0, 0)); 403 } 404 405 //----------------------------------------------------------------------- 406 // Check Japanese Eras 407 //----------------------------------------------------------------------- 408 @DataProvider(name="japaneseEras") 409 Object[][] data_japanseseEras() { 410 return new Object[][] { 411 { JapaneseEra.SEIREKI, -999, "Seireki"}, 412 { JapaneseEra.MEIJI, -1, "Meiji"}, 413 { JapaneseEra.TAISHO, 0, "Taisho"}, 414 { JapaneseEra.SHOWA, 1, "Showa"}, 415 { JapaneseEra.HEISEI, 2, "Heisei"}, 416 }; 417 } 418 419 @Test(dataProvider="japaneseEras") 420 public void test_Japanese_Eras(Era era, int eraValue, String name) { 421 assertEquals(era.getValue(), eraValue, "EraValue"); 422 assertEquals(era.toString(), name, "Era Name"); 423 assertEquals(era, JapaneseChronology.INSTANCE.eraOf(eraValue), "JapaneseChronology.eraOf()"); 424 List<Era> eras = JapaneseChronology.INSTANCE.eras(); 425 assertTrue(eras.contains(era), "Era is not present in JapaneseChronology.INSTANCE.eras()"); 426 } 427 428 @Test 429 public void test_Japanese_badEras() { 430 int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000}; 431 for (int badEra : badEras) { 432 try { 433 Era era = JapaneseChronology.INSTANCE.eraOf(badEra); 434 fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra); 435 } catch (DateTimeException ex) { 436 // ignore expected exception 437 } 438 } 439 } 440 441 @Test(dataProvider="japaneseEras") 442 public void test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name) { 443 JapaneseEra actualEra = JapaneseEra.valueOf(name); 444 assertEquals(actualEra, expectedEra, "JapaneseEra.valueOf(name)"); 445 446 actualEra = JapaneseEra.of(eraValue); 447 assertEquals(actualEra, expectedEra, "JapaneseEra.of(value)"); 448 449 String string = actualEra.toString(); 450 assertEquals(string, name, "JapaneseEra.toString()"); 451 } 452 453 @Test 454 public void test_JapaneseEra_values() { 455 JapaneseEra[] actualEras = JapaneseEra.values(); 456 Object[][] erasInfo = data_japanseseEras(); 457 assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras"); 458 459 for (int i = 0; i < erasInfo.length; i++) { 460 Object[] eraInfo = erasInfo[i]; 461 assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch"); 462 } 463 } 464 465 @Test 466 public void test_JapaneseChronology_eras() { 467 List<Era> actualEras = JapaneseChronology.INSTANCE.eras(); 468 Object[][] erasInfo = data_japanseseEras(); 469 assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras"); 470 471 for (int i = 0; i < erasInfo.length; i++) { 472 Object[] eraInfo = erasInfo[i]; 473 assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch"); 474 } 475 } 476 477 //----------------------------------------------------------------------- 478 // PeriodUntil() 479 //----------------------------------------------------------------------- 480 @Test 481 public void test_periodUntilDate() { 482 JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1); 483 JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2); 484 Period period = mdate1.periodUntil(mdate2); 485 assertEquals(period, Period.of(1, 1, 1)); 486 } 487 488 @Test 489 public void test_periodUntilUnit() { 490 JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1); 491 JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2); 492 long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS); 493 assertEquals(months, 13); 494 } 495 496 @Test 497 public void test_periodUntilDiffChrono() { 498 JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1); 499 JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2); 500 MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2); 501 Period period = mdate1.periodUntil(ldate2); 502 assertEquals(period, Period.of(1, 1, 1)); 503 } 504 505 //----------------------------------------------------------------------- 506 // toString() 507 //----------------------------------------------------------------------- 508 @DataProvider(name="toString") 509 Object[][] data_toString() { 510 return new Object[][] { 511 {JapaneseChronology.INSTANCE.date(0001, 1, 1), "Japanese 0001-01-01"}, 512 {JapaneseChronology.INSTANCE.date(1728, 10, 28), "Japanese 1728-10-28"}, 513 {JapaneseChronology.INSTANCE.date(1728, 10, 29), "Japanese 1728-10-29"}, 514 {JapaneseChronology.INSTANCE.date(1727, 12, 5), "Japanese 1727-12-05"}, 515 {JapaneseChronology.INSTANCE.date(1727, 12, 6), "Japanese 1727-12-06"}, 516 {JapaneseChronology.INSTANCE.date(1868, 9, 8), "Japanese Meiji 1-09-08"}, 517 {JapaneseChronology.INSTANCE.date(1912, 7, 29), "Japanese Meiji 45-07-29"}, 518 {JapaneseChronology.INSTANCE.date(1912, 7, 30), "Japanese Taisho 1-07-30"}, 519 {JapaneseChronology.INSTANCE.date(1926, 12, 24), "Japanese Taisho 15-12-24"}, 520 {JapaneseChronology.INSTANCE.date(1926, 12, 25), "Japanese Showa 1-12-25"}, 521 {JapaneseChronology.INSTANCE.date(1989, 1, 7), "Japanese Showa 64-01-07"}, 522 {JapaneseChronology.INSTANCE.date(1989, 1, 8), "Japanese Heisei 1-01-08"}, 523 {JapaneseChronology.INSTANCE.date(2012, 12, 6), "Japanese Heisei 24-12-06"}, 524 }; 525 } 526 527 @Test(dataProvider="toString") 528 public void test_toString(JapaneseDate jdate, String expected) { 529 assertEquals(jdate.toString(), expected); 530 } 531 532 //----------------------------------------------------------------------- 533 // equals() 534 //----------------------------------------------------------------------- 535 @Test 536 public void test_equals_true() { 537 assertTrue(JapaneseChronology.INSTANCE.equals(JapaneseChronology.INSTANCE)); 538 } 539 540 @Test 541 public void test_equals_false() { 542 assertFalse(JapaneseChronology.INSTANCE.equals(IsoChronology.INSTANCE)); 543 } 544 545 }