test/java/time/tck/java/time/TCKLocalDateTime.java

Print this page




  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  63 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  64 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  65 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  66 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  67 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  68 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  69 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  70 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  71 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  72 import static java.time.temporal.ChronoField.EPOCH_DAY;
  73 import static java.time.temporal.ChronoField.EPOCH_MONTH;
  74 import static java.time.temporal.ChronoField.ERA;
  75 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  76 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  77 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  78 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  79 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  80 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  81 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  82 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  83 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  84 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  85 import static java.time.temporal.ChronoField.NANO_OF_SECOND;

  86 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  87 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  88 import static java.time.temporal.ChronoField.YEAR;
  89 import static java.time.temporal.ChronoField.YEAR_OF_ERA;

  90 import static java.time.temporal.ChronoUnit.DAYS;







  91 import static java.time.temporal.ChronoUnit.MONTHS;
  92 import static java.time.temporal.ChronoUnit.NANOS;
  93 import static java.time.temporal.ChronoUnit.SECONDS;

  94 import static java.time.temporal.ChronoUnit.YEARS;
  95 import static org.testng.Assert.assertEquals;
  96 import static org.testng.Assert.assertFalse;
  97 import static org.testng.Assert.assertSame;
  98 import static org.testng.Assert.assertTrue;

  99 
 100 import java.io.ByteArrayOutputStream;
 101 import java.io.DataOutputStream;
 102 import java.time.Clock;
 103 import java.time.DateTimeException;
 104 import java.time.DayOfWeek;
 105 import java.time.Instant;
 106 import java.time.LocalDate;
 107 import java.time.LocalDateTime;
 108 import java.time.LocalTime;
 109 import java.time.Month;
 110 import java.time.OffsetDateTime;

 111 import java.time.Year;
 112 import java.time.ZoneId;
 113 import java.time.ZoneOffset;
 114 import java.time.ZonedDateTime;
 115 import java.time.chrono.IsoChronology;
 116 import java.time.format.DateTimeFormatter;
 117 import java.time.format.DateTimeParseException;
 118 import java.time.temporal.ChronoField;
 119 import java.time.temporal.ChronoUnit;
 120 import java.time.temporal.JulianFields;
 121 import java.time.temporal.Queries;
 122 import java.time.temporal.Temporal;
 123 import java.time.temporal.TemporalAccessor;
 124 import java.time.temporal.TemporalAdjuster;
 125 import java.time.temporal.TemporalAmount;
 126 import java.time.temporal.TemporalField;
 127 import java.time.temporal.TemporalQuery;
 128 import java.time.temporal.TemporalUnit;
 129 import java.util.ArrayList;
 130 import java.util.Arrays;
 131 import java.util.Iterator;
 132 import java.util.List;
 133 
 134 import org.testng.annotations.BeforeMethod;
 135 import org.testng.annotations.DataProvider;
 136 import org.testng.annotations.Test;
 137 
 138 /**
 139  * Test LocalDateTime.
 140  */
 141 @Test
 142 public class TCKLocalDateTime extends AbstractDateTimeTest {
 143 
 144     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 145     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 146     private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2);
 147     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 148     private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza");
 149 
 150     private LocalDateTime TEST_2007_07_15_12_30_40_987654321 = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 151     private LocalDateTime MAX_DATE_TIME;
 152     private LocalDateTime MIN_DATE_TIME;
 153     private Instant MAX_INSTANT;
 154     private Instant MIN_INSTANT;
 155 
 156     @BeforeMethod(groups={"implementation","tck"})
 157     public void setUp() {
 158         MAX_DATE_TIME = LocalDateTime.MAX;
 159         MIN_DATE_TIME = LocalDateTime.MIN;
 160         MAX_INSTANT = MAX_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 161         MIN_INSTANT = MIN_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 162     }
 163 
 164     //-----------------------------------------------------------------------
 165     @Override
 166     protected List<TemporalAccessor> samples() {
 167         TemporalAccessor[] array = {TEST_2007_07_15_12_30_40_987654321, LocalDateTime.MAX, LocalDateTime.MIN, };
 168         return Arrays.asList(array);
 169     }
 170 
 171     @Override
 172     protected List<TemporalField> validFields() {
 173         TemporalField[] array = {
 174             NANO_OF_SECOND,
 175             NANO_OF_DAY,
 176             MICRO_OF_SECOND,


 178             MILLI_OF_SECOND,
 179             MILLI_OF_DAY,
 180             SECOND_OF_MINUTE,
 181             SECOND_OF_DAY,
 182             MINUTE_OF_HOUR,
 183             MINUTE_OF_DAY,
 184             CLOCK_HOUR_OF_AMPM,
 185             HOUR_OF_AMPM,
 186             CLOCK_HOUR_OF_DAY,
 187             HOUR_OF_DAY,
 188             AMPM_OF_DAY,
 189             DAY_OF_WEEK,
 190             ALIGNED_DAY_OF_WEEK_IN_MONTH,
 191             ALIGNED_DAY_OF_WEEK_IN_YEAR,
 192             DAY_OF_MONTH,
 193             DAY_OF_YEAR,
 194             EPOCH_DAY,
 195             ALIGNED_WEEK_OF_MONTH,
 196             ALIGNED_WEEK_OF_YEAR,
 197             MONTH_OF_YEAR,
 198             EPOCH_MONTH,
 199             YEAR_OF_ERA,
 200             YEAR,
 201             ERA,
 202             JulianFields.JULIAN_DAY,
 203             JulianFields.MODIFIED_JULIAN_DAY,
 204             JulianFields.RATA_DIE,
 205         };
 206         return Arrays.asList(array);
 207     }
 208 
 209     @Override
 210     protected List<TemporalField> invalidFields() {
 211         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 212         list.removeAll(validFields());
 213         return list;
 214     }
 215 
 216     //-----------------------------------------------------------------------
 217     private void check(LocalDateTime test, int y, int m, int d, int h, int mi, int s, int n) {
 218         assertEquals(test.getYear(), y);


 255         byte[] bytes = baos.toByteArray();
 256         assertSerializedBySer(LocalDateTime.of(2012, 9, 16, 22, 17, 59, 459_000_000), bytes);
 257     }
 258 
 259     //-----------------------------------------------------------------------
 260     // constants
 261     //-----------------------------------------------------------------------
 262     @Test
 263     public void constant_MIN() {
 264         check(LocalDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
 265     }
 266 
 267     @Test
 268     public void constant_MAX() {
 269         check(LocalDateTime.MAX, Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999);
 270     }
 271 
 272     //-----------------------------------------------------------------------
 273     // now()
 274     //-----------------------------------------------------------------------
 275     @Test(timeOut=30000, groups={"tck"})  // TODO: remove when time zone loading is faster
 276     public void now() {
 277         LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone());
 278         LocalDateTime test = LocalDateTime.now();
 279         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 280         if (diff >= 100000000) {
 281             // may be date change
 282             expected = LocalDateTime.now(Clock.systemDefaultZone());
 283             test = LocalDateTime.now();
 284             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 285         }
 286         assertTrue(diff < 100000000);  // less than 0.1 secs
 287     }
 288 
 289     //-----------------------------------------------------------------------
 290     // now(ZoneId)
 291     //-----------------------------------------------------------------------
 292     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 293     public void now_ZoneId_nullZoneId() {
 294         LocalDateTime.now((ZoneId) null);
 295     }
 296 
 297     @Test(groups={"tck"})
 298     public void now_ZoneId() {
 299         ZoneId zone = ZoneId.of("UTC+01:02:03");
 300         LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
 301         LocalDateTime test = LocalDateTime.now(zone);
 302         for (int i = 0; i < 100; i++) {
 303             if (expected.equals(test)) {
 304                 return;
 305             }
 306             expected = LocalDateTime.now(Clock.system(zone));
 307             test = LocalDateTime.now(zone);
 308         }
 309         assertEquals(test, expected);
 310     }
 311 
 312     //-----------------------------------------------------------------------
 313     // now(Clock)
 314     //-----------------------------------------------------------------------
 315     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 316     public void now_Clock_nullClock() {
 317         LocalDateTime.now((Clock) null);
 318     }
 319 
 320     @Test(groups={"tck"})
 321     public void now_Clock_allSecsInDay_utc() {
 322         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 323             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 324             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 325             LocalDateTime test = LocalDateTime.now(clock);
 326             assertEquals(test.getYear(), 1970);
 327             assertEquals(test.getMonth(), Month.JANUARY);
 328             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 329             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 330             assertEquals(test.getMinute(), (i / 60) % 60);
 331             assertEquals(test.getSecond(), i % 60);
 332             assertEquals(test.getNano(), 123456789);
 333         }
 334     }
 335 
 336     @Test(groups={"tck"})
 337     public void now_Clock_allSecsInDay_offset() {
 338         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 339             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 340             Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
 341             LocalDateTime test = LocalDateTime.now(clock);
 342             assertEquals(test.getYear(), 1970);
 343             assertEquals(test.getMonth(), Month.JANUARY);
 344             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
 345             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 346             assertEquals(test.getMinute(), (i / 60) % 60);
 347             assertEquals(test.getSecond(), i % 60);
 348             assertEquals(test.getNano(), 123456789);
 349         }
 350     }
 351 
 352     @Test(groups={"tck"})
 353     public void now_Clock_allSecsInDay_beforeEpoch() {
 354         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 355         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 356             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 357             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 358             LocalDateTime test = LocalDateTime.now(clock);
 359             assertEquals(test.getYear(), 1969);
 360             assertEquals(test.getMonth(), Month.DECEMBER);
 361             assertEquals(test.getDayOfMonth(), 31);
 362             expected = expected.minusSeconds(1);
 363             assertEquals(test.toLocalTime(), expected);
 364         }
 365     }
 366 
 367     //-----------------------------------------------------------------------
 368     @Test(groups={"tck"})
 369     public void now_Clock_maxYear() {
 370         Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC);
 371         LocalDateTime test = LocalDateTime.now(clock);
 372         assertEquals(test, MAX_DATE_TIME);
 373     }
 374 
 375     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 376     public void now_Clock_tooBig() {
 377         Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC);
 378         LocalDateTime.now(clock);
 379     }
 380 
 381     @Test(groups={"tck"})
 382     public void now_Clock_minYear() {
 383         Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC);
 384         LocalDateTime test = LocalDateTime.now(clock);
 385         assertEquals(test, MIN_DATE_TIME);
 386     }
 387 
 388     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 389     public void now_Clock_tooLow() {
 390         Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC);
 391         LocalDateTime.now(clock);
 392     }
 393 
 394     //-----------------------------------------------------------------------
 395     // of() factories
 396     //-----------------------------------------------------------------------
 397     //-----------------------------------------------------------------------
 398     @Test(groups={"tck"})
 399     public void factory_of_4intsMonth() {
 400         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30);
 401         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 402     }
 403 
 404     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 405     public void factory_of_4intsMonth_yearTooLow() {
 406         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30);
 407     }
 408 
 409     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 410     public void factory_of_4intsMonth_nullMonth() {
 411         LocalDateTime.of(2007, null, 15, 12, 30);
 412     }
 413 
 414     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 415     public void factory_of_4intsMonth_dayTooLow() {
 416         LocalDateTime.of(2007, Month.JULY, -1, 12, 30);
 417     }
 418 
 419     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 420     public void factory_of_4intsMonth_dayTooHigh() {
 421         LocalDateTime.of(2007, Month.JULY, 32, 12, 30);
 422     }
 423 
 424     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 425     public void factory_of_4intsMonth_hourTooLow() {
 426         LocalDateTime.of(2007, Month.JULY, 15, -1, 30);
 427     }
 428 
 429     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 430     public void factory_of_4intsMonth_hourTooHigh() {
 431         LocalDateTime.of(2007, Month.JULY, 15, 24, 30);
 432     }
 433 
 434     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 435     public void factory_of_4intsMonth_minuteTooLow() {
 436         LocalDateTime.of(2007, Month.JULY, 15, 12, -1);
 437     }
 438 
 439     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 440     public void factory_of_4intsMonth_minuteTooHigh() {
 441         LocalDateTime.of(2007, Month.JULY, 15, 12, 60);
 442     }
 443 
 444     //-----------------------------------------------------------------------
 445     @Test(groups={"tck"})
 446     public void factory_of_5intsMonth() {
 447         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40);
 448         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 449     }
 450 
 451     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 452     public void factory_of_5intsMonth_yearTooLow() {
 453         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40);
 454     }
 455 
 456     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 457     public void factory_of_5intsMonth_nullMonth() {
 458         LocalDateTime.of(2007, null, 15, 12, 30, 40);
 459     }
 460 
 461     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 462     public void factory_of_5intsMonth_dayTooLow() {
 463         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40);
 464     }
 465 
 466     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 467     public void factory_of_5intsMonth_dayTooHigh() {
 468         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40);
 469     }
 470 
 471     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 472     public void factory_of_5intsMonth_hourTooLow() {
 473         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40);
 474     }
 475 
 476     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 477     public void factory_of_5intsMonth_hourTooHigh() {
 478         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40);
 479     }
 480 
 481     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 482     public void factory_of_5intsMonth_minuteTooLow() {
 483         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40);
 484     }
 485 
 486     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 487     public void factory_of_5intsMonth_minuteTooHigh() {
 488         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40);
 489     }
 490 
 491     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 492     public void factory_of_5intsMonth_secondTooLow() {
 493         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1);
 494     }
 495 
 496     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 497     public void factory_of_5intsMonth_secondTooHigh() {
 498         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60);
 499     }
 500 
 501     //-----------------------------------------------------------------------
 502     @Test(groups={"tck"})
 503     public void factory_of_6intsMonth() {
 504         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 987654321);
 505         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 506     }
 507 
 508     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 509     public void factory_of_6intsMonth_yearTooLow() {
 510         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321);
 511     }
 512 
 513     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 514     public void factory_of_6intsMonth_nullMonth() {
 515         LocalDateTime.of(2007, null, 15, 12, 30, 40, 987654321);
 516     }
 517 
 518     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 519     public void factory_of_6intsMonth_dayTooLow() {
 520         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40, 987654321);
 521     }
 522 
 523     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 524     public void factory_of_6intsMonth_dayTooHigh() {
 525         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40, 987654321);
 526     }
 527 
 528     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 529     public void factory_of_6intsMonth_hourTooLow() {
 530         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40, 987654321);
 531     }
 532 
 533     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 534     public void factory_of_6intsMonth_hourTooHigh() {
 535         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40, 987654321);
 536     }
 537 
 538     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 539     public void factory_of_6intsMonth_minuteTooLow() {
 540         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40, 987654321);
 541     }
 542 
 543     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 544     public void factory_of_6intsMonth_minuteTooHigh() {
 545         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40, 987654321);
 546     }
 547 
 548     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 549     public void factory_of_6intsMonth_secondTooLow() {
 550         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321);
 551     }
 552 
 553     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 554     public void factory_of_6intsMonth_secondTooHigh() {
 555         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60, 987654321);
 556     }
 557 
 558     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 559     public void factory_of_6intsMonth_nanoTooLow() {
 560         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, -1);
 561     }
 562 
 563     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 564     public void factory_of_6intsMonth_nanoTooHigh() {
 565         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 1000000000);
 566     }
 567 
 568     //-----------------------------------------------------------------------
 569     @Test(groups={"tck"})
 570     public void factory_of_5ints() {
 571         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30);
 572         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 573     }
 574 
 575     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 576     public void factory_of_5ints_yearTooLow() {
 577         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30);
 578     }
 579 
 580     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 581     public void factory_of_5ints_monthTooLow() {
 582         LocalDateTime.of(2007, 0, 15, 12, 30);
 583     }
 584 
 585     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 586     public void factory_of_5ints_monthTooHigh() {
 587         LocalDateTime.of(2007, 13, 15, 12, 30);
 588     }
 589 
 590     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 591     public void factory_of_5ints_dayTooLow() {
 592         LocalDateTime.of(2007, 7, -1, 12, 30);
 593     }
 594 
 595     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 596     public void factory_of_5ints_dayTooHigh() {
 597         LocalDateTime.of(2007, 7, 32, 12, 30);
 598     }
 599 
 600     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 601     public void factory_of_5ints_hourTooLow() {
 602         LocalDateTime.of(2007, 7, 15, -1, 30);
 603     }
 604 
 605     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 606     public void factory_of_5ints_hourTooHigh() {
 607         LocalDateTime.of(2007, 7, 15, 24, 30);
 608     }
 609 
 610     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 611     public void factory_of_5ints_minuteTooLow() {
 612         LocalDateTime.of(2007, 7, 15, 12, -1);
 613     }
 614 
 615     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 616     public void factory_of_5ints_minuteTooHigh() {
 617         LocalDateTime.of(2007, 7, 15, 12, 60);
 618     }
 619 
 620     //-----------------------------------------------------------------------
 621     @Test(groups={"tck"})
 622     public void factory_of_6ints() {
 623         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40);
 624         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 625     }
 626 
 627     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 628     public void factory_of_6ints_yearTooLow() {
 629         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40);
 630     }
 631 
 632     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 633     public void factory_of_6ints_monthTooLow() {
 634         LocalDateTime.of(2007, 0, 15, 12, 30, 40);
 635     }
 636 
 637     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 638     public void factory_of_6ints_monthTooHigh() {
 639         LocalDateTime.of(2007, 13, 15, 12, 30, 40);
 640     }
 641 
 642     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 643     public void factory_of_6ints_dayTooLow() {
 644         LocalDateTime.of(2007, 7, -1, 12, 30, 40);
 645     }
 646 
 647     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 648     public void factory_of_6ints_dayTooHigh() {
 649         LocalDateTime.of(2007, 7, 32, 12, 30, 40);
 650     }
 651 
 652     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 653     public void factory_of_6ints_hourTooLow() {
 654         LocalDateTime.of(2007, 7, 15, -1, 30, 40);
 655     }
 656 
 657     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 658     public void factory_of_6ints_hourTooHigh() {
 659         LocalDateTime.of(2007, 7, 15, 24, 30, 40);
 660     }
 661 
 662     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 663     public void factory_of_6ints_minuteTooLow() {
 664         LocalDateTime.of(2007, 7, 15, 12, -1, 40);
 665     }
 666 
 667     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 668     public void factory_of_6ints_minuteTooHigh() {
 669         LocalDateTime.of(2007, 7, 15, 12, 60, 40);
 670     }
 671 
 672     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 673     public void factory_of_6ints_secondTooLow() {
 674         LocalDateTime.of(2007, 7, 15, 12, 30, -1);
 675     }
 676 
 677     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 678     public void factory_of_6ints_secondTooHigh() {
 679         LocalDateTime.of(2007, 7, 15, 12, 30, 60);
 680     }
 681 
 682     //-----------------------------------------------------------------------
 683     @Test(groups={"tck"})
 684     public void factory_of_7ints() {
 685         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 686         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 687     }
 688 
 689     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 690     public void factory_of_7ints_yearTooLow() {
 691         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40, 987654321);
 692     }
 693 
 694     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 695     public void factory_of_7ints_monthTooLow() {
 696         LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321);
 697     }
 698 
 699     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 700     public void factory_of_7ints_monthTooHigh() {
 701         LocalDateTime.of(2007, 13, 15, 12, 30, 40, 987654321);
 702     }
 703 
 704     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 705     public void factory_of_7ints_dayTooLow() {
 706         LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321);
 707     }
 708 
 709     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 710     public void factory_of_7ints_dayTooHigh() {
 711         LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321);
 712     }
 713 
 714     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 715     public void factory_of_7ints_hourTooLow() {
 716         LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321);
 717     }
 718 
 719     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 720     public void factory_of_7ints_hourTooHigh() {
 721         LocalDateTime.of(2007, 7, 15, 24, 30, 40, 987654321);
 722     }
 723 
 724     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 725     public void factory_of_7ints_minuteTooLow() {
 726         LocalDateTime.of(2007, 7, 15, 12, -1, 40, 987654321);
 727     }
 728 
 729     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 730     public void factory_of_7ints_minuteTooHigh() {
 731         LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321);
 732     }
 733 
 734     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 735     public void factory_of_7ints_secondTooLow() {
 736         LocalDateTime.of(2007, 7, 15, 12, 30, -1, 987654321);
 737     }
 738 
 739     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 740     public void factory_of_7ints_secondTooHigh() {
 741         LocalDateTime.of(2007, 7, 15, 12, 30, 60, 987654321);
 742     }
 743 
 744     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 745     public void factory_of_7ints_nanoTooLow() {
 746         LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1);
 747     }
 748 
 749     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 750     public void factory_of_7ints_nanoTooHigh() {
 751         LocalDateTime.of(2007, 7, 15, 12, 30, 40, 1000000000);
 752     }
 753 
 754     //-----------------------------------------------------------------------
 755     @Test(groups={"tck"})
 756     public void factory_of_LocalDate_LocalTime() {
 757         LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(12, 30, 40, 987654321));
 758         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 759     }
 760 
 761     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 762     public void factory_of_LocalDate_LocalTime_nullLocalDate() {
 763         LocalDateTime.of(null, LocalTime.of(12, 30, 40, 987654321));
 764     }
 765 
 766     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 767     public void factory_of_LocalDate_LocalTime_nullLocalTime() {
 768         LocalDateTime.of(LocalDate.of(2007, 7, 15), null);
 769     }
 770 
 771     //-----------------------------------------------------------------------
 772     // ofInstant()
 773     //-----------------------------------------------------------------------
 774     @DataProvider(name="instantFactory")
 775     Object[][] data_instantFactory() {
 776         return new Object[][] {
 777                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), ZONE_PARIS, LocalDateTime.of(1970, 1, 2, 2, 2, 4, 500)},
 778                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), OFFSET_MTWO, LocalDateTime.of(1970, 1, 1, 23, 2, 4, 500)},
 779                 {Instant.ofEpochSecond(-86400 + 4, 500), OFFSET_PTWO, LocalDateTime.of(1969, 12, 31, 2, 0, 4, 500)},
 780                 {OffsetDateTime.of(LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0), ZoneOffset.UTC).toInstant(),
 781                         ZoneOffset.UTC, LocalDateTime.MIN},
 782                 {OffsetDateTime.of(LocalDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 59, 999_999_999), ZoneOffset.UTC).toInstant(),
 783                         ZoneOffset.UTC, LocalDateTime.MAX},
 784         };
 785     }
 786 
 787     @Test(dataProvider="instantFactory")
 788     public void factory_ofInstant(Instant instant, ZoneId zone, LocalDateTime expected) {
 789         LocalDateTime test = LocalDateTime.ofInstant(instant, zone);
 790         assertEquals(test, expected);
 791     }
 792 
 793     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 794     public void factory_ofInstant_instantTooBig() {
 795         LocalDateTime.ofInstant(Instant.MAX, OFFSET_PONE) ;
 796     }
 797 
 798     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 799     public void factory_ofInstant_instantTooSmall() {
 800         LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ;
 801     }
 802 
 803     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 804     public void factory_ofInstant_nullInstant() {
 805         LocalDateTime.ofInstant((Instant) null, ZONE_GAZA);
 806     }
 807 
 808     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 809     public void factory_ofInstant_nullZone() {
 810         LocalDateTime.ofInstant(Instant.EPOCH, (ZoneId) null);
 811     }
 812 
 813     //-----------------------------------------------------------------------
 814     // ofEpochSecond()
 815     //-----------------------------------------------------------------------
 816     @Test(groups={"tck"})
 817     public void factory_ofEpochSecond_longOffset_afterEpoch() {
 818         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 819         for (int i = 0; i < 100000; i++) {
 820             LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO);
 821             assertEquals(test, base.plusSeconds(i));
 822         }
 823     }
 824 
 825     @Test(groups={"tck"})
 826     public void factory_ofEpochSecond_longOffset_beforeEpoch() {
 827         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 828         for (int i = 0; i < 100000; i++) {
 829             LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO);
 830             assertEquals(test, base.minusSeconds(i));
 831         }
 832     }
 833 
 834     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 835     public void factory_ofEpochSecond_longOffset_tooBig() {
 836         LocalDateTime.ofEpochSecond(Long.MAX_VALUE, 500, OFFSET_PONE);  // TODO: better test
 837     }
 838 
 839     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 840     public void factory_ofEpochSecond_longOffset_tooSmall() {
 841         LocalDateTime.ofEpochSecond(Long.MIN_VALUE, 500, OFFSET_PONE);  // TODO: better test
 842     }
 843 
 844     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 845     public void factory_ofEpochSecond_badNanos_toBig() {
 846         LocalDateTime.ofEpochSecond(0, 1_000_000_000, OFFSET_PONE);
 847     }
 848 
 849     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 850     public void factory_ofEpochSecond_badNanos_toSmall() {
 851         LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE);
 852     }
 853 
 854     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 855     public void factory_ofEpochSecond_longOffset_nullOffset() {
 856         LocalDateTime.ofEpochSecond(0L, 500, null);
 857     }
 858 
 859     //-----------------------------------------------------------------------
 860     // from()
 861     //-----------------------------------------------------------------------
 862     @Test(groups={"tck"})
 863     public void test_from_TemporalAccessor() {
 864         LocalDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30);
 865         assertEquals(LocalDateTime.from(base), base);
 866         assertEquals(LocalDateTime.from(ZonedDateTime.of(base, ZoneOffset.ofHours(2))), base);
 867     }
 868 
 869     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 870     public void test_from_TemporalAccessor_invalid_noDerive() {
 871         LocalDateTime.from(LocalTime.of(12, 30));
 872     }
 873 
 874     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 875     public void test_from_TemporalAccessor_null() {
 876         LocalDateTime.from((TemporalAccessor) null);
 877     }
 878 
 879     //-----------------------------------------------------------------------
 880     // parse()
 881     //-----------------------------------------------------------------------
 882     @Test(dataProvider="sampleToString", groups={"tck"})
 883     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String text) {
 884         LocalDateTime t = LocalDateTime.parse(text);
 885         assertEquals(t.getYear(), y);
 886         assertEquals(t.getMonth().getValue(), month);
 887         assertEquals(t.getDayOfMonth(), d);
 888         assertEquals(t.getHour(), h);
 889         assertEquals(t.getMinute(), m);
 890         assertEquals(t.getSecond(), s);
 891         assertEquals(t.getNano(), n);
 892     }
 893 
 894     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 895     public void factory_parse_illegalValue() {
 896         LocalDateTime.parse("2008-06-32T11:15");
 897     }
 898 
 899     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 900     public void factory_parse_invalidValue() {
 901         LocalDateTime.parse("2008-06-31T11:15");
 902     }
 903 
 904     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 905     public void factory_parse_nullText() {
 906         LocalDateTime.parse((String) null);
 907     }
 908 
 909     //-----------------------------------------------------------------------
 910     // parse(DateTimeFormatter)
 911     //-----------------------------------------------------------------------
 912     @Test(groups={"tck"})
 913     public void factory_parse_formatter() {
 914         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 915         LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f);
 916         assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45));
 917     }
 918 
 919     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 920     public void factory_parse_formatter_nullText() {
 921         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 922         LocalDateTime.parse((String) null, f);
 923     }
 924 
 925     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 926     public void factory_parse_formatter_nullFormatter() {
 927         LocalDateTime.parse("ANY", null);
 928     }
 929 
 930     //-----------------------------------------------------------------------
 931     // get(TemporalField)
 932     //-----------------------------------------------------------------------
 933     @Test
 934     public void test_get_TemporalField() {
 935         LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
 936         assertEquals(test.get(ChronoField.YEAR), 2008);
 937         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 938         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 939         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 940         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 941 
 942         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 943         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 944         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 945         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);


 953         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 954         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 955         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 956         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 957         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 958 
 959         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 960         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 961         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 962         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 963         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 964         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 965     }
 966 
 967     //-----------------------------------------------------------------------
 968     // query(TemporalQuery)
 969     //-----------------------------------------------------------------------
 970     @DataProvider(name="query")
 971     Object[][] data_query() {
 972         return new Object[][] {
 973                 {TEST_2007_07_15_12_30_40_987654321, Queries.chronology(), IsoChronology.INSTANCE},
 974                 {TEST_2007_07_15_12_30_40_987654321, Queries.zoneId(), null},
 975                 {TEST_2007_07_15_12_30_40_987654321, Queries.precision(), ChronoUnit.NANOS},
 976                 {TEST_2007_07_15_12_30_40_987654321, Queries.zone(), null},
 977                 {TEST_2007_07_15_12_30_40_987654321, Queries.offset(), null},
 978                 {TEST_2007_07_15_12_30_40_987654321, Queries.localDate(), LocalDate.of(2007, 7, 15)},
 979                 {TEST_2007_07_15_12_30_40_987654321, Queries.localTime(), LocalTime.of(12, 30, 40, 987654321)},
 980         };
 981     }
 982 
 983     @Test(dataProvider="query")
 984     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 985         assertEquals(temporal.query(query), expected);
 986     }
 987 
 988     @Test(dataProvider="query")
 989     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 990         assertEquals(query.queryFrom(temporal), expected);
 991     }
 992 
 993     @Test(expectedExceptions=NullPointerException.class)
 994     public void test_query_null() {
 995         TEST_2007_07_15_12_30_40_987654321.query(null);
 996     }
 997 
 998     //-----------------------------------------------------------------------
 999     @DataProvider(name="sampleDates")


1016             {0, 0, 1, 0},
1017             {0, 0, 1, 1},
1018             {0, 1, 0, 0},
1019             {0, 1, 0, 1},
1020             {0, 1, 1, 0},
1021             {0, 1, 1, 1},
1022             {1, 0, 0, 0},
1023             {1, 0, 0, 1},
1024             {1, 0, 1, 0},
1025             {1, 0, 1, 1},
1026             {1, 1, 0, 0},
1027             {1, 1, 0, 1},
1028             {1, 1, 1, 0},
1029             {1, 1, 1, 1},
1030         };
1031     }
1032 
1033     //-----------------------------------------------------------------------
1034     // get*()
1035     //-----------------------------------------------------------------------
1036     @Test(dataProvider="sampleDates", groups={"tck"})
1037     public void test_get_dates(int y, int m, int d) {
1038         LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30);
1039         assertEquals(a.getYear(), y);
1040         assertEquals(a.getMonth(), Month.of(m));
1041         assertEquals(a.getDayOfMonth(), d);
1042     }
1043 
1044     @Test(dataProvider="sampleDates", groups={"tck"})
1045     public void test_getDOY(int y, int m, int d) {
1046         LocalDateTime a = LocalDateTime.of(y, m, d, 12 ,30);
1047         int total = 0;
1048         for (int i = 1; i < m; i++) {
1049             total += Month.of(i).length(isIsoLeap(y));
1050         }
1051         int doy = total + d;
1052         assertEquals(a.getDayOfYear(), doy);
1053     }
1054 
1055     @Test(dataProvider="sampleTimes", groups={"tck"})
1056     public void test_get_times(int h, int m, int s, int ns) {
1057         LocalDateTime a = LocalDateTime.of(TEST_2007_07_15_12_30_40_987654321.toLocalDate(), LocalTime.of(h, m, s, ns));
1058         assertEquals(a.getHour(), h);
1059         assertEquals(a.getMinute(), m);
1060         assertEquals(a.getSecond(), s);
1061         assertEquals(a.getNano(), ns);
1062     }
1063 
1064     //-----------------------------------------------------------------------
1065     // getDayOfWeek()
1066     //-----------------------------------------------------------------------
1067     @Test(groups={"tck"})
1068     public void test_getDayOfWeek() {
1069         DayOfWeek dow = DayOfWeek.MONDAY;
1070         for (Month month : Month.values()) {
1071             int length = month.length(false);
1072             for (int i = 1; i <= length; i++) {
1073                 LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i),
1074                         TEST_2007_07_15_12_30_40_987654321.toLocalTime());
1075                 assertSame(d.getDayOfWeek(), dow);
1076                 dow = dow.plus(1);
1077             }
1078         }
1079     }
1080 
1081     //-----------------------------------------------------------------------








































1082     // with()
1083     //-----------------------------------------------------------------------
1084     @Test(groups={"tck"})
1085     public void test_with_adjustment() {
1086         final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5);
1087         TemporalAdjuster adjuster = new TemporalAdjuster() {
1088             @Override
1089             public Temporal adjustInto(Temporal dateTime) {
1090                 return sample;
1091             }
1092         };
1093         assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample);
1094     }
1095 
1096     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1097     public void test_with_adjustment_null() {
1098         TEST_2007_07_15_12_30_40_987654321.with((TemporalAdjuster) null);
1099     }
1100 
1101     //-----------------------------------------------------------------------
1102     // withYear()
1103     //-----------------------------------------------------------------------
1104     @Test(groups={"tck"})
1105     public void test_withYear_int_normal() {
1106         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withYear(2008);
1107         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1108     }
1109 
1110     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1111     public void test_withYear_int_invalid() {
1112         TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1);
1113     }
1114 
1115     @Test(groups={"tck"})
1116     public void test_withYear_int_adjustDay() {
1117         LocalDateTime t = LocalDateTime.of(2008, 2, 29, 12, 30).withYear(2007);
1118         LocalDateTime expected = LocalDateTime.of(2007, 2, 28, 12, 30);
1119         assertEquals(t, expected);
1120     }
1121 
1122     //-----------------------------------------------------------------------
1123     // withMonth()
1124     //-----------------------------------------------------------------------
1125     @Test(groups={"tck"})
1126     public void test_withMonth_int_normal() {
1127         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withMonth(1);
1128         check(t, 2007, 1, 15, 12, 30, 40, 987654321);
1129     }
1130 
1131     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1132     public void test_withMonth_int_invalid() {
1133         TEST_2007_07_15_12_30_40_987654321.withMonth(13);
1134     }
1135 
1136     @Test(groups={"tck"})
1137     public void test_withMonth_int_adjustDay() {
1138         LocalDateTime t = LocalDateTime.of(2007, 12, 31, 12, 30).withMonth(11);
1139         LocalDateTime expected = LocalDateTime.of(2007, 11, 30, 12, 30);
1140         assertEquals(t, expected);
1141     }
1142 
1143     //-----------------------------------------------------------------------
1144     // withDayOfMonth()
1145     //-----------------------------------------------------------------------
1146     @Test(groups={"tck"})
1147     public void test_withDayOfMonth_normal() {
1148         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfMonth(1);
1149         check(t, 2007, 7, 1, 12, 30, 40, 987654321);
1150     }
1151 
1152     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1153     public void test_withDayOfMonth_invalid() {
1154         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(32);
1155     }
1156 
1157     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1158     public void test_withDayOfMonth_invalidCombination() {
1159         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(31);
1160     }
1161 
1162     //-----------------------------------------------------------------------
1163     // withDayOfYear(int)
1164     //-----------------------------------------------------------------------
1165     @Test(groups={"tck"})
1166     public void test_withDayOfYear_normal() {
1167         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfYear(33);
1168         assertEquals(t, LocalDateTime.of(2007, 2, 2, 12, 30, 40, 987654321));
1169     }
1170 
1171     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1172     public void test_withDayOfYear_illegal() {
1173         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(367);
1174     }
1175 
1176     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1177     public void test_withDayOfYear_invalid() {
1178         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(366);
1179     }
1180 
1181     //-----------------------------------------------------------------------
1182     // withHour()
1183     //-----------------------------------------------------------------------
1184     @Test(groups={"tck"})
1185     public void test_withHour_normal() {
1186         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1187         for (int i = 0; i < 24; i++) {
1188             t = t.withHour(i);
1189             assertEquals(t.getHour(), i);
1190         }
1191     }
1192 
1193     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1194     public void test_withHour_hourTooLow() {
1195         TEST_2007_07_15_12_30_40_987654321.withHour(-1);
1196     }
1197 
1198     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1199     public void test_withHour_hourTooHigh() {
1200         TEST_2007_07_15_12_30_40_987654321.withHour(24);
1201     }
1202 
1203     //-----------------------------------------------------------------------
1204     // withMinute()
1205     //-----------------------------------------------------------------------
1206     @Test(groups={"tck"})
1207     public void test_withMinute_normal() {
1208         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1209         for (int i = 0; i < 60; i++) {
1210             t = t.withMinute(i);
1211             assertEquals(t.getMinute(), i);
1212         }
1213     }
1214 
1215     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1216     public void test_withMinute_minuteTooLow() {
1217         TEST_2007_07_15_12_30_40_987654321.withMinute(-1);
1218     }
1219 
1220     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1221     public void test_withMinute_minuteTooHigh() {
1222         TEST_2007_07_15_12_30_40_987654321.withMinute(60);
1223     }
1224 
1225     //-----------------------------------------------------------------------
1226     // withSecond()
1227     //-----------------------------------------------------------------------
1228     @Test(groups={"tck"})
1229     public void test_withSecond_normal() {
1230         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1231         for (int i = 0; i < 60; i++) {
1232             t = t.withSecond(i);
1233             assertEquals(t.getSecond(), i);
1234         }
1235     }
1236 
1237     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1238     public void test_withSecond_secondTooLow() {
1239         TEST_2007_07_15_12_30_40_987654321.withSecond(-1);
1240     }
1241 
1242     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1243     public void test_withSecond_secondTooHigh() {
1244         TEST_2007_07_15_12_30_40_987654321.withSecond(60);
1245     }
1246 
1247     //-----------------------------------------------------------------------
1248     // withNano()
1249     //-----------------------------------------------------------------------
1250     @Test(groups={"tck"})
1251     public void test_withNanoOfSecond_normal() {
1252         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1253         t = t.withNano(1);
1254         assertEquals(t.getNano(), 1);
1255         t = t.withNano(10);
1256         assertEquals(t.getNano(), 10);
1257         t = t.withNano(100);
1258         assertEquals(t.getNano(), 100);
1259         t = t.withNano(999999999);
1260         assertEquals(t.getNano(), 999999999);
1261     }
1262 
1263     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1264     public void test_withNanoOfSecond_nanoTooLow() {
1265         TEST_2007_07_15_12_30_40_987654321.withNano(-1);
1266     }
1267 
1268     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1269     public void test_withNanoOfSecond_nanoTooHigh() {
1270         TEST_2007_07_15_12_30_40_987654321.withNano(1000000000);
1271     }
1272 
1273     //-----------------------------------------------------------------------
1274     // truncatedTo(TemporalUnit)
1275     //-----------------------------------------------------------------------
1276     @Test(groups={"tck"})
1277     public void test_truncatedTo_normal() {
1278         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(NANOS), TEST_2007_07_15_12_30_40_987654321);
1279         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(SECONDS), TEST_2007_07_15_12_30_40_987654321.withNano(0));
1280         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(DAYS), TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT));
1281     }
1282 
1283     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1284     public void test_truncatedTo_null() {
1285         TEST_2007_07_15_12_30_40_987654321.truncatedTo(null);
1286     }
1287 
1288     //-----------------------------------------------------------------------
1289     // plus(TemporalAmount)
1290     //-----------------------------------------------------------------------
1291     @Test
1292     public void test_plus_TemporalAmount_positiveMonths() {
1293         MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS);
1294         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1295         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1296     }
1297 
1298     @Test
1299     public void test_plus_TemporalAmount_negativeDays() {
1300         MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS);
1301         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1302         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1303     }


1305     @Test(expectedExceptions=DateTimeException.class)
1306     public void test_plus_TemporalAmount_invalidTooLarge() {
1307         MockSimplePeriod period = MockSimplePeriod.of(1, YEARS);
1308         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(period);
1309     }
1310 
1311     @Test(expectedExceptions=DateTimeException.class)
1312     public void test_plus_TemporalAmount_invalidTooSmall() {
1313         MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS);
1314         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(period);
1315     }
1316 
1317     @Test(expectedExceptions=NullPointerException.class)
1318     public void test_plus_TemporalAmount_null() {
1319         TEST_2007_07_15_12_30_40_987654321.plus((TemporalAmount) null);
1320     }
1321 
1322     //-----------------------------------------------------------------------
1323     // plus(long,TemporalUnit)
1324     //-----------------------------------------------------------------------
1325     @Test(groups={"tck"})
1326     public void test_plus_longTemporalUnit_positiveMonths() {
1327         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(7, ChronoUnit.MONTHS);
1328         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1329     }
1330 
1331     @Test(groups={"tck"})
1332     public void test_plus_longTemporalUnit_negativeDays() {
1333         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(-25, ChronoUnit.DAYS);
1334         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1335     }
1336 
1337     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1338     public void test_plus_longTemporalUnit_null() {
1339         TEST_2007_07_15_12_30_40_987654321.plus(1, (TemporalUnit) null);
1340     }
1341 
1342     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1343     public void test_plus_longTemporalUnit_invalidTooLarge() {
1344         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(1, ChronoUnit.YEARS);
1345     }
1346 
1347     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1348     public void test_plus_longTemporalUnit_invalidTooSmall() {
1349         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(-1, ChronoUnit.YEARS);
1350     }
1351 
1352     //-----------------------------------------------------------------------
1353     // plusYears()
1354     //-----------------------------------------------------------------------
1355     @Test(groups={"tck"})
1356     public void test_plusYears_int_normal() {
1357         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1);
1358         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1359     }
1360 
1361     @Test(groups={"tck"})
1362     public void test_plusYears_int_negative() {
1363         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1);
1364         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
1365     }
1366 
1367     @Test(groups={"tck"})
1368     public void test_plusYears_int_adjustDay() {
1369         LocalDateTime t = createDateMidnight(2008, 2, 29).plusYears(1);
1370         check(t, 2009, 2, 28, 0, 0, 0, 0);
1371     }
1372 
1373     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1374     public void test_plusYears_int_invalidTooLarge() {
1375         createDateMidnight(Year.MAX_VALUE, 1, 1).plusYears(1);
1376     }
1377 
1378     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1379     public void test_plusYears_int_invalidTooSmall() {
1380         LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-1);
1381     }
1382 
1383     //-----------------------------------------------------------------------
1384     // plusMonths()
1385     //-----------------------------------------------------------------------
1386     @Test(groups={"tck"})
1387     public void test_plusMonths_int_normal() {
1388         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(1);
1389         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
1390     }
1391 
1392     @Test(groups={"tck"})
1393     public void test_plusMonths_int_overYears() {
1394         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(25);
1395         check(t, 2009, 8, 15, 12, 30, 40, 987654321);
1396     }
1397 
1398     @Test(groups={"tck"})
1399     public void test_plusMonths_int_negative() {
1400         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-1);
1401         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
1402     }
1403 
1404     @Test(groups={"tck"})
1405     public void test_plusMonths_int_negativeAcrossYear() {
1406         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-7);
1407         check(t, 2006, 12, 15, 12, 30, 40, 987654321);
1408     }
1409 
1410     @Test(groups={"tck"})
1411     public void test_plusMonths_int_negativeOverYears() {
1412         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-31);
1413         check(t, 2004, 12, 15, 12, 30, 40, 987654321);
1414     }
1415 
1416     @Test(groups={"tck"})
1417     public void test_plusMonths_int_adjustDayFromLeapYear() {
1418         LocalDateTime t = createDateMidnight(2008, 2, 29).plusMonths(12);
1419         check(t, 2009, 2, 28, 0, 0, 0, 0);
1420     }
1421 
1422     @Test(groups={"tck"})
1423     public void test_plusMonths_int_adjustDayFromMonthLength() {
1424         LocalDateTime t = createDateMidnight(2007, 3, 31).plusMonths(1);
1425         check(t, 2007, 4, 30, 0, 0, 0, 0);
1426     }
1427 
1428     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1429     public void test_plusMonths_int_invalidTooLarge() {
1430         createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1);
1431     }
1432 
1433     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1434     public void test_plusMonths_int_invalidTooSmall() {
1435         createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1);
1436     }
1437 
1438     //-----------------------------------------------------------------------
1439     // plusWeeks()
1440     //-----------------------------------------------------------------------
1441     @DataProvider(name="samplePlusWeeksSymmetry")
1442     Object[][] provider_samplePlusWeeksSymmetry() {
1443         return new Object[][] {
1444             {createDateMidnight(-1, 1, 1)},
1445             {createDateMidnight(-1, 2, 28)},
1446             {createDateMidnight(-1, 3, 1)},
1447             {createDateMidnight(-1, 12, 31)},
1448             {createDateMidnight(0, 1, 1)},
1449             {createDateMidnight(0, 2, 28)},
1450             {createDateMidnight(0, 2, 29)},
1451             {createDateMidnight(0, 3, 1)},
1452             {createDateMidnight(0, 12, 31)},
1453             {createDateMidnight(2007, 1, 1)},
1454             {createDateMidnight(2007, 2, 28)},
1455             {createDateMidnight(2007, 3, 1)},
1456             {createDateMidnight(2007, 12, 31)},
1457             {createDateMidnight(2008, 1, 1)},
1458             {createDateMidnight(2008, 2, 28)},
1459             {createDateMidnight(2008, 2, 29)},
1460             {createDateMidnight(2008, 3, 1)},
1461             {createDateMidnight(2008, 12, 31)},
1462             {createDateMidnight(2099, 1, 1)},
1463             {createDateMidnight(2099, 2, 28)},
1464             {createDateMidnight(2099, 3, 1)},
1465             {createDateMidnight(2099, 12, 31)},
1466             {createDateMidnight(2100, 1, 1)},
1467             {createDateMidnight(2100, 2, 28)},
1468             {createDateMidnight(2100, 3, 1)},
1469             {createDateMidnight(2100, 12, 31)},
1470         };
1471     }
1472 
1473     @Test(dataProvider="samplePlusWeeksSymmetry", groups={"tck"})
1474     public void test_plusWeeks_symmetry(LocalDateTime reference) {
1475         for (int weeks = 0; weeks < 365 * 8; weeks++) {
1476             LocalDateTime t = reference.plusWeeks(weeks).plusWeeks(-weeks);
1477             assertEquals(t, reference);
1478 
1479             t = reference.plusWeeks(-weeks).plusWeeks(weeks);
1480             assertEquals(t, reference);
1481         }
1482     }
1483 
1484     @Test(groups={"tck"})
1485     public void test_plusWeeks_normal() {
1486         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(1);
1487         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
1488     }
1489 
1490     @Test(groups={"tck"})
1491     public void test_plusWeeks_overMonths() {
1492         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(9);
1493         check(t, 2007, 9, 16, 12, 30, 40, 987654321);
1494     }
1495 
1496     @Test(groups={"tck"})
1497     public void test_plusWeeks_overYears() {
1498         LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52);
1499         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1500     }
1501 
1502     @Test(groups={"tck"})
1503     public void test_plusWeeks_overLeapYears() {
1504         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusWeeks(104);
1505         check(t, 2008, 7, 12, 12, 30, 40, 987654321);
1506     }
1507 
1508     @Test(groups={"tck"})
1509     public void test_plusWeeks_negative() {
1510         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-1);
1511         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
1512     }
1513 
1514     @Test(groups={"tck"})
1515     public void test_plusWeeks_negativeAcrossYear() {
1516         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-28);
1517         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1518     }
1519 
1520     @Test(groups={"tck"})
1521     public void test_plusWeeks_negativeOverYears() {
1522         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-104);
1523         check(t, 2005, 7, 17, 12, 30, 40, 987654321);
1524     }
1525 
1526     @Test(groups={"tck"})
1527     public void test_plusWeeks_maximum() {
1528         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).plusWeeks(1);
1529         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1530     }
1531 
1532     @Test(groups={"tck"})
1533     public void test_plusWeeks_minimum() {
1534         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).plusWeeks(-1);
1535         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1536     }
1537 
1538     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1539     public void test_plusWeeks_invalidTooLarge() {
1540         createDateMidnight(Year.MAX_VALUE, 12, 25).plusWeeks(1);
1541     }
1542 
1543     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1544     public void test_plusWeeks_invalidTooSmall() {
1545         createDateMidnight(Year.MIN_VALUE, 1, 7).plusWeeks(-1);
1546     }
1547 
1548     //-----------------------------------------------------------------------
1549     // plusDays()
1550     //-----------------------------------------------------------------------
1551     @DataProvider(name="samplePlusDaysSymmetry")
1552     Object[][] provider_samplePlusDaysSymmetry() {
1553         return new Object[][] {
1554             {createDateMidnight(-1, 1, 1)},
1555             {createDateMidnight(-1, 2, 28)},
1556             {createDateMidnight(-1, 3, 1)},
1557             {createDateMidnight(-1, 12, 31)},
1558             {createDateMidnight(0, 1, 1)},
1559             {createDateMidnight(0, 2, 28)},
1560             {createDateMidnight(0, 2, 29)},
1561             {createDateMidnight(0, 3, 1)},
1562             {createDateMidnight(0, 12, 31)},
1563             {createDateMidnight(2007, 1, 1)},
1564             {createDateMidnight(2007, 2, 28)},
1565             {createDateMidnight(2007, 3, 1)},
1566             {createDateMidnight(2007, 12, 31)},
1567             {createDateMidnight(2008, 1, 1)},
1568             {createDateMidnight(2008, 2, 28)},
1569             {createDateMidnight(2008, 2, 29)},
1570             {createDateMidnight(2008, 3, 1)},
1571             {createDateMidnight(2008, 12, 31)},
1572             {createDateMidnight(2099, 1, 1)},
1573             {createDateMidnight(2099, 2, 28)},
1574             {createDateMidnight(2099, 3, 1)},
1575             {createDateMidnight(2099, 12, 31)},
1576             {createDateMidnight(2100, 1, 1)},
1577             {createDateMidnight(2100, 2, 28)},
1578             {createDateMidnight(2100, 3, 1)},
1579             {createDateMidnight(2100, 12, 31)},
1580         };
1581     }
1582 
1583     @Test(dataProvider="samplePlusDaysSymmetry", groups={"tck"})
1584     public void test_plusDays_symmetry(LocalDateTime reference) {
1585         for (int days = 0; days < 365 * 8; days++) {
1586             LocalDateTime t = reference.plusDays(days).plusDays(-days);
1587             assertEquals(t, reference);
1588 
1589             t = reference.plusDays(-days).plusDays(days);
1590             assertEquals(t, reference);
1591         }
1592     }
1593 
1594     @Test(groups={"tck"})
1595     public void test_plusDays_normal() {
1596         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(1);
1597         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
1598     }
1599 
1600     @Test(groups={"tck"})
1601     public void test_plusDays_overMonths() {
1602         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(62);
1603         check(t, 2007, 9, 15, 12, 30, 40, 987654321);
1604     }
1605 
1606     @Test(groups={"tck"})
1607     public void test_plusDays_overYears() {
1608         LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366);
1609         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1610     }
1611 
1612     @Test(groups={"tck"})
1613     public void test_plusDays_overLeapYears() {
1614         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusDays(365 + 366);
1615         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1616     }
1617 
1618     @Test(groups={"tck"})
1619     public void test_plusDays_negative() {
1620         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-1);
1621         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
1622     }
1623 
1624     @Test(groups={"tck"})
1625     public void test_plusDays_negativeAcrossYear() {
1626         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-196);
1627         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1628     }
1629 
1630     @Test(groups={"tck"})
1631     public void test_plusDays_negativeOverYears() {
1632         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-730);
1633         check(t, 2005, 7, 15, 12, 30, 40, 987654321);
1634     }
1635 
1636     @Test(groups={"tck"})
1637     public void test_plusDays_maximum() {
1638         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).plusDays(1);
1639         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1640     }
1641 
1642     @Test(groups={"tck"})
1643     public void test_plusDays_minimum() {
1644         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).plusDays(-1);
1645         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1646     }
1647 
1648     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1649     public void test_plusDays_invalidTooLarge() {
1650         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(1);
1651     }
1652 
1653     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1654     public void test_plusDays_invalidTooSmall() {
1655         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(-1);
1656     }
1657 
1658     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
1659     public void test_plusDays_overflowTooLarge() {
1660         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(Long.MAX_VALUE);
1661     }
1662 
1663     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
1664     public void test_plusDays_overflowTooSmall() {
1665         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(Long.MIN_VALUE);
1666     }
1667 
1668     //-----------------------------------------------------------------------
1669     // plusHours()
1670     //-----------------------------------------------------------------------
1671     @Test(groups={"tck"})
1672     public void test_plusHours_one() {
1673         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1674         LocalDate d = t.toLocalDate();
1675 
1676         for (int i = 0; i < 50; i++) {
1677             t = t.plusHours(1);
1678 
1679             if ((i + 1) % 24 == 0) {
1680                 d = d.plusDays(1);
1681             }
1682 
1683             assertEquals(t.toLocalDate(), d);
1684             assertEquals(t.getHour(), (i + 1) % 24);
1685         }
1686     }
1687 
1688     @Test(groups={"tck"})
1689     public void test_plusHours_fromZero() {
1690         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1691         LocalDate d = base.toLocalDate().minusDays(3);
1692         LocalTime t = LocalTime.of(21, 0);
1693 
1694         for (int i = -50; i < 50; i++) {
1695             LocalDateTime dt = base.plusHours(i);
1696             t = t.plusHours(1);
1697 
1698             if (t.getHour() == 0) {
1699                 d = d.plusDays(1);
1700             }
1701 
1702             assertEquals(dt.toLocalDate(), d);
1703             assertEquals(dt.toLocalTime(), t);
1704         }
1705     }
1706 
1707     @Test(groups={"tck"})
1708     public void test_plusHours_fromOne() {
1709         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
1710         LocalDate d = base.toLocalDate().minusDays(3);
1711         LocalTime t = LocalTime.of(22, 0);
1712 
1713         for (int i = -50; i < 50; i++) {
1714             LocalDateTime dt = base.plusHours(i);
1715 
1716             t = t.plusHours(1);
1717 
1718             if (t.getHour() == 0) {
1719                 d = d.plusDays(1);
1720             }
1721 
1722             assertEquals(dt.toLocalDate(), d);
1723             assertEquals(dt.toLocalTime(), t);
1724         }
1725     }
1726 
1727     //-----------------------------------------------------------------------
1728     // plusMinutes()
1729     //-----------------------------------------------------------------------
1730     @Test(groups={"tck"})
1731     public void test_plusMinutes_one() {
1732         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1733         LocalDate d = t.toLocalDate();
1734 
1735         int hour = 0;
1736         int min = 0;
1737 
1738         for (int i = 0; i < 70; i++) {
1739             t = t.plusMinutes(1);
1740             min++;
1741             if (min == 60) {
1742                 hour++;
1743                 min = 0;
1744             }
1745 
1746             assertEquals(t.toLocalDate(), d);
1747             assertEquals(t.getHour(), hour);
1748             assertEquals(t.getMinute(), min);
1749         }
1750     }
1751 
1752     @Test(groups={"tck"})
1753     public void test_plusMinutes_fromZero() {
1754         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1755         LocalDate d = base.toLocalDate().minusDays(1);
1756         LocalTime t = LocalTime.of(22, 49);
1757 
1758         for (int i = -70; i < 70; i++) {
1759             LocalDateTime dt = base.plusMinutes(i);
1760             t = t.plusMinutes(1);
1761 
1762             if (t == LocalTime.MIDNIGHT) {
1763                 d = d.plusDays(1);
1764             }
1765 
1766             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
1767             assertEquals(dt.toLocalTime(), t, String.valueOf(i));
1768         }
1769     }
1770 
1771     @Test(groups={"tck"})
1772     public void test_plusMinutes_noChange_oneDay() {
1773         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60);
1774         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
1775     }
1776 
1777     //-----------------------------------------------------------------------
1778     // plusSeconds()
1779     //-----------------------------------------------------------------------
1780     @Test(groups={"tck"})
1781     public void test_plusSeconds_one() {
1782         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1783         LocalDate d = t.toLocalDate();
1784 
1785         int hour = 0;
1786         int min = 0;
1787         int sec = 0;
1788 
1789         for (int i = 0; i < 3700; i++) {
1790             t = t.plusSeconds(1);
1791             sec++;
1792             if (sec == 60) {
1793                 min++;
1794                 sec = 0;
1795             }
1796             if (min == 60) {
1797                 hour++;
1798                 min = 0;
1799             }
1800 


1835 
1836                         if (hour == 24) {
1837                             hour = 0;
1838                         }
1839                     }
1840                 }
1841 
1842                 if (i == 0) {
1843                     date = date.plusDays(1);
1844                 }
1845 
1846                 return ret;
1847             }
1848 
1849             public void remove() {
1850                 throw new UnsupportedOperationException();
1851             }
1852         };
1853     }
1854 
1855     @Test(dataProvider="plusSeconds_fromZero", groups={"tck"})
1856     public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
1857         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1858         LocalDateTime t = base.plusSeconds(seconds);
1859 
1860         assertEquals(date, t.toLocalDate());
1861         assertEquals(hour, t.getHour());
1862         assertEquals(min, t.getMinute());
1863         assertEquals(sec, t.getSecond());
1864     }
1865 
1866     @Test(groups={"tck"})
1867     public void test_plusSeconds_noChange_oneDay() {
1868         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusSeconds(24 * 60 * 60);
1869         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
1870     }
1871 
1872     //-----------------------------------------------------------------------
1873     // plusNanos()
1874     //-----------------------------------------------------------------------
1875     @Test(groups={"tck"})
1876     public void test_plusNanos_halfABillion() {
1877         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1878         LocalDate d = t.toLocalDate();
1879 
1880         int hour = 0;
1881         int min = 0;
1882         int sec = 0;
1883         int nanos = 0;
1884 
1885         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
1886             t = t.plusNanos(500000000);
1887             nanos += 500000000;
1888             if (nanos == 1000000000) {
1889                 sec++;
1890                 nanos = 0;
1891             }
1892             if (sec == 60) {
1893                 min++;
1894                 sec = 0;
1895             }


1939                             hour++;
1940                             min = 0;
1941 
1942                             if (hour == 24) {
1943                                 hour = 0;
1944                                 date = date.plusDays(1);
1945                             }
1946                         }
1947                     }
1948                 }
1949 
1950                 return ret;
1951             }
1952 
1953             public void remove() {
1954                 throw new UnsupportedOperationException();
1955             }
1956         };
1957     }
1958 
1959     @Test(dataProvider="plusNanos_fromZero", groups={"tck"})
1960     public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
1961         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1962         LocalDateTime t = base.plusNanos(nanoseconds);
1963 
1964         assertEquals(date, t.toLocalDate());
1965         assertEquals(hour, t.getHour());
1966         assertEquals(min, t.getMinute());
1967         assertEquals(sec, t.getSecond());
1968         assertEquals(nanos, t.getNano());
1969     }
1970 
1971     @Test(groups={"tck"})
1972     public void test_plusNanos_noChange_oneDay() {
1973         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L);
1974         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
1975     }
1976 
1977     //-----------------------------------------------------------------------
1978     // minus(TemporalAmount)
1979     //-----------------------------------------------------------------------
1980     @Test
1981     public void test_minus_TemporalAmount_positiveMonths() {
1982         MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS);
1983         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
1984         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
1985     }
1986 
1987     @Test
1988     public void test_minus_TemporalAmount_negativeDays() {
1989         MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS);
1990         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
1991         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));


1994     @Test(expectedExceptions=DateTimeException.class)
1995     public void test_minus_TemporalAmount_invalidTooLarge() {
1996         MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS);
1997         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(period);
1998     }
1999 
2000     @Test(expectedExceptions=DateTimeException.class)
2001     public void test_minus_TemporalAmount_invalidTooSmall() {
2002         MockSimplePeriod period = MockSimplePeriod.of(1, YEARS);
2003         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period);
2004     }
2005 
2006     @Test(expectedExceptions=NullPointerException.class)
2007     public void test_minus_TemporalAmount_null() {
2008         TEST_2007_07_15_12_30_40_987654321.minus((TemporalAmount) null);
2009     }
2010 
2011     //-----------------------------------------------------------------------
2012     // minus(long,TemporalUnit)
2013     //-----------------------------------------------------------------------
2014     @Test(groups={"tck"})
2015     public void test_minus_longTemporalUnit_positiveMonths() {
2016         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(7, ChronoUnit.MONTHS);
2017         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
2018     }
2019 
2020     @Test(groups={"tck"})
2021     public void test_minus_longTemporalUnit_negativeDays() {
2022         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(-25, ChronoUnit.DAYS);
2023         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));
2024     }
2025 
2026     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2027     public void test_minus_longTemporalUnit_null() {
2028         TEST_2007_07_15_12_30_40_987654321.minus(1, (TemporalUnit) null);
2029     }
2030 
2031     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2032     public void test_minus_longTemporalUnit_invalidTooLarge() {
2033         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(-1, ChronoUnit.YEARS);
2034     }
2035 
2036     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2037     public void test_minus_longTemporalUnit_invalidTooSmall() {
2038         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(1, ChronoUnit.YEARS);
2039     }
2040 
2041     //-----------------------------------------------------------------------
2042     // minusYears()
2043     //-----------------------------------------------------------------------
2044     @Test(groups={"tck"})
2045     public void test_minusYears_int_normal() {
2046         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(1);
2047         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
2048     }
2049 
2050     @Test(groups={"tck"})
2051     public void test_minusYears_int_negative() {
2052         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1);
2053         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
2054     }
2055 
2056     @Test(groups={"tck"})
2057     public void test_minusYears_int_adjustDay() {
2058         LocalDateTime t = createDateMidnight(2008, 2, 29).minusYears(1);
2059         check(t, 2007, 2, 28, 0, 0, 0, 0);
2060     }
2061 
2062     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2063     public void test_minusYears_int_invalidTooLarge() {
2064         createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1);
2065     }
2066 
2067     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2068     public void test_minusYears_int_invalidTooSmall() {
2069         createDateMidnight(Year.MIN_VALUE, 1, 1).minusYears(1);
2070     }
2071 
2072     //-----------------------------------------------------------------------
2073     // minusMonths()
2074     //-----------------------------------------------------------------------
2075     @Test(groups={"tck"})
2076     public void test_minusMonths_int_normal() {
2077         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(1);
2078         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
2079     }
2080 
2081     @Test(groups={"tck"})
2082     public void test_minusMonths_int_overYears() {
2083         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(25);
2084         check(t, 2005, 6, 15, 12, 30, 40, 987654321);
2085     }
2086 
2087     @Test(groups={"tck"})
2088     public void test_minusMonths_int_negative() {
2089         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-1);
2090         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
2091     }
2092 
2093     @Test(groups={"tck"})
2094     public void test_minusMonths_int_negativeAcrossYear() {
2095         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-7);
2096         check(t, 2008, 2, 15, 12, 30, 40, 987654321);
2097     }
2098 
2099     @Test(groups={"tck"})
2100     public void test_minusMonths_int_negativeOverYears() {
2101         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-31);
2102         check(t, 2010, 2, 15, 12, 30, 40, 987654321);
2103     }
2104 
2105     @Test(groups={"tck"})
2106     public void test_minusMonths_int_adjustDayFromLeapYear() {
2107         LocalDateTime t = createDateMidnight(2008, 2, 29).minusMonths(12);
2108         check(t, 2007, 2, 28, 0, 0, 0, 0);
2109     }
2110 
2111     @Test(groups={"tck"})
2112     public void test_minusMonths_int_adjustDayFromMonthLength() {
2113         LocalDateTime t = createDateMidnight(2007, 3, 31).minusMonths(1);
2114         check(t, 2007, 2, 28, 0, 0, 0, 0);
2115     }
2116 
2117     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2118     public void test_minusMonths_int_invalidTooLarge() {
2119         createDateMidnight(Year.MAX_VALUE, 12, 1).minusMonths(-1);
2120     }
2121 
2122     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2123     public void test_minusMonths_int_invalidTooSmall() {
2124         createDateMidnight(Year.MIN_VALUE, 1, 1).minusMonths(1);
2125     }
2126 
2127     //-----------------------------------------------------------------------
2128     // minusWeeks()
2129     //-----------------------------------------------------------------------
2130     @DataProvider(name="sampleMinusWeeksSymmetry")
2131     Object[][] provider_sampleMinusWeeksSymmetry() {
2132         return new Object[][] {
2133             {createDateMidnight(-1, 1, 1)},
2134             {createDateMidnight(-1, 2, 28)},
2135             {createDateMidnight(-1, 3, 1)},
2136             {createDateMidnight(-1, 12, 31)},
2137             {createDateMidnight(0, 1, 1)},
2138             {createDateMidnight(0, 2, 28)},
2139             {createDateMidnight(0, 2, 29)},
2140             {createDateMidnight(0, 3, 1)},
2141             {createDateMidnight(0, 12, 31)},
2142             {createDateMidnight(2007, 1, 1)},
2143             {createDateMidnight(2007, 2, 28)},
2144             {createDateMidnight(2007, 3, 1)},
2145             {createDateMidnight(2007, 12, 31)},
2146             {createDateMidnight(2008, 1, 1)},
2147             {createDateMidnight(2008, 2, 28)},
2148             {createDateMidnight(2008, 2, 29)},
2149             {createDateMidnight(2008, 3, 1)},
2150             {createDateMidnight(2008, 12, 31)},
2151             {createDateMidnight(2099, 1, 1)},
2152             {createDateMidnight(2099, 2, 28)},
2153             {createDateMidnight(2099, 3, 1)},
2154             {createDateMidnight(2099, 12, 31)},
2155             {createDateMidnight(2100, 1, 1)},
2156             {createDateMidnight(2100, 2, 28)},
2157             {createDateMidnight(2100, 3, 1)},
2158             {createDateMidnight(2100, 12, 31)},
2159         };
2160     }
2161 
2162     @Test(dataProvider="sampleMinusWeeksSymmetry", groups={"tck"})
2163     public void test_minusWeeks_symmetry(LocalDateTime reference) {
2164         for (int weeks = 0; weeks < 365 * 8; weeks++) {
2165             LocalDateTime t = reference.minusWeeks(weeks).minusWeeks(-weeks);
2166             assertEquals(t, reference);
2167 
2168             t = reference.minusWeeks(-weeks).minusWeeks(weeks);
2169             assertEquals(t, reference);
2170         }
2171     }
2172 
2173     @Test(groups={"tck"})
2174     public void test_minusWeeks_normal() {
2175         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(1);
2176         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
2177     }
2178 
2179     @Test(groups={"tck"})
2180     public void test_minusWeeks_overMonths() {
2181         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9);
2182         check(t, 2007, 5, 13, 12, 30, 40, 987654321);
2183     }
2184 
2185     @Test(groups={"tck"})
2186     public void test_minusWeeks_overYears() {
2187         LocalDateTime t = LocalDateTime.of(2008, 7, 13, 12, 30, 40, 987654321).minusWeeks(52);
2188         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2189     }
2190 
2191     @Test(groups={"tck"})
2192     public void test_minusWeeks_overLeapYears() {
2193         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1).minusWeeks(104);
2194         check(t, 2006, 7, 18, 12, 30, 40, 987654321);
2195     }
2196 
2197     @Test(groups={"tck"})
2198     public void test_minusWeeks_negative() {
2199         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-1);
2200         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
2201     }
2202 
2203     @Test(groups={"tck"})
2204     public void test_minusWeeks_negativeAcrossYear() {
2205         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-28);
2206         check(t, 2008, 1, 27, 12, 30, 40, 987654321);
2207     }
2208 
2209     @Test(groups={"tck"})
2210     public void test_minusWeeks_negativeOverYears() {
2211         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-104);
2212         check(t, 2009, 7, 12, 12, 30, 40, 987654321);
2213     }
2214 
2215     @Test(groups={"tck"})
2216     public void test_minusWeeks_maximum() {
2217         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).minusWeeks(-1);
2218         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2219     }
2220 
2221     @Test(groups={"tck"})
2222     public void test_minusWeeks_minimum() {
2223         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).minusWeeks(1);
2224         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2225     }
2226 
2227     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2228     public void test_minusWeeks_invalidTooLarge() {
2229         createDateMidnight(Year.MAX_VALUE, 12, 25).minusWeeks(-1);
2230     }
2231 
2232     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2233     public void test_minusWeeks_invalidTooSmall() {
2234         createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1);
2235     }
2236 
2237     //-----------------------------------------------------------------------
2238     // minusDays()
2239     //-----------------------------------------------------------------------
2240     @DataProvider(name="sampleMinusDaysSymmetry")
2241     Object[][] provider_sampleMinusDaysSymmetry() {
2242         return new Object[][] {
2243             {createDateMidnight(-1, 1, 1)},
2244             {createDateMidnight(-1, 2, 28)},
2245             {createDateMidnight(-1, 3, 1)},
2246             {createDateMidnight(-1, 12, 31)},
2247             {createDateMidnight(0, 1, 1)},
2248             {createDateMidnight(0, 2, 28)},
2249             {createDateMidnight(0, 2, 29)},
2250             {createDateMidnight(0, 3, 1)},
2251             {createDateMidnight(0, 12, 31)},
2252             {createDateMidnight(2007, 1, 1)},
2253             {createDateMidnight(2007, 2, 28)},
2254             {createDateMidnight(2007, 3, 1)},
2255             {createDateMidnight(2007, 12, 31)},
2256             {createDateMidnight(2008, 1, 1)},
2257             {createDateMidnight(2008, 2, 28)},
2258             {createDateMidnight(2008, 2, 29)},
2259             {createDateMidnight(2008, 3, 1)},
2260             {createDateMidnight(2008, 12, 31)},
2261             {createDateMidnight(2099, 1, 1)},
2262             {createDateMidnight(2099, 2, 28)},
2263             {createDateMidnight(2099, 3, 1)},
2264             {createDateMidnight(2099, 12, 31)},
2265             {createDateMidnight(2100, 1, 1)},
2266             {createDateMidnight(2100, 2, 28)},
2267             {createDateMidnight(2100, 3, 1)},
2268             {createDateMidnight(2100, 12, 31)},
2269         };
2270     }
2271 
2272     @Test(dataProvider="sampleMinusDaysSymmetry", groups={"tck"})
2273     public void test_minusDays_symmetry(LocalDateTime reference) {
2274         for (int days = 0; days < 365 * 8; days++) {
2275             LocalDateTime t = reference.minusDays(days).minusDays(-days);
2276             assertEquals(t, reference);
2277 
2278             t = reference.minusDays(-days).minusDays(days);
2279             assertEquals(t, reference);
2280         }
2281     }
2282 
2283     @Test(groups={"tck"})
2284     public void test_minusDays_normal() {
2285         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(1);
2286         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
2287     }
2288 
2289     @Test(groups={"tck"})
2290     public void test_minusDays_overMonths() {
2291         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62);
2292         check(t, 2007, 5, 14, 12, 30, 40, 987654321);
2293     }
2294 
2295     @Test(groups={"tck"})
2296     public void test_minusDays_overYears() {
2297         LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367);
2298         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2299     }
2300 
2301     @Test(groups={"tck"})
2302     public void test_minusDays_overLeapYears() {
2303         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(2).minusDays(365 + 366);
2304         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2305     }
2306 
2307     @Test(groups={"tck"})
2308     public void test_minusDays_negative() {
2309         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-1);
2310         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
2311     }
2312 
2313     @Test(groups={"tck"})
2314     public void test_minusDays_negativeAcrossYear() {
2315         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-169);
2316         check(t, 2007, 12, 31, 12, 30, 40, 987654321);
2317     }
2318 
2319     @Test(groups={"tck"})
2320     public void test_minusDays_negativeOverYears() {
2321         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-731);
2322         check(t, 2009, 7, 15, 12, 30, 40, 987654321);
2323     }
2324 
2325     @Test(groups={"tck"})
2326     public void test_minusDays_maximum() {
2327         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).minusDays(-1);
2328         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2329     }
2330 
2331     @Test(groups={"tck"})
2332     public void test_minusDays_minimum() {
2333         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).minusDays(1);
2334         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2335     }
2336 
2337     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2338     public void test_minusDays_invalidTooLarge() {
2339         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1);
2340     }
2341 
2342     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2343     public void test_minusDays_invalidTooSmall() {
2344         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1);
2345     }
2346 
2347     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
2348     public void test_minusDays_overflowTooLarge() {
2349         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(Long.MIN_VALUE);
2350     }
2351 
2352     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
2353     public void test_minusDays_overflowTooSmall() {
2354         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(Long.MAX_VALUE);
2355     }
2356 
2357     //-----------------------------------------------------------------------
2358     // minusHours()
2359     //-----------------------------------------------------------------------
2360     @Test(groups={"tck"})
2361     public void test_minusHours_one() {
2362         LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2363         LocalDate d = t.toLocalDate();
2364 
2365         for (int i = 0; i < 50; i++) {
2366             t = t.minusHours(1);
2367 
2368             if (i % 24 == 0) {
2369                 d = d.minusDays(1);
2370             }
2371 
2372             assertEquals(t.toLocalDate(), d);
2373             assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
2374         }
2375     }
2376 
2377     @Test(groups={"tck"})
2378     public void test_minusHours_fromZero() {
2379         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2380         LocalDate d = base.toLocalDate().plusDays(2);
2381         LocalTime t = LocalTime.of(3, 0);
2382 
2383         for (int i = -50; i < 50; i++) {
2384             LocalDateTime dt = base.minusHours(i);
2385             t = t.minusHours(1);
2386 
2387             if (t.getHour() == 23) {
2388                 d = d.minusDays(1);
2389             }
2390 
2391             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
2392             assertEquals(dt.toLocalTime(), t);
2393         }
2394     }
2395 
2396     @Test(groups={"tck"})
2397     public void test_minusHours_fromOne() {
2398         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
2399         LocalDate d = base.toLocalDate().plusDays(2);
2400         LocalTime t = LocalTime.of(4, 0);
2401 
2402         for (int i = -50; i < 50; i++) {
2403             LocalDateTime dt = base.minusHours(i);
2404 
2405             t = t.minusHours(1);
2406 
2407             if (t.getHour() == 23) {
2408                 d = d.minusDays(1);
2409             }
2410 
2411             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
2412             assertEquals(dt.toLocalTime(), t);
2413         }
2414     }
2415 
2416     //-----------------------------------------------------------------------
2417     // minusMinutes()
2418     //-----------------------------------------------------------------------
2419     @Test(groups={"tck"})
2420     public void test_minusMinutes_one() {
2421         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2422         LocalDate d = t.toLocalDate().minusDays(1);
2423 
2424         int hour = 0;
2425         int min = 0;
2426 
2427         for (int i = 0; i < 70; i++) {
2428             t = t.minusMinutes(1);
2429             min--;
2430             if (min == -1) {
2431                 hour--;
2432                 min = 59;
2433 
2434                 if (hour == -1) {
2435                     hour = 23;
2436                 }
2437             }
2438             assertEquals(t.toLocalDate(), d);
2439             assertEquals(t.getHour(), hour);
2440             assertEquals(t.getMinute(), min);
2441         }
2442     }
2443 
2444     @Test(groups={"tck"})
2445     public void test_minusMinutes_fromZero() {
2446         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2447         LocalDate d = base.toLocalDate().minusDays(1);
2448         LocalTime t = LocalTime.of(22, 49);
2449 
2450         for (int i = 70; i > -70; i--) {
2451             LocalDateTime dt = base.minusMinutes(i);
2452             t = t.plusMinutes(1);
2453 
2454             if (t == LocalTime.MIDNIGHT) {
2455                 d = d.plusDays(1);
2456             }
2457 
2458             assertEquals(dt.toLocalDate(), d);
2459             assertEquals(dt.toLocalTime(), t);
2460         }
2461     }
2462 
2463     @Test(groups={"tck"})
2464     public void test_minusMinutes_noChange_oneDay() {
2465         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMinutes(24 * 60);
2466         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1));
2467     }
2468 
2469     //-----------------------------------------------------------------------
2470     // minusSeconds()
2471     //-----------------------------------------------------------------------
2472     @Test(groups={"tck"})
2473     public void test_minusSeconds_one() {
2474         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2475         LocalDate d = t.toLocalDate().minusDays(1);
2476 
2477         int hour = 0;
2478         int min = 0;
2479         int sec = 0;
2480 
2481         for (int i = 0; i < 3700; i++) {
2482             t = t.minusSeconds(1);
2483             sec--;
2484             if (sec == -1) {
2485                 min--;
2486                 sec = 59;
2487 
2488                 if (min == -1) {
2489                     hour--;
2490                     min = 59;
2491 
2492                     if (hour == -1) {


2532 
2533                         if (hour == 24) {
2534                             hour = 0;
2535                         }
2536                     }
2537                 }
2538 
2539                 if (i == 0) {
2540                     date = date.plusDays(1);
2541                 }
2542 
2543                 return ret;
2544             }
2545 
2546             public void remove() {
2547                 throw new UnsupportedOperationException();
2548             }
2549         };
2550     }
2551 
2552     @Test(dataProvider="minusSeconds_fromZero", groups={"tck"})
2553     public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
2554         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2555         LocalDateTime t = base.minusSeconds(seconds);
2556 
2557         assertEquals(date, t.toLocalDate());
2558         assertEquals(hour, t.getHour());
2559         assertEquals(min, t.getMinute());
2560         assertEquals(sec, t.getSecond());
2561     }
2562 
2563     //-----------------------------------------------------------------------
2564     // minusNanos()
2565     //-----------------------------------------------------------------------
2566     @Test(groups={"tck"})
2567     public void test_minusNanos_halfABillion() {
2568         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2569         LocalDate d = t.toLocalDate().minusDays(1);
2570 
2571         int hour = 0;
2572         int min = 0;
2573         int sec = 0;
2574         int nanos = 0;
2575 
2576         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
2577             t = t.minusNanos(500000000);
2578             nanos -= 500000000;
2579 
2580             if (nanos < 0) {
2581                 sec--;
2582                 nanos += 1000000000;
2583 
2584                 if (sec == -1) {
2585                     min--;
2586                     sec += 60;


2637                             hour++;
2638                             min = 0;
2639 
2640                             if (hour == 24) {
2641                                 hour = 0;
2642                                 date = date.plusDays(1);
2643                             }
2644                         }
2645                     }
2646                 }
2647 
2648                 return ret;
2649             }
2650 
2651             public void remove() {
2652                 throw new UnsupportedOperationException();
2653             }
2654         };
2655     }
2656 
2657     @Test(dataProvider="minusNanos_fromZero", groups={"tck"})
2658     public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
2659         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2660         LocalDateTime t = base.minusNanos(nanoseconds);
2661 
2662         assertEquals(date, t.toLocalDate());
2663         assertEquals(hour, t.getHour());
2664         assertEquals(min, t.getMinute());
2665         assertEquals(sec, t.getSecond());
2666         assertEquals(nanos, t.getNano());
2667     }
2668 
2669     //-----------------------------------------------------------------------


















































































































































































2670     // atOffset()
2671     //-----------------------------------------------------------------------
2672     @Test(groups={"tck"})
2673     public void test_atOffset() {
2674         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2675         assertEquals(t.atOffset(OFFSET_PTWO), OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2676     }
2677 
2678     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2679     public void test_atOffset_nullZoneOffset() {
2680         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2681         t.atOffset((ZoneOffset) null);
2682     }
2683 
2684     //-----------------------------------------------------------------------
2685     // atZone()
2686     //-----------------------------------------------------------------------
2687     @Test(groups={"tck"})
2688     public void test_atZone() {
2689         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2690         assertEquals(t.atZone(ZONE_PARIS),
2691                 ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS));
2692     }
2693 
2694     @Test(groups={"tck"})
2695     public void test_atZone_Offset() {
2696         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2697         assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2698     }
2699 
2700     @Test(groups={"tck"})
2701     public void test_atZone_dstGap() {
2702         LocalDateTime t = LocalDateTime.of(2007, 4, 1, 0, 0);
2703         assertEquals(t.atZone(ZONE_GAZA),
2704                 ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA));
2705     }
2706 
2707     @Test(groups={"tck"})
2708     public void test_atZone_dstOverlap() {
2709         LocalDateTime t = LocalDateTime.of(2007, 10, 28, 2, 30);
2710         assertEquals(t.atZone(ZONE_PARIS),
2711                 ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, ZONE_PARIS));
2712     }
2713 
2714     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2715     public void test_atZone_nullTimeZone() {
2716         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2717         t.atZone((ZoneId) null);
2718     }
2719 
2720     //-----------------------------------------------------------------------
2721     // toEpochSecond()
2722     //-----------------------------------------------------------------------
2723     @Test(groups={"tck"})
2724     public void test_toEpochSecond_afterEpoch() {
2725         for (int i = -5; i < 5; i++) {
2726             ZoneOffset offset = ZoneOffset.ofHours(i);
2727             for (int j = 0; j < 100000; j++) {
2728                 LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j);
2729                 assertEquals(a.toEpochSecond(offset), j - i * 3600);
2730             }
2731         }
2732     }
2733 
2734     @Test(groups={"tck"})
2735     public void test_toEpochSecond_beforeEpoch() {
2736         for (int i = 0; i < 100000; i++) {
2737             LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).minusSeconds(i);
2738             assertEquals(a.toEpochSecond(ZoneOffset.UTC), -i);
2739         }
2740     }
2741 
2742     //-----------------------------------------------------------------------
2743     // compareTo()
2744     //-----------------------------------------------------------------------
2745     @Test(groups={"tck"})
2746     public void test_comparisons() {
2747         test_comparisons_LocalDateTime(
2748             LocalDate.of(Year.MIN_VALUE, 1, 1),
2749             LocalDate.of(Year.MIN_VALUE, 12, 31),
2750             LocalDate.of(-1, 1, 1),
2751             LocalDate.of(-1, 12, 31),
2752             LocalDate.of(0, 1, 1),
2753             LocalDate.of(0, 12, 31),
2754             LocalDate.of(1, 1, 1),
2755             LocalDate.of(1, 12, 31),
2756             LocalDate.of(2008, 1, 1),
2757             LocalDate.of(2008, 2, 29),
2758             LocalDate.of(2008, 12, 31),
2759             LocalDate.of(Year.MAX_VALUE, 1, 1),
2760             LocalDate.of(Year.MAX_VALUE, 12, 31)
2761         );
2762     }
2763 
2764     void test_comparisons_LocalDateTime(LocalDate... localDates) {
2765         test_comparisons_LocalDateTime(


2806                 if (i < j) {
2807                     assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
2808                     assertEquals(a.isBefore(b), true, a + " <=> " + b);
2809                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2810                     assertEquals(a.equals(b), false, a + " <=> " + b);
2811                 } else if (i > j) {
2812                     assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
2813                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2814                     assertEquals(a.isAfter(b), true, a + " <=> " + b);
2815                     assertEquals(a.equals(b), false, a + " <=> " + b);
2816                 } else {
2817                     assertEquals(a.compareTo(b), 0, a + " <=> " + b);
2818                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2819                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2820                     assertEquals(a.equals(b), true, a + " <=> " + b);
2821                 }
2822             }
2823         }
2824     }
2825 
2826     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2827     public void test_compareTo_ObjectNull() {
2828         TEST_2007_07_15_12_30_40_987654321.compareTo(null);
2829     }
2830 
2831     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2832     public void test_isBefore_ObjectNull() {
2833         TEST_2007_07_15_12_30_40_987654321.isBefore(null);
2834     }
2835 
2836     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2837     public void test_isAfter_ObjectNull() {
2838         TEST_2007_07_15_12_30_40_987654321.isAfter(null);
2839     }
2840 
2841     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
2842     @SuppressWarnings({"unchecked", "rawtypes"})
2843     public void compareToNonLocalDateTime() {
2844        Comparable c = TEST_2007_07_15_12_30_40_987654321;
2845        c.compareTo(new Object());
2846     }
2847 
2848     //-----------------------------------------------------------------------
2849     // equals()
2850     //-----------------------------------------------------------------------
2851     @DataProvider(name="sampleDateTimes")
2852     Iterator<Object[]> provider_sampleDateTimes() {
2853         return new Iterator<Object[]>() {
2854             Object[][] sampleDates = provider_sampleDates();
2855             Object[][] sampleTimes = provider_sampleTimes();
2856             int datesIndex = 0;
2857             int timesIndex = 0;
2858 
2859             public boolean hasNext() {
2860                 return datesIndex < sampleDates.length;
2861             }


2866 
2867                 Object[] ret = new Object[sampleDate.length + sampleTime.length];
2868 
2869                 System.arraycopy(sampleDate, 0, ret, 0, sampleDate.length);
2870                 System.arraycopy(sampleTime, 0, ret, sampleDate.length, sampleTime.length);
2871 
2872                 if (++timesIndex == sampleTimes.length) {
2873                     datesIndex++;
2874                     timesIndex = 0;
2875                 }
2876 
2877                 return ret;
2878             }
2879 
2880             public void remove() {
2881                 throw new UnsupportedOperationException();
2882             }
2883         };
2884     }
2885 
2886     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2887     public void test_equals_true(int y, int m, int d, int h, int mi, int s, int n) {
2888         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2889         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
2890         assertTrue(a.equals(b));
2891     }
2892 
2893     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2894     public void test_equals_false_year_differs(int y, int m, int d, int h, int mi, int s, int n) {
2895         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2896         LocalDateTime b = LocalDateTime.of(y + 1, m, d, h, mi, s, n);
2897         assertFalse(a.equals(b));
2898     }
2899 
2900     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2901     public void test_equals_false_month_differs(int y, int m, int d, int h, int mi, int s, int n) {
2902         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2903         LocalDateTime b = LocalDateTime.of(y, m + 1, d, h, mi, s, n);
2904         assertFalse(a.equals(b));
2905     }
2906 
2907     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2908     public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) {
2909         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2910         LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n);
2911         assertFalse(a.equals(b));
2912     }
2913 
2914     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2915     public void test_equals_false_hour_differs(int y, int m, int d, int h, int mi, int s, int n) {
2916         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2917         LocalDateTime b = LocalDateTime.of(y, m, d, h + 1, mi, s, n);
2918         assertFalse(a.equals(b));
2919     }
2920 
2921     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2922     public void test_equals_false_minute_differs(int y, int m, int d, int h, int mi, int s, int n) {
2923         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2924         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi + 1, s, n);
2925         assertFalse(a.equals(b));
2926     }
2927 
2928     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2929     public void test_equals_false_second_differs(int y, int m, int d, int h, int mi, int s, int n) {
2930         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2931         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s + 1, n);
2932         assertFalse(a.equals(b));
2933     }
2934 
2935     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2936     public void test_equals_false_nano_differs(int y, int m, int d, int h, int mi, int s, int n) {
2937         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2938         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n + 1);
2939         assertFalse(a.equals(b));
2940     }
2941 
2942     @Test(groups={"tck"})
2943     public void test_equals_itself_true() {
2944         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(TEST_2007_07_15_12_30_40_987654321), true);
2945     }
2946 
2947     @Test(groups={"tck"})
2948     public void test_equals_string_false() {
2949         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals("2007-07-15T12:30:40.987654321"), false);
2950     }
2951 
2952     @Test(groups={"tck"})
2953     public void test_equals_null_false() {
2954         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(null), false);
2955     }
2956 
2957     //-----------------------------------------------------------------------
2958     // hashCode()
2959     //-----------------------------------------------------------------------
2960     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2961     public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) {
2962         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2963         assertEquals(a.hashCode(), a.hashCode());
2964         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
2965         assertEquals(a.hashCode(), b.hashCode());
2966     }
2967 
2968     //-----------------------------------------------------------------------
2969     // toString()
2970     //-----------------------------------------------------------------------
2971     @DataProvider(name="sampleToString")
2972     Object[][] provider_sampleToString() {
2973         return new Object[][] {
2974             {2008, 7, 5, 2, 1, 0, 0, "2008-07-05T02:01"},
2975             {2007, 12, 31, 23, 59, 1, 0, "2007-12-31T23:59:01"},
2976             {999, 12, 31, 23, 59, 59, 990000000, "0999-12-31T23:59:59.990"},
2977             {-1, 1, 2, 23, 59, 59, 999990000, "-0001-01-02T23:59:59.999990"},
2978             {-2008, 1, 2, 23, 59, 59, 999999990, "-2008-01-02T23:59:59.999999990"},
2979         };
2980     }
2981 
2982     @Test(dataProvider="sampleToString", groups={"tck"})
2983     public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
2984         LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
2985         String str = t.toString();
2986         assertEquals(str, expected);
2987     }
2988 
2989     //-----------------------------------------------------------------------
2990     // toString(DateTimeFormatter)
2991     //-----------------------------------------------------------------------
2992     @Test(groups={"tck"})
2993     public void test_toString_formatter() {
2994         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2995         String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(f);
2996         assertEquals(t, "2010 12 3 11 30 45");
2997     }
2998 
2999     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
3000     public void test_toString_formatter_null() {
3001         LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(null);
3002     }
3003 
3004 }


  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  63 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  64 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  65 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  66 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  67 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  68 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  69 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  70 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  71 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  72 import static java.time.temporal.ChronoField.EPOCH_DAY;

  73 import static java.time.temporal.ChronoField.ERA;
  74 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  75 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  76 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  77 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  78 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  79 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  80 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  81 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  82 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  83 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  84 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  85 import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
  86 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  87 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  88 import static java.time.temporal.ChronoField.YEAR;
  89 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  90 import static java.time.temporal.ChronoUnit.CENTURIES;
  91 import static java.time.temporal.ChronoUnit.DAYS;
  92 import static java.time.temporal.ChronoUnit.DECADES;
  93 import static java.time.temporal.ChronoUnit.HALF_DAYS;
  94 import static java.time.temporal.ChronoUnit.HOURS;
  95 import static java.time.temporal.ChronoUnit.MICROS;
  96 import static java.time.temporal.ChronoUnit.MILLENNIA;
  97 import static java.time.temporal.ChronoUnit.MILLIS;
  98 import static java.time.temporal.ChronoUnit.MINUTES;
  99 import static java.time.temporal.ChronoUnit.MONTHS;
 100 import static java.time.temporal.ChronoUnit.NANOS;
 101 import static java.time.temporal.ChronoUnit.SECONDS;
 102 import static java.time.temporal.ChronoUnit.WEEKS;
 103 import static java.time.temporal.ChronoUnit.YEARS;
 104 import static org.testng.Assert.assertEquals;
 105 import static org.testng.Assert.assertFalse;
 106 import static org.testng.Assert.assertSame;
 107 import static org.testng.Assert.assertTrue;
 108 import static org.testng.Assert.fail;
 109 
 110 import java.io.ByteArrayOutputStream;
 111 import java.io.DataOutputStream;
 112 import java.time.Clock;
 113 import java.time.DateTimeException;
 114 import java.time.DayOfWeek;
 115 import java.time.Instant;
 116 import java.time.LocalDate;
 117 import java.time.LocalDateTime;
 118 import java.time.LocalTime;
 119 import java.time.Month;
 120 import java.time.OffsetDateTime;
 121 import java.time.OffsetTime;
 122 import java.time.Year;
 123 import java.time.ZoneId;
 124 import java.time.ZoneOffset;
 125 import java.time.ZonedDateTime;
 126 import java.time.chrono.IsoChronology;
 127 import java.time.format.DateTimeFormatter;
 128 import java.time.format.DateTimeParseException;
 129 import java.time.temporal.ChronoField;
 130 import java.time.temporal.ChronoUnit;
 131 import java.time.temporal.JulianFields;

 132 import java.time.temporal.Temporal;
 133 import java.time.temporal.TemporalAccessor;
 134 import java.time.temporal.TemporalAdjuster;
 135 import java.time.temporal.TemporalAmount;
 136 import java.time.temporal.TemporalField;
 137 import java.time.temporal.TemporalQuery;
 138 import java.time.temporal.TemporalUnit;
 139 import java.util.ArrayList;
 140 import java.util.Arrays;
 141 import java.util.Iterator;
 142 import java.util.List;
 143 
 144 import org.testng.annotations.BeforeMethod;
 145 import org.testng.annotations.DataProvider;
 146 import org.testng.annotations.Test;
 147 
 148 /**
 149  * Test LocalDateTime.
 150  */
 151 @Test
 152 public class TCKLocalDateTime extends AbstractDateTimeTest {
 153 
 154     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 155     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 156     private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2);
 157     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 158     private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza");
 159 
 160     private LocalDateTime TEST_2007_07_15_12_30_40_987654321 = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 161     private LocalDateTime MAX_DATE_TIME;
 162     private LocalDateTime MIN_DATE_TIME;
 163     private Instant MAX_INSTANT;
 164     private Instant MIN_INSTANT;
 165 
 166     @BeforeMethod
 167     public void setUp() {
 168         MAX_DATE_TIME = LocalDateTime.MAX;
 169         MIN_DATE_TIME = LocalDateTime.MIN;
 170         MAX_INSTANT = MAX_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 171         MIN_INSTANT = MIN_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 172     }
 173 
 174     //-----------------------------------------------------------------------
 175     @Override
 176     protected List<TemporalAccessor> samples() {
 177         TemporalAccessor[] array = {TEST_2007_07_15_12_30_40_987654321, LocalDateTime.MAX, LocalDateTime.MIN, };
 178         return Arrays.asList(array);
 179     }
 180 
 181     @Override
 182     protected List<TemporalField> validFields() {
 183         TemporalField[] array = {
 184             NANO_OF_SECOND,
 185             NANO_OF_DAY,
 186             MICRO_OF_SECOND,


 188             MILLI_OF_SECOND,
 189             MILLI_OF_DAY,
 190             SECOND_OF_MINUTE,
 191             SECOND_OF_DAY,
 192             MINUTE_OF_HOUR,
 193             MINUTE_OF_DAY,
 194             CLOCK_HOUR_OF_AMPM,
 195             HOUR_OF_AMPM,
 196             CLOCK_HOUR_OF_DAY,
 197             HOUR_OF_DAY,
 198             AMPM_OF_DAY,
 199             DAY_OF_WEEK,
 200             ALIGNED_DAY_OF_WEEK_IN_MONTH,
 201             ALIGNED_DAY_OF_WEEK_IN_YEAR,
 202             DAY_OF_MONTH,
 203             DAY_OF_YEAR,
 204             EPOCH_DAY,
 205             ALIGNED_WEEK_OF_MONTH,
 206             ALIGNED_WEEK_OF_YEAR,
 207             MONTH_OF_YEAR,
 208             PROLEPTIC_MONTH,
 209             YEAR_OF_ERA,
 210             YEAR,
 211             ERA,
 212             JulianFields.JULIAN_DAY,
 213             JulianFields.MODIFIED_JULIAN_DAY,
 214             JulianFields.RATA_DIE,
 215         };
 216         return Arrays.asList(array);
 217     }
 218 
 219     @Override
 220     protected List<TemporalField> invalidFields() {
 221         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 222         list.removeAll(validFields());
 223         return list;
 224     }
 225 
 226     //-----------------------------------------------------------------------
 227     private void check(LocalDateTime test, int y, int m, int d, int h, int mi, int s, int n) {
 228         assertEquals(test.getYear(), y);


 265         byte[] bytes = baos.toByteArray();
 266         assertSerializedBySer(LocalDateTime.of(2012, 9, 16, 22, 17, 59, 459_000_000), bytes);
 267     }
 268 
 269     //-----------------------------------------------------------------------
 270     // constants
 271     //-----------------------------------------------------------------------
 272     @Test
 273     public void constant_MIN() {
 274         check(LocalDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
 275     }
 276 
 277     @Test
 278     public void constant_MAX() {
 279         check(LocalDateTime.MAX, Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999);
 280     }
 281 
 282     //-----------------------------------------------------------------------
 283     // now()
 284     //-----------------------------------------------------------------------
 285     @Test(timeOut=30000)  // TODO: remove when time zone loading is faster
 286     public void now() {
 287         LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone());
 288         LocalDateTime test = LocalDateTime.now();
 289         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 290         if (diff >= 100000000) {
 291             // may be date change
 292             expected = LocalDateTime.now(Clock.systemDefaultZone());
 293             test = LocalDateTime.now();
 294             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 295         }
 296         assertTrue(diff < 100000000);  // less than 0.1 secs
 297     }
 298 
 299     //-----------------------------------------------------------------------
 300     // now(ZoneId)
 301     //-----------------------------------------------------------------------
 302     @Test(expectedExceptions=NullPointerException.class)
 303     public void now_ZoneId_nullZoneId() {
 304         LocalDateTime.now((ZoneId) null);
 305     }
 306 
 307     @Test
 308     public void now_ZoneId() {
 309         ZoneId zone = ZoneId.of("UTC+01:02:03");
 310         LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
 311         LocalDateTime test = LocalDateTime.now(zone);
 312         for (int i = 0; i < 100; i++) {
 313             if (expected.equals(test)) {
 314                 return;
 315             }
 316             expected = LocalDateTime.now(Clock.system(zone));
 317             test = LocalDateTime.now(zone);
 318         }
 319         assertEquals(test, expected);
 320     }
 321 
 322     //-----------------------------------------------------------------------
 323     // now(Clock)
 324     //-----------------------------------------------------------------------
 325     @Test(expectedExceptions=NullPointerException.class)
 326     public void now_Clock_nullClock() {
 327         LocalDateTime.now((Clock) null);
 328     }
 329 
 330     @Test
 331     public void now_Clock_allSecsInDay_utc() {
 332         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 333             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 334             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 335             LocalDateTime test = LocalDateTime.now(clock);
 336             assertEquals(test.getYear(), 1970);
 337             assertEquals(test.getMonth(), Month.JANUARY);
 338             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 339             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 340             assertEquals(test.getMinute(), (i / 60) % 60);
 341             assertEquals(test.getSecond(), i % 60);
 342             assertEquals(test.getNano(), 123456789);
 343         }
 344     }
 345 
 346     @Test
 347     public void now_Clock_allSecsInDay_offset() {
 348         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 349             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 350             Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
 351             LocalDateTime test = LocalDateTime.now(clock);
 352             assertEquals(test.getYear(), 1970);
 353             assertEquals(test.getMonth(), Month.JANUARY);
 354             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
 355             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 356             assertEquals(test.getMinute(), (i / 60) % 60);
 357             assertEquals(test.getSecond(), i % 60);
 358             assertEquals(test.getNano(), 123456789);
 359         }
 360     }
 361 
 362     @Test
 363     public void now_Clock_allSecsInDay_beforeEpoch() {
 364         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 365         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 366             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 367             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 368             LocalDateTime test = LocalDateTime.now(clock);
 369             assertEquals(test.getYear(), 1969);
 370             assertEquals(test.getMonth(), Month.DECEMBER);
 371             assertEquals(test.getDayOfMonth(), 31);
 372             expected = expected.minusSeconds(1);
 373             assertEquals(test.toLocalTime(), expected);
 374         }
 375     }
 376 
 377     //-----------------------------------------------------------------------
 378     @Test
 379     public void now_Clock_maxYear() {
 380         Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC);
 381         LocalDateTime test = LocalDateTime.now(clock);
 382         assertEquals(test, MAX_DATE_TIME);
 383     }
 384 
 385     @Test(expectedExceptions=DateTimeException.class)
 386     public void now_Clock_tooBig() {
 387         Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC);
 388         LocalDateTime.now(clock);
 389     }
 390 
 391     @Test
 392     public void now_Clock_minYear() {
 393         Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC);
 394         LocalDateTime test = LocalDateTime.now(clock);
 395         assertEquals(test, MIN_DATE_TIME);
 396     }
 397 
 398     @Test(expectedExceptions=DateTimeException.class)
 399     public void now_Clock_tooLow() {
 400         Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC);
 401         LocalDateTime.now(clock);
 402     }
 403 
 404     //-----------------------------------------------------------------------
 405     // of() factories
 406     //-----------------------------------------------------------------------
 407     //-----------------------------------------------------------------------
 408     @Test
 409     public void factory_of_4intsMonth() {
 410         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30);
 411         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 412     }
 413 
 414     @Test(expectedExceptions=DateTimeException.class)
 415     public void factory_of_4intsMonth_yearTooLow() {
 416         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30);
 417     }
 418 
 419     @Test(expectedExceptions=NullPointerException.class)
 420     public void factory_of_4intsMonth_nullMonth() {
 421         LocalDateTime.of(2007, null, 15, 12, 30);
 422     }
 423 
 424     @Test(expectedExceptions=DateTimeException.class)
 425     public void factory_of_4intsMonth_dayTooLow() {
 426         LocalDateTime.of(2007, Month.JULY, -1, 12, 30);
 427     }
 428 
 429     @Test(expectedExceptions=DateTimeException.class)
 430     public void factory_of_4intsMonth_dayTooHigh() {
 431         LocalDateTime.of(2007, Month.JULY, 32, 12, 30);
 432     }
 433 
 434     @Test(expectedExceptions=DateTimeException.class)
 435     public void factory_of_4intsMonth_hourTooLow() {
 436         LocalDateTime.of(2007, Month.JULY, 15, -1, 30);
 437     }
 438 
 439     @Test(expectedExceptions=DateTimeException.class)
 440     public void factory_of_4intsMonth_hourTooHigh() {
 441         LocalDateTime.of(2007, Month.JULY, 15, 24, 30);
 442     }
 443 
 444     @Test(expectedExceptions=DateTimeException.class)
 445     public void factory_of_4intsMonth_minuteTooLow() {
 446         LocalDateTime.of(2007, Month.JULY, 15, 12, -1);
 447     }
 448 
 449     @Test(expectedExceptions=DateTimeException.class)
 450     public void factory_of_4intsMonth_minuteTooHigh() {
 451         LocalDateTime.of(2007, Month.JULY, 15, 12, 60);
 452     }
 453 
 454     //-----------------------------------------------------------------------
 455     @Test
 456     public void factory_of_5intsMonth() {
 457         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40);
 458         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 459     }
 460 
 461     @Test(expectedExceptions=DateTimeException.class)
 462     public void factory_of_5intsMonth_yearTooLow() {
 463         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40);
 464     }
 465 
 466     @Test(expectedExceptions=NullPointerException.class)
 467     public void factory_of_5intsMonth_nullMonth() {
 468         LocalDateTime.of(2007, null, 15, 12, 30, 40);
 469     }
 470 
 471     @Test(expectedExceptions=DateTimeException.class)
 472     public void factory_of_5intsMonth_dayTooLow() {
 473         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40);
 474     }
 475 
 476     @Test(expectedExceptions=DateTimeException.class)
 477     public void factory_of_5intsMonth_dayTooHigh() {
 478         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40);
 479     }
 480 
 481     @Test(expectedExceptions=DateTimeException.class)
 482     public void factory_of_5intsMonth_hourTooLow() {
 483         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40);
 484     }
 485 
 486     @Test(expectedExceptions=DateTimeException.class)
 487     public void factory_of_5intsMonth_hourTooHigh() {
 488         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40);
 489     }
 490 
 491     @Test(expectedExceptions=DateTimeException.class)
 492     public void factory_of_5intsMonth_minuteTooLow() {
 493         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40);
 494     }
 495 
 496     @Test(expectedExceptions=DateTimeException.class)
 497     public void factory_of_5intsMonth_minuteTooHigh() {
 498         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40);
 499     }
 500 
 501     @Test(expectedExceptions=DateTimeException.class)
 502     public void factory_of_5intsMonth_secondTooLow() {
 503         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1);
 504     }
 505 
 506     @Test(expectedExceptions=DateTimeException.class)
 507     public void factory_of_5intsMonth_secondTooHigh() {
 508         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60);
 509     }
 510 
 511     //-----------------------------------------------------------------------
 512     @Test
 513     public void factory_of_6intsMonth() {
 514         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 987654321);
 515         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 516     }
 517 
 518     @Test(expectedExceptions=DateTimeException.class)
 519     public void factory_of_6intsMonth_yearTooLow() {
 520         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321);
 521     }
 522 
 523     @Test(expectedExceptions=NullPointerException.class)
 524     public void factory_of_6intsMonth_nullMonth() {
 525         LocalDateTime.of(2007, null, 15, 12, 30, 40, 987654321);
 526     }
 527 
 528     @Test(expectedExceptions=DateTimeException.class)
 529     public void factory_of_6intsMonth_dayTooLow() {
 530         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40, 987654321);
 531     }
 532 
 533     @Test(expectedExceptions=DateTimeException.class)
 534     public void factory_of_6intsMonth_dayTooHigh() {
 535         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40, 987654321);
 536     }
 537 
 538     @Test(expectedExceptions=DateTimeException.class)
 539     public void factory_of_6intsMonth_hourTooLow() {
 540         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40, 987654321);
 541     }
 542 
 543     @Test(expectedExceptions=DateTimeException.class)
 544     public void factory_of_6intsMonth_hourTooHigh() {
 545         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40, 987654321);
 546     }
 547 
 548     @Test(expectedExceptions=DateTimeException.class)
 549     public void factory_of_6intsMonth_minuteTooLow() {
 550         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40, 987654321);
 551     }
 552 
 553     @Test(expectedExceptions=DateTimeException.class)
 554     public void factory_of_6intsMonth_minuteTooHigh() {
 555         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40, 987654321);
 556     }
 557 
 558     @Test(expectedExceptions=DateTimeException.class)
 559     public void factory_of_6intsMonth_secondTooLow() {
 560         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321);
 561     }
 562 
 563     @Test(expectedExceptions=DateTimeException.class)
 564     public void factory_of_6intsMonth_secondTooHigh() {
 565         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60, 987654321);
 566     }
 567 
 568     @Test(expectedExceptions=DateTimeException.class)
 569     public void factory_of_6intsMonth_nanoTooLow() {
 570         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, -1);
 571     }
 572 
 573     @Test(expectedExceptions=DateTimeException.class)
 574     public void factory_of_6intsMonth_nanoTooHigh() {
 575         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 1000000000);
 576     }
 577 
 578     //-----------------------------------------------------------------------
 579     @Test
 580     public void factory_of_5ints() {
 581         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30);
 582         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 583     }
 584 
 585     @Test(expectedExceptions=DateTimeException.class)
 586     public void factory_of_5ints_yearTooLow() {
 587         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30);
 588     }
 589 
 590     @Test(expectedExceptions=DateTimeException.class)
 591     public void factory_of_5ints_monthTooLow() {
 592         LocalDateTime.of(2007, 0, 15, 12, 30);
 593     }
 594 
 595     @Test(expectedExceptions=DateTimeException.class)
 596     public void factory_of_5ints_monthTooHigh() {
 597         LocalDateTime.of(2007, 13, 15, 12, 30);
 598     }
 599 
 600     @Test(expectedExceptions=DateTimeException.class)
 601     public void factory_of_5ints_dayTooLow() {
 602         LocalDateTime.of(2007, 7, -1, 12, 30);
 603     }
 604 
 605     @Test(expectedExceptions=DateTimeException.class)
 606     public void factory_of_5ints_dayTooHigh() {
 607         LocalDateTime.of(2007, 7, 32, 12, 30);
 608     }
 609 
 610     @Test(expectedExceptions=DateTimeException.class)
 611     public void factory_of_5ints_hourTooLow() {
 612         LocalDateTime.of(2007, 7, 15, -1, 30);
 613     }
 614 
 615     @Test(expectedExceptions=DateTimeException.class)
 616     public void factory_of_5ints_hourTooHigh() {
 617         LocalDateTime.of(2007, 7, 15, 24, 30);
 618     }
 619 
 620     @Test(expectedExceptions=DateTimeException.class)
 621     public void factory_of_5ints_minuteTooLow() {
 622         LocalDateTime.of(2007, 7, 15, 12, -1);
 623     }
 624 
 625     @Test(expectedExceptions=DateTimeException.class)
 626     public void factory_of_5ints_minuteTooHigh() {
 627         LocalDateTime.of(2007, 7, 15, 12, 60);
 628     }
 629 
 630     //-----------------------------------------------------------------------
 631     @Test
 632     public void factory_of_6ints() {
 633         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40);
 634         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 635     }
 636 
 637     @Test(expectedExceptions=DateTimeException.class)
 638     public void factory_of_6ints_yearTooLow() {
 639         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40);
 640     }
 641 
 642     @Test(expectedExceptions=DateTimeException.class)
 643     public void factory_of_6ints_monthTooLow() {
 644         LocalDateTime.of(2007, 0, 15, 12, 30, 40);
 645     }
 646 
 647     @Test(expectedExceptions=DateTimeException.class)
 648     public void factory_of_6ints_monthTooHigh() {
 649         LocalDateTime.of(2007, 13, 15, 12, 30, 40);
 650     }
 651 
 652     @Test(expectedExceptions=DateTimeException.class)
 653     public void factory_of_6ints_dayTooLow() {
 654         LocalDateTime.of(2007, 7, -1, 12, 30, 40);
 655     }
 656 
 657     @Test(expectedExceptions=DateTimeException.class)
 658     public void factory_of_6ints_dayTooHigh() {
 659         LocalDateTime.of(2007, 7, 32, 12, 30, 40);
 660     }
 661 
 662     @Test(expectedExceptions=DateTimeException.class)
 663     public void factory_of_6ints_hourTooLow() {
 664         LocalDateTime.of(2007, 7, 15, -1, 30, 40);
 665     }
 666 
 667     @Test(expectedExceptions=DateTimeException.class)
 668     public void factory_of_6ints_hourTooHigh() {
 669         LocalDateTime.of(2007, 7, 15, 24, 30, 40);
 670     }
 671 
 672     @Test(expectedExceptions=DateTimeException.class)
 673     public void factory_of_6ints_minuteTooLow() {
 674         LocalDateTime.of(2007, 7, 15, 12, -1, 40);
 675     }
 676 
 677     @Test(expectedExceptions=DateTimeException.class)
 678     public void factory_of_6ints_minuteTooHigh() {
 679         LocalDateTime.of(2007, 7, 15, 12, 60, 40);
 680     }
 681 
 682     @Test(expectedExceptions=DateTimeException.class)
 683     public void factory_of_6ints_secondTooLow() {
 684         LocalDateTime.of(2007, 7, 15, 12, 30, -1);
 685     }
 686 
 687     @Test(expectedExceptions=DateTimeException.class)
 688     public void factory_of_6ints_secondTooHigh() {
 689         LocalDateTime.of(2007, 7, 15, 12, 30, 60);
 690     }
 691 
 692     //-----------------------------------------------------------------------
 693     @Test
 694     public void factory_of_7ints() {
 695         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 696         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 697     }
 698 
 699     @Test(expectedExceptions=DateTimeException.class)
 700     public void factory_of_7ints_yearTooLow() {
 701         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40, 987654321);
 702     }
 703 
 704     @Test(expectedExceptions=DateTimeException.class)
 705     public void factory_of_7ints_monthTooLow() {
 706         LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321);
 707     }
 708 
 709     @Test(expectedExceptions=DateTimeException.class)
 710     public void factory_of_7ints_monthTooHigh() {
 711         LocalDateTime.of(2007, 13, 15, 12, 30, 40, 987654321);
 712     }
 713 
 714     @Test(expectedExceptions=DateTimeException.class)
 715     public void factory_of_7ints_dayTooLow() {
 716         LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321);
 717     }
 718 
 719     @Test(expectedExceptions=DateTimeException.class)
 720     public void factory_of_7ints_dayTooHigh() {
 721         LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321);
 722     }
 723 
 724     @Test(expectedExceptions=DateTimeException.class)
 725     public void factory_of_7ints_hourTooLow() {
 726         LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321);
 727     }
 728 
 729     @Test(expectedExceptions=DateTimeException.class)
 730     public void factory_of_7ints_hourTooHigh() {
 731         LocalDateTime.of(2007, 7, 15, 24, 30, 40, 987654321);
 732     }
 733 
 734     @Test(expectedExceptions=DateTimeException.class)
 735     public void factory_of_7ints_minuteTooLow() {
 736         LocalDateTime.of(2007, 7, 15, 12, -1, 40, 987654321);
 737     }
 738 
 739     @Test(expectedExceptions=DateTimeException.class)
 740     public void factory_of_7ints_minuteTooHigh() {
 741         LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321);
 742     }
 743 
 744     @Test(expectedExceptions=DateTimeException.class)
 745     public void factory_of_7ints_secondTooLow() {
 746         LocalDateTime.of(2007, 7, 15, 12, 30, -1, 987654321);
 747     }
 748 
 749     @Test(expectedExceptions=DateTimeException.class)
 750     public void factory_of_7ints_secondTooHigh() {
 751         LocalDateTime.of(2007, 7, 15, 12, 30, 60, 987654321);
 752     }
 753 
 754     @Test(expectedExceptions=DateTimeException.class)
 755     public void factory_of_7ints_nanoTooLow() {
 756         LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1);
 757     }
 758 
 759     @Test(expectedExceptions=DateTimeException.class)
 760     public void factory_of_7ints_nanoTooHigh() {
 761         LocalDateTime.of(2007, 7, 15, 12, 30, 40, 1000000000);
 762     }
 763 
 764     //-----------------------------------------------------------------------
 765     @Test
 766     public void factory_of_LocalDate_LocalTime() {
 767         LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(12, 30, 40, 987654321));
 768         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 769     }
 770 
 771     @Test(expectedExceptions=NullPointerException.class)
 772     public void factory_of_LocalDate_LocalTime_nullLocalDate() {
 773         LocalDateTime.of(null, LocalTime.of(12, 30, 40, 987654321));
 774     }
 775 
 776     @Test(expectedExceptions=NullPointerException.class)
 777     public void factory_of_LocalDate_LocalTime_nullLocalTime() {
 778         LocalDateTime.of(LocalDate.of(2007, 7, 15), null);
 779     }
 780 
 781     //-----------------------------------------------------------------------
 782     // ofInstant()
 783     //-----------------------------------------------------------------------
 784     @DataProvider(name="instantFactory")
 785     Object[][] data_instantFactory() {
 786         return new Object[][] {
 787                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), ZONE_PARIS, LocalDateTime.of(1970, 1, 2, 2, 2, 4, 500)},
 788                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), OFFSET_MTWO, LocalDateTime.of(1970, 1, 1, 23, 2, 4, 500)},
 789                 {Instant.ofEpochSecond(-86400 + 4, 500), OFFSET_PTWO, LocalDateTime.of(1969, 12, 31, 2, 0, 4, 500)},
 790                 {OffsetDateTime.of(LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0), ZoneOffset.UTC).toInstant(),
 791                         ZoneOffset.UTC, LocalDateTime.MIN},
 792                 {OffsetDateTime.of(LocalDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 59, 999_999_999), ZoneOffset.UTC).toInstant(),
 793                         ZoneOffset.UTC, LocalDateTime.MAX},
 794         };
 795     }
 796 
 797     @Test(dataProvider="instantFactory")
 798     public void factory_ofInstant(Instant instant, ZoneId zone, LocalDateTime expected) {
 799         LocalDateTime test = LocalDateTime.ofInstant(instant, zone);
 800         assertEquals(test, expected);
 801     }
 802 
 803     @Test(expectedExceptions=DateTimeException.class)
 804     public void factory_ofInstant_instantTooBig() {
 805         LocalDateTime.ofInstant(Instant.MAX, OFFSET_PONE) ;
 806     }
 807 
 808     @Test(expectedExceptions=DateTimeException.class)
 809     public void factory_ofInstant_instantTooSmall() {
 810         LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ;
 811     }
 812 
 813     @Test(expectedExceptions=NullPointerException.class)
 814     public void factory_ofInstant_nullInstant() {
 815         LocalDateTime.ofInstant((Instant) null, ZONE_GAZA);
 816     }
 817 
 818     @Test(expectedExceptions=NullPointerException.class)
 819     public void factory_ofInstant_nullZone() {
 820         LocalDateTime.ofInstant(Instant.EPOCH, (ZoneId) null);
 821     }
 822 
 823     //-----------------------------------------------------------------------
 824     // ofEpochSecond()
 825     //-----------------------------------------------------------------------
 826     @Test
 827     public void factory_ofEpochSecond_longOffset_afterEpoch() {
 828         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 829         for (int i = 0; i < 100000; i++) {
 830             LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO);
 831             assertEquals(test, base.plusSeconds(i));
 832         }
 833     }
 834 
 835     @Test
 836     public void factory_ofEpochSecond_longOffset_beforeEpoch() {
 837         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 838         for (int i = 0; i < 100000; i++) {
 839             LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO);
 840             assertEquals(test, base.minusSeconds(i));
 841         }
 842     }
 843 
 844     @Test(expectedExceptions=DateTimeException.class)
 845     public void factory_ofEpochSecond_longOffset_tooBig() {
 846         LocalDateTime.ofEpochSecond(Long.MAX_VALUE, 500, OFFSET_PONE);  // TODO: better test
 847     }
 848 
 849     @Test(expectedExceptions=DateTimeException.class)
 850     public void factory_ofEpochSecond_longOffset_tooSmall() {
 851         LocalDateTime.ofEpochSecond(Long.MIN_VALUE, 500, OFFSET_PONE);  // TODO: better test
 852     }
 853 
 854     @Test(expectedExceptions=DateTimeException.class)
 855     public void factory_ofEpochSecond_badNanos_toBig() {
 856         LocalDateTime.ofEpochSecond(0, 1_000_000_000, OFFSET_PONE);
 857     }
 858 
 859     @Test(expectedExceptions=DateTimeException.class)
 860     public void factory_ofEpochSecond_badNanos_toSmall() {
 861         LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE);
 862     }
 863 
 864     @Test(expectedExceptions=NullPointerException.class)
 865     public void factory_ofEpochSecond_longOffset_nullOffset() {
 866         LocalDateTime.ofEpochSecond(0L, 500, null);
 867     }
 868 
 869     //-----------------------------------------------------------------------
 870     // from()
 871     //-----------------------------------------------------------------------
 872     @Test
 873     public void test_from_TemporalAccessor() {
 874         LocalDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30);
 875         assertEquals(LocalDateTime.from(base), base);
 876         assertEquals(LocalDateTime.from(ZonedDateTime.of(base, ZoneOffset.ofHours(2))), base);
 877     }
 878 
 879     @Test(expectedExceptions=DateTimeException.class)
 880     public void test_from_TemporalAccessor_invalid_noDerive() {
 881         LocalDateTime.from(LocalTime.of(12, 30));
 882     }
 883 
 884     @Test(expectedExceptions=NullPointerException.class)
 885     public void test_from_TemporalAccessor_null() {
 886         LocalDateTime.from((TemporalAccessor) null);
 887     }
 888 
 889     //-----------------------------------------------------------------------
 890     // parse()
 891     //-----------------------------------------------------------------------
 892     @Test(dataProvider="sampleToString")
 893     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String text) {
 894         LocalDateTime t = LocalDateTime.parse(text);
 895         assertEquals(t.getYear(), y);
 896         assertEquals(t.getMonth().getValue(), month);
 897         assertEquals(t.getDayOfMonth(), d);
 898         assertEquals(t.getHour(), h);
 899         assertEquals(t.getMinute(), m);
 900         assertEquals(t.getSecond(), s);
 901         assertEquals(t.getNano(), n);
 902     }
 903 
 904     @Test(expectedExceptions=DateTimeParseException.class)
 905     public void factory_parse_illegalValue() {
 906         LocalDateTime.parse("2008-06-32T11:15");
 907     }
 908 
 909     @Test(expectedExceptions=DateTimeParseException.class)
 910     public void factory_parse_invalidValue() {
 911         LocalDateTime.parse("2008-06-31T11:15");
 912     }
 913 
 914     @Test(expectedExceptions=NullPointerException.class)
 915     public void factory_parse_nullText() {
 916         LocalDateTime.parse((String) null);
 917     }
 918 
 919     //-----------------------------------------------------------------------
 920     // parse(DateTimeFormatter)
 921     //-----------------------------------------------------------------------
 922     @Test
 923     public void factory_parse_formatter() {
 924         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 925         LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f);
 926         assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45));
 927     }
 928 
 929     @Test(expectedExceptions=NullPointerException.class)
 930     public void factory_parse_formatter_nullText() {
 931         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 932         LocalDateTime.parse((String) null, f);
 933     }
 934 
 935     @Test(expectedExceptions=NullPointerException.class)
 936     public void factory_parse_formatter_nullFormatter() {
 937         LocalDateTime.parse("ANY", null);
 938     }
 939 
 940     //-----------------------------------------------------------------------
 941     // get(TemporalField)
 942     //-----------------------------------------------------------------------
 943     @Test
 944     public void test_get_TemporalField() {
 945         LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
 946         assertEquals(test.get(ChronoField.YEAR), 2008);
 947         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 948         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 949         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 950         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 951 
 952         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 953         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 954         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 955         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);


 963         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 964         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 965         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 966         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 967         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 968 
 969         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 970         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 971         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 972         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 973         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 974         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 975     }
 976 
 977     //-----------------------------------------------------------------------
 978     // query(TemporalQuery)
 979     //-----------------------------------------------------------------------
 980     @DataProvider(name="query")
 981     Object[][] data_query() {
 982         return new Object[][] {
 983                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.chronology(), IsoChronology.INSTANCE},
 984                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zoneId(), null},
 985                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.precision(), ChronoUnit.NANOS},
 986                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zone(), null},
 987                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.offset(), null},
 988                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localDate(), LocalDate.of(2007, 7, 15)},
 989                 {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localTime(), LocalTime.of(12, 30, 40, 987654321)},
 990         };
 991     }
 992 
 993     @Test(dataProvider="query")
 994     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 995         assertEquals(temporal.query(query), expected);
 996     }
 997 
 998     @Test(dataProvider="query")
 999     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
1000         assertEquals(query.queryFrom(temporal), expected);
1001     }
1002 
1003     @Test(expectedExceptions=NullPointerException.class)
1004     public void test_query_null() {
1005         TEST_2007_07_15_12_30_40_987654321.query(null);
1006     }
1007 
1008     //-----------------------------------------------------------------------
1009     @DataProvider(name="sampleDates")


1026             {0, 0, 1, 0},
1027             {0, 0, 1, 1},
1028             {0, 1, 0, 0},
1029             {0, 1, 0, 1},
1030             {0, 1, 1, 0},
1031             {0, 1, 1, 1},
1032             {1, 0, 0, 0},
1033             {1, 0, 0, 1},
1034             {1, 0, 1, 0},
1035             {1, 0, 1, 1},
1036             {1, 1, 0, 0},
1037             {1, 1, 0, 1},
1038             {1, 1, 1, 0},
1039             {1, 1, 1, 1},
1040         };
1041     }
1042 
1043     //-----------------------------------------------------------------------
1044     // get*()
1045     //-----------------------------------------------------------------------
1046     @Test(dataProvider="sampleDates")
1047     public void test_get_dates(int y, int m, int d) {
1048         LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30);
1049         assertEquals(a.getYear(), y);
1050         assertEquals(a.getMonth(), Month.of(m));
1051         assertEquals(a.getDayOfMonth(), d);
1052     }
1053 
1054     @Test(dataProvider="sampleDates")
1055     public void test_getDOY(int y, int m, int d) {
1056         LocalDateTime a = LocalDateTime.of(y, m, d, 12 ,30);
1057         int total = 0;
1058         for (int i = 1; i < m; i++) {
1059             total += Month.of(i).length(isIsoLeap(y));
1060         }
1061         int doy = total + d;
1062         assertEquals(a.getDayOfYear(), doy);
1063     }
1064 
1065     @Test(dataProvider="sampleTimes")
1066     public void test_get_times(int h, int m, int s, int ns) {
1067         LocalDateTime a = LocalDateTime.of(TEST_2007_07_15_12_30_40_987654321.toLocalDate(), LocalTime.of(h, m, s, ns));
1068         assertEquals(a.getHour(), h);
1069         assertEquals(a.getMinute(), m);
1070         assertEquals(a.getSecond(), s);
1071         assertEquals(a.getNano(), ns);
1072     }
1073 
1074     //-----------------------------------------------------------------------
1075     // getDayOfWeek()
1076     //-----------------------------------------------------------------------
1077     @Test
1078     public void test_getDayOfWeek() {
1079         DayOfWeek dow = DayOfWeek.MONDAY;
1080         for (Month month : Month.values()) {
1081             int length = month.length(false);
1082             for (int i = 1; i <= length; i++) {
1083                 LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i),
1084                         TEST_2007_07_15_12_30_40_987654321.toLocalTime());
1085                 assertSame(d.getDayOfWeek(), dow);
1086                 dow = dow.plus(1);
1087             }
1088         }
1089     }
1090 
1091     //-----------------------------------------------------------------------
1092     // adjustInto(Temporal)
1093     //-----------------------------------------------------------------------
1094     @DataProvider(name="adjustInto")
1095     Object[][] data_adjustInto() {
1096         return new Object[][]{
1097                 {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null},
1098                 {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null},
1099                 {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null},
1100                 {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null},
1101                 {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null},
1102                 {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null},
1103 
1104                 {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null},
1105                 {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
1106                 {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null},
1107 
1108                 {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
1109                 {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class},
1110                 {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
1111                 {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class},
1112 
1113         };
1114     }
1115 
1116     @Test(dataProvider="adjustInto")
1117     public void test_adjustInto(LocalDateTime test, Temporal temporal, Temporal expected, Class<?> expectedEx) {
1118         if (expectedEx == null) {
1119             Temporal result = test.adjustInto(temporal);
1120             assertEquals(result, expected);
1121         } else {
1122             try {
1123                 Temporal result = test.adjustInto(temporal);
1124                 fail();
1125             } catch (Exception ex) {
1126                 assertTrue(expectedEx.isInstance(ex));
1127             }
1128         }
1129     }
1130 
1131     //-----------------------------------------------------------------------
1132     // with()
1133     //-----------------------------------------------------------------------
1134     @Test
1135     public void test_with_adjustment() {
1136         final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5);
1137         TemporalAdjuster adjuster = new TemporalAdjuster() {
1138             @Override
1139             public Temporal adjustInto(Temporal dateTime) {
1140                 return sample;
1141             }
1142         };
1143         assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample);
1144     }
1145 
1146     @Test(expectedExceptions=NullPointerException.class)
1147     public void test_with_adjustment_null() {
1148         TEST_2007_07_15_12_30_40_987654321.with((TemporalAdjuster) null);
1149     }
1150 
1151     //-----------------------------------------------------------------------
1152     // withYear()
1153     //-----------------------------------------------------------------------
1154     @Test
1155     public void test_withYear_int_normal() {
1156         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withYear(2008);
1157         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1158     }
1159 
1160     @Test(expectedExceptions=DateTimeException.class)
1161     public void test_withYear_int_invalid() {
1162         TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1);
1163     }
1164 
1165     @Test
1166     public void test_withYear_int_adjustDay() {
1167         LocalDateTime t = LocalDateTime.of(2008, 2, 29, 12, 30).withYear(2007);
1168         LocalDateTime expected = LocalDateTime.of(2007, 2, 28, 12, 30);
1169         assertEquals(t, expected);
1170     }
1171 
1172     //-----------------------------------------------------------------------
1173     // withMonth()
1174     //-----------------------------------------------------------------------
1175     @Test
1176     public void test_withMonth_int_normal() {
1177         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withMonth(1);
1178         check(t, 2007, 1, 15, 12, 30, 40, 987654321);
1179     }
1180 
1181     @Test(expectedExceptions=DateTimeException.class)
1182     public void test_withMonth_int_invalid() {
1183         TEST_2007_07_15_12_30_40_987654321.withMonth(13);
1184     }
1185 
1186     @Test
1187     public void test_withMonth_int_adjustDay() {
1188         LocalDateTime t = LocalDateTime.of(2007, 12, 31, 12, 30).withMonth(11);
1189         LocalDateTime expected = LocalDateTime.of(2007, 11, 30, 12, 30);
1190         assertEquals(t, expected);
1191     }
1192 
1193     //-----------------------------------------------------------------------
1194     // withDayOfMonth()
1195     //-----------------------------------------------------------------------
1196     @Test
1197     public void test_withDayOfMonth_normal() {
1198         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfMonth(1);
1199         check(t, 2007, 7, 1, 12, 30, 40, 987654321);
1200     }
1201 
1202     @Test(expectedExceptions=DateTimeException.class)
1203     public void test_withDayOfMonth_invalid() {
1204         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(32);
1205     }
1206 
1207     @Test(expectedExceptions=DateTimeException.class)
1208     public void test_withDayOfMonth_invalidCombination() {
1209         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(31);
1210     }
1211 
1212     //-----------------------------------------------------------------------
1213     // withDayOfYear(int)
1214     //-----------------------------------------------------------------------
1215     @Test
1216     public void test_withDayOfYear_normal() {
1217         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfYear(33);
1218         assertEquals(t, LocalDateTime.of(2007, 2, 2, 12, 30, 40, 987654321));
1219     }
1220 
1221     @Test(expectedExceptions=DateTimeException.class)
1222     public void test_withDayOfYear_illegal() {
1223         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(367);
1224     }
1225 
1226     @Test(expectedExceptions=DateTimeException.class)
1227     public void test_withDayOfYear_invalid() {
1228         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(366);
1229     }
1230 
1231     //-----------------------------------------------------------------------
1232     // withHour()
1233     //-----------------------------------------------------------------------
1234     @Test
1235     public void test_withHour_normal() {
1236         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1237         for (int i = 0; i < 24; i++) {
1238             t = t.withHour(i);
1239             assertEquals(t.getHour(), i);
1240         }
1241     }
1242 
1243     @Test(expectedExceptions=DateTimeException.class)
1244     public void test_withHour_hourTooLow() {
1245         TEST_2007_07_15_12_30_40_987654321.withHour(-1);
1246     }
1247 
1248     @Test(expectedExceptions=DateTimeException.class)
1249     public void test_withHour_hourTooHigh() {
1250         TEST_2007_07_15_12_30_40_987654321.withHour(24);
1251     }
1252 
1253     //-----------------------------------------------------------------------
1254     // withMinute()
1255     //-----------------------------------------------------------------------
1256     @Test
1257     public void test_withMinute_normal() {
1258         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1259         for (int i = 0; i < 60; i++) {
1260             t = t.withMinute(i);
1261             assertEquals(t.getMinute(), i);
1262         }
1263     }
1264 
1265     @Test(expectedExceptions=DateTimeException.class)
1266     public void test_withMinute_minuteTooLow() {
1267         TEST_2007_07_15_12_30_40_987654321.withMinute(-1);
1268     }
1269 
1270     @Test(expectedExceptions=DateTimeException.class)
1271     public void test_withMinute_minuteTooHigh() {
1272         TEST_2007_07_15_12_30_40_987654321.withMinute(60);
1273     }
1274 
1275     //-----------------------------------------------------------------------
1276     // withSecond()
1277     //-----------------------------------------------------------------------
1278     @Test
1279     public void test_withSecond_normal() {
1280         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1281         for (int i = 0; i < 60; i++) {
1282             t = t.withSecond(i);
1283             assertEquals(t.getSecond(), i);
1284         }
1285     }
1286 
1287     @Test(expectedExceptions=DateTimeException.class)
1288     public void test_withSecond_secondTooLow() {
1289         TEST_2007_07_15_12_30_40_987654321.withSecond(-1);
1290     }
1291 
1292     @Test(expectedExceptions=DateTimeException.class)
1293     public void test_withSecond_secondTooHigh() {
1294         TEST_2007_07_15_12_30_40_987654321.withSecond(60);
1295     }
1296 
1297     //-----------------------------------------------------------------------
1298     // withNano()
1299     //-----------------------------------------------------------------------
1300     @Test
1301     public void test_withNanoOfSecond_normal() {
1302         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1303         t = t.withNano(1);
1304         assertEquals(t.getNano(), 1);
1305         t = t.withNano(10);
1306         assertEquals(t.getNano(), 10);
1307         t = t.withNano(100);
1308         assertEquals(t.getNano(), 100);
1309         t = t.withNano(999999999);
1310         assertEquals(t.getNano(), 999999999);
1311     }
1312 
1313     @Test(expectedExceptions=DateTimeException.class)
1314     public void test_withNanoOfSecond_nanoTooLow() {
1315         TEST_2007_07_15_12_30_40_987654321.withNano(-1);
1316     }
1317 
1318     @Test(expectedExceptions=DateTimeException.class)
1319     public void test_withNanoOfSecond_nanoTooHigh() {
1320         TEST_2007_07_15_12_30_40_987654321.withNano(1000000000);
1321     }
1322 
1323     //-----------------------------------------------------------------------
1324     // truncatedTo(TemporalUnit)
1325     //-----------------------------------------------------------------------
1326     @Test
1327     public void test_truncatedTo_normal() {
1328         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(NANOS), TEST_2007_07_15_12_30_40_987654321);
1329         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(SECONDS), TEST_2007_07_15_12_30_40_987654321.withNano(0));
1330         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(DAYS), TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT));
1331     }
1332 
1333     @Test(expectedExceptions=NullPointerException.class)
1334     public void test_truncatedTo_null() {
1335         TEST_2007_07_15_12_30_40_987654321.truncatedTo(null);
1336     }
1337 
1338     //-----------------------------------------------------------------------
1339     // plus(TemporalAmount)
1340     //-----------------------------------------------------------------------
1341     @Test
1342     public void test_plus_TemporalAmount_positiveMonths() {
1343         MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS);
1344         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1345         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1346     }
1347 
1348     @Test
1349     public void test_plus_TemporalAmount_negativeDays() {
1350         MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS);
1351         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1352         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1353     }


1355     @Test(expectedExceptions=DateTimeException.class)
1356     public void test_plus_TemporalAmount_invalidTooLarge() {
1357         MockSimplePeriod period = MockSimplePeriod.of(1, YEARS);
1358         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(period);
1359     }
1360 
1361     @Test(expectedExceptions=DateTimeException.class)
1362     public void test_plus_TemporalAmount_invalidTooSmall() {
1363         MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS);
1364         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(period);
1365     }
1366 
1367     @Test(expectedExceptions=NullPointerException.class)
1368     public void test_plus_TemporalAmount_null() {
1369         TEST_2007_07_15_12_30_40_987654321.plus((TemporalAmount) null);
1370     }
1371 
1372     //-----------------------------------------------------------------------
1373     // plus(long,TemporalUnit)
1374     //-----------------------------------------------------------------------
1375     @Test
1376     public void test_plus_longTemporalUnit_positiveMonths() {
1377         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(7, ChronoUnit.MONTHS);
1378         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1379     }
1380 
1381     @Test
1382     public void test_plus_longTemporalUnit_negativeDays() {
1383         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(-25, ChronoUnit.DAYS);
1384         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1385     }
1386 
1387     @Test(expectedExceptions=NullPointerException.class)
1388     public void test_plus_longTemporalUnit_null() {
1389         TEST_2007_07_15_12_30_40_987654321.plus(1, (TemporalUnit) null);
1390     }
1391 
1392     @Test(expectedExceptions=DateTimeException.class)
1393     public void test_plus_longTemporalUnit_invalidTooLarge() {
1394         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(1, ChronoUnit.YEARS);
1395     }
1396 
1397     @Test(expectedExceptions=DateTimeException.class)
1398     public void test_plus_longTemporalUnit_invalidTooSmall() {
1399         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(-1, ChronoUnit.YEARS);
1400     }
1401 
1402     //-----------------------------------------------------------------------
1403     // plusYears()
1404     //-----------------------------------------------------------------------
1405     @Test
1406     public void test_plusYears_int_normal() {
1407         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1);
1408         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1409     }
1410 
1411     @Test
1412     public void test_plusYears_int_negative() {
1413         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1);
1414         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
1415     }
1416 
1417     @Test
1418     public void test_plusYears_int_adjustDay() {
1419         LocalDateTime t = createDateMidnight(2008, 2, 29).plusYears(1);
1420         check(t, 2009, 2, 28, 0, 0, 0, 0);
1421     }
1422 
1423     @Test(expectedExceptions=DateTimeException.class)
1424     public void test_plusYears_int_invalidTooLarge() {
1425         createDateMidnight(Year.MAX_VALUE, 1, 1).plusYears(1);
1426     }
1427 
1428     @Test(expectedExceptions=DateTimeException.class)
1429     public void test_plusYears_int_invalidTooSmall() {
1430         LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-1);
1431     }
1432 
1433     //-----------------------------------------------------------------------
1434     // plusMonths()
1435     //-----------------------------------------------------------------------
1436     @Test
1437     public void test_plusMonths_int_normal() {
1438         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(1);
1439         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
1440     }
1441 
1442     @Test
1443     public void test_plusMonths_int_overYears() {
1444         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(25);
1445         check(t, 2009, 8, 15, 12, 30, 40, 987654321);
1446     }
1447 
1448     @Test
1449     public void test_plusMonths_int_negative() {
1450         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-1);
1451         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
1452     }
1453 
1454     @Test
1455     public void test_plusMonths_int_negativeAcrossYear() {
1456         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-7);
1457         check(t, 2006, 12, 15, 12, 30, 40, 987654321);
1458     }
1459 
1460     @Test
1461     public void test_plusMonths_int_negativeOverYears() {
1462         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-31);
1463         check(t, 2004, 12, 15, 12, 30, 40, 987654321);
1464     }
1465 
1466     @Test
1467     public void test_plusMonths_int_adjustDayFromLeapYear() {
1468         LocalDateTime t = createDateMidnight(2008, 2, 29).plusMonths(12);
1469         check(t, 2009, 2, 28, 0, 0, 0, 0);
1470     }
1471 
1472     @Test
1473     public void test_plusMonths_int_adjustDayFromMonthLength() {
1474         LocalDateTime t = createDateMidnight(2007, 3, 31).plusMonths(1);
1475         check(t, 2007, 4, 30, 0, 0, 0, 0);
1476     }
1477 
1478     @Test(expectedExceptions=DateTimeException.class)
1479     public void test_plusMonths_int_invalidTooLarge() {
1480         createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1);
1481     }
1482 
1483     @Test(expectedExceptions=DateTimeException.class)
1484     public void test_plusMonths_int_invalidTooSmall() {
1485         createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1);
1486     }
1487 
1488     //-----------------------------------------------------------------------
1489     // plusWeeks()
1490     //-----------------------------------------------------------------------
1491     @DataProvider(name="samplePlusWeeksSymmetry")
1492     Object[][] provider_samplePlusWeeksSymmetry() {
1493         return new Object[][] {
1494             {createDateMidnight(-1, 1, 1)},
1495             {createDateMidnight(-1, 2, 28)},
1496             {createDateMidnight(-1, 3, 1)},
1497             {createDateMidnight(-1, 12, 31)},
1498             {createDateMidnight(0, 1, 1)},
1499             {createDateMidnight(0, 2, 28)},
1500             {createDateMidnight(0, 2, 29)},
1501             {createDateMidnight(0, 3, 1)},
1502             {createDateMidnight(0, 12, 31)},
1503             {createDateMidnight(2007, 1, 1)},
1504             {createDateMidnight(2007, 2, 28)},
1505             {createDateMidnight(2007, 3, 1)},
1506             {createDateMidnight(2007, 12, 31)},
1507             {createDateMidnight(2008, 1, 1)},
1508             {createDateMidnight(2008, 2, 28)},
1509             {createDateMidnight(2008, 2, 29)},
1510             {createDateMidnight(2008, 3, 1)},
1511             {createDateMidnight(2008, 12, 31)},
1512             {createDateMidnight(2099, 1, 1)},
1513             {createDateMidnight(2099, 2, 28)},
1514             {createDateMidnight(2099, 3, 1)},
1515             {createDateMidnight(2099, 12, 31)},
1516             {createDateMidnight(2100, 1, 1)},
1517             {createDateMidnight(2100, 2, 28)},
1518             {createDateMidnight(2100, 3, 1)},
1519             {createDateMidnight(2100, 12, 31)},
1520         };
1521     }
1522 
1523     @Test(dataProvider="samplePlusWeeksSymmetry")
1524     public void test_plusWeeks_symmetry(LocalDateTime reference) {
1525         for (int weeks = 0; weeks < 365 * 8; weeks++) {
1526             LocalDateTime t = reference.plusWeeks(weeks).plusWeeks(-weeks);
1527             assertEquals(t, reference);
1528 
1529             t = reference.plusWeeks(-weeks).plusWeeks(weeks);
1530             assertEquals(t, reference);
1531         }
1532     }
1533 
1534     @Test
1535     public void test_plusWeeks_normal() {
1536         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(1);
1537         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
1538     }
1539 
1540     @Test
1541     public void test_plusWeeks_overMonths() {
1542         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(9);
1543         check(t, 2007, 9, 16, 12, 30, 40, 987654321);
1544     }
1545 
1546     @Test
1547     public void test_plusWeeks_overYears() {
1548         LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52);
1549         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1550     }
1551 
1552     @Test
1553     public void test_plusWeeks_overLeapYears() {
1554         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusWeeks(104);
1555         check(t, 2008, 7, 12, 12, 30, 40, 987654321);
1556     }
1557 
1558     @Test
1559     public void test_plusWeeks_negative() {
1560         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-1);
1561         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
1562     }
1563 
1564     @Test
1565     public void test_plusWeeks_negativeAcrossYear() {
1566         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-28);
1567         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1568     }
1569 
1570     @Test
1571     public void test_plusWeeks_negativeOverYears() {
1572         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-104);
1573         check(t, 2005, 7, 17, 12, 30, 40, 987654321);
1574     }
1575 
1576     @Test
1577     public void test_plusWeeks_maximum() {
1578         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).plusWeeks(1);
1579         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1580     }
1581 
1582     @Test
1583     public void test_plusWeeks_minimum() {
1584         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).plusWeeks(-1);
1585         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1586     }
1587 
1588     @Test(expectedExceptions=DateTimeException.class)
1589     public void test_plusWeeks_invalidTooLarge() {
1590         createDateMidnight(Year.MAX_VALUE, 12, 25).plusWeeks(1);
1591     }
1592 
1593     @Test(expectedExceptions=DateTimeException.class)
1594     public void test_plusWeeks_invalidTooSmall() {
1595         createDateMidnight(Year.MIN_VALUE, 1, 7).plusWeeks(-1);
1596     }
1597 
1598     //-----------------------------------------------------------------------
1599     // plusDays()
1600     //-----------------------------------------------------------------------
1601     @DataProvider(name="samplePlusDaysSymmetry")
1602     Object[][] provider_samplePlusDaysSymmetry() {
1603         return new Object[][] {
1604             {createDateMidnight(-1, 1, 1)},
1605             {createDateMidnight(-1, 2, 28)},
1606             {createDateMidnight(-1, 3, 1)},
1607             {createDateMidnight(-1, 12, 31)},
1608             {createDateMidnight(0, 1, 1)},
1609             {createDateMidnight(0, 2, 28)},
1610             {createDateMidnight(0, 2, 29)},
1611             {createDateMidnight(0, 3, 1)},
1612             {createDateMidnight(0, 12, 31)},
1613             {createDateMidnight(2007, 1, 1)},
1614             {createDateMidnight(2007, 2, 28)},
1615             {createDateMidnight(2007, 3, 1)},
1616             {createDateMidnight(2007, 12, 31)},
1617             {createDateMidnight(2008, 1, 1)},
1618             {createDateMidnight(2008, 2, 28)},
1619             {createDateMidnight(2008, 2, 29)},
1620             {createDateMidnight(2008, 3, 1)},
1621             {createDateMidnight(2008, 12, 31)},
1622             {createDateMidnight(2099, 1, 1)},
1623             {createDateMidnight(2099, 2, 28)},
1624             {createDateMidnight(2099, 3, 1)},
1625             {createDateMidnight(2099, 12, 31)},
1626             {createDateMidnight(2100, 1, 1)},
1627             {createDateMidnight(2100, 2, 28)},
1628             {createDateMidnight(2100, 3, 1)},
1629             {createDateMidnight(2100, 12, 31)},
1630         };
1631     }
1632 
1633     @Test(dataProvider="samplePlusDaysSymmetry")
1634     public void test_plusDays_symmetry(LocalDateTime reference) {
1635         for (int days = 0; days < 365 * 8; days++) {
1636             LocalDateTime t = reference.plusDays(days).plusDays(-days);
1637             assertEquals(t, reference);
1638 
1639             t = reference.plusDays(-days).plusDays(days);
1640             assertEquals(t, reference);
1641         }
1642     }
1643 
1644     @Test
1645     public void test_plusDays_normal() {
1646         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(1);
1647         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
1648     }
1649 
1650     @Test
1651     public void test_plusDays_overMonths() {
1652         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(62);
1653         check(t, 2007, 9, 15, 12, 30, 40, 987654321);
1654     }
1655 
1656     @Test
1657     public void test_plusDays_overYears() {
1658         LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366);
1659         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1660     }
1661 
1662     @Test
1663     public void test_plusDays_overLeapYears() {
1664         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusDays(365 + 366);
1665         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1666     }
1667 
1668     @Test
1669     public void test_plusDays_negative() {
1670         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-1);
1671         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
1672     }
1673 
1674     @Test
1675     public void test_plusDays_negativeAcrossYear() {
1676         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-196);
1677         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1678     }
1679 
1680     @Test
1681     public void test_plusDays_negativeOverYears() {
1682         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-730);
1683         check(t, 2005, 7, 15, 12, 30, 40, 987654321);
1684     }
1685 
1686     @Test
1687     public void test_plusDays_maximum() {
1688         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).plusDays(1);
1689         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1690     }
1691 
1692     @Test
1693     public void test_plusDays_minimum() {
1694         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).plusDays(-1);
1695         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1696     }
1697 
1698     @Test(expectedExceptions=DateTimeException.class)
1699     public void test_plusDays_invalidTooLarge() {
1700         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(1);
1701     }
1702 
1703     @Test(expectedExceptions=DateTimeException.class)
1704     public void test_plusDays_invalidTooSmall() {
1705         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(-1);
1706     }
1707 
1708     @Test(expectedExceptions=ArithmeticException.class)
1709     public void test_plusDays_overflowTooLarge() {
1710         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(Long.MAX_VALUE);
1711     }
1712 
1713     @Test(expectedExceptions=ArithmeticException.class)
1714     public void test_plusDays_overflowTooSmall() {
1715         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(Long.MIN_VALUE);
1716     }
1717 
1718     //-----------------------------------------------------------------------
1719     // plusHours()
1720     //-----------------------------------------------------------------------
1721     @Test
1722     public void test_plusHours_one() {
1723         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1724         LocalDate d = t.toLocalDate();
1725 
1726         for (int i = 0; i < 50; i++) {
1727             t = t.plusHours(1);
1728 
1729             if ((i + 1) % 24 == 0) {
1730                 d = d.plusDays(1);
1731             }
1732 
1733             assertEquals(t.toLocalDate(), d);
1734             assertEquals(t.getHour(), (i + 1) % 24);
1735         }
1736     }
1737 
1738     @Test
1739     public void test_plusHours_fromZero() {
1740         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1741         LocalDate d = base.toLocalDate().minusDays(3);
1742         LocalTime t = LocalTime.of(21, 0);
1743 
1744         for (int i = -50; i < 50; i++) {
1745             LocalDateTime dt = base.plusHours(i);
1746             t = t.plusHours(1);
1747 
1748             if (t.getHour() == 0) {
1749                 d = d.plusDays(1);
1750             }
1751 
1752             assertEquals(dt.toLocalDate(), d);
1753             assertEquals(dt.toLocalTime(), t);
1754         }
1755     }
1756 
1757     @Test
1758     public void test_plusHours_fromOne() {
1759         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
1760         LocalDate d = base.toLocalDate().minusDays(3);
1761         LocalTime t = LocalTime.of(22, 0);
1762 
1763         for (int i = -50; i < 50; i++) {
1764             LocalDateTime dt = base.plusHours(i);
1765 
1766             t = t.plusHours(1);
1767 
1768             if (t.getHour() == 0) {
1769                 d = d.plusDays(1);
1770             }
1771 
1772             assertEquals(dt.toLocalDate(), d);
1773             assertEquals(dt.toLocalTime(), t);
1774         }
1775     }
1776 
1777     //-----------------------------------------------------------------------
1778     // plusMinutes()
1779     //-----------------------------------------------------------------------
1780     @Test
1781     public void test_plusMinutes_one() {
1782         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1783         LocalDate d = t.toLocalDate();
1784 
1785         int hour = 0;
1786         int min = 0;
1787 
1788         for (int i = 0; i < 70; i++) {
1789             t = t.plusMinutes(1);
1790             min++;
1791             if (min == 60) {
1792                 hour++;
1793                 min = 0;
1794             }
1795 
1796             assertEquals(t.toLocalDate(), d);
1797             assertEquals(t.getHour(), hour);
1798             assertEquals(t.getMinute(), min);
1799         }
1800     }
1801 
1802     @Test
1803     public void test_plusMinutes_fromZero() {
1804         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1805         LocalDate d = base.toLocalDate().minusDays(1);
1806         LocalTime t = LocalTime.of(22, 49);
1807 
1808         for (int i = -70; i < 70; i++) {
1809             LocalDateTime dt = base.plusMinutes(i);
1810             t = t.plusMinutes(1);
1811 
1812             if (t == LocalTime.MIDNIGHT) {
1813                 d = d.plusDays(1);
1814             }
1815 
1816             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
1817             assertEquals(dt.toLocalTime(), t, String.valueOf(i));
1818         }
1819     }
1820 
1821     @Test
1822     public void test_plusMinutes_noChange_oneDay() {
1823         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60);
1824         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
1825     }
1826 
1827     //-----------------------------------------------------------------------
1828     // plusSeconds()
1829     //-----------------------------------------------------------------------
1830     @Test
1831     public void test_plusSeconds_one() {
1832         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1833         LocalDate d = t.toLocalDate();
1834 
1835         int hour = 0;
1836         int min = 0;
1837         int sec = 0;
1838 
1839         for (int i = 0; i < 3700; i++) {
1840             t = t.plusSeconds(1);
1841             sec++;
1842             if (sec == 60) {
1843                 min++;
1844                 sec = 0;
1845             }
1846             if (min == 60) {
1847                 hour++;
1848                 min = 0;
1849             }
1850 


1885 
1886                         if (hour == 24) {
1887                             hour = 0;
1888                         }
1889                     }
1890                 }
1891 
1892                 if (i == 0) {
1893                     date = date.plusDays(1);
1894                 }
1895 
1896                 return ret;
1897             }
1898 
1899             public void remove() {
1900                 throw new UnsupportedOperationException();
1901             }
1902         };
1903     }
1904 
1905     @Test(dataProvider="plusSeconds_fromZero")
1906     public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
1907         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1908         LocalDateTime t = base.plusSeconds(seconds);
1909 
1910         assertEquals(date, t.toLocalDate());
1911         assertEquals(hour, t.getHour());
1912         assertEquals(min, t.getMinute());
1913         assertEquals(sec, t.getSecond());
1914     }
1915 
1916     @Test
1917     public void test_plusSeconds_noChange_oneDay() {
1918         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusSeconds(24 * 60 * 60);
1919         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
1920     }
1921 
1922     //-----------------------------------------------------------------------
1923     // plusNanos()
1924     //-----------------------------------------------------------------------
1925     @Test
1926     public void test_plusNanos_halfABillion() {
1927         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1928         LocalDate d = t.toLocalDate();
1929 
1930         int hour = 0;
1931         int min = 0;
1932         int sec = 0;
1933         int nanos = 0;
1934 
1935         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
1936             t = t.plusNanos(500000000);
1937             nanos += 500000000;
1938             if (nanos == 1000000000) {
1939                 sec++;
1940                 nanos = 0;
1941             }
1942             if (sec == 60) {
1943                 min++;
1944                 sec = 0;
1945             }


1989                             hour++;
1990                             min = 0;
1991 
1992                             if (hour == 24) {
1993                                 hour = 0;
1994                                 date = date.plusDays(1);
1995                             }
1996                         }
1997                     }
1998                 }
1999 
2000                 return ret;
2001             }
2002 
2003             public void remove() {
2004                 throw new UnsupportedOperationException();
2005             }
2006         };
2007     }
2008 
2009     @Test(dataProvider="plusNanos_fromZero")
2010     public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
2011         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2012         LocalDateTime t = base.plusNanos(nanoseconds);
2013 
2014         assertEquals(date, t.toLocalDate());
2015         assertEquals(hour, t.getHour());
2016         assertEquals(min, t.getMinute());
2017         assertEquals(sec, t.getSecond());
2018         assertEquals(nanos, t.getNano());
2019     }
2020 
2021     @Test
2022     public void test_plusNanos_noChange_oneDay() {
2023         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L);
2024         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1));
2025     }
2026 
2027     //-----------------------------------------------------------------------
2028     // minus(TemporalAmount)
2029     //-----------------------------------------------------------------------
2030     @Test
2031     public void test_minus_TemporalAmount_positiveMonths() {
2032         MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS);
2033         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
2034         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
2035     }
2036 
2037     @Test
2038     public void test_minus_TemporalAmount_negativeDays() {
2039         MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS);
2040         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
2041         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));


2044     @Test(expectedExceptions=DateTimeException.class)
2045     public void test_minus_TemporalAmount_invalidTooLarge() {
2046         MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS);
2047         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(period);
2048     }
2049 
2050     @Test(expectedExceptions=DateTimeException.class)
2051     public void test_minus_TemporalAmount_invalidTooSmall() {
2052         MockSimplePeriod period = MockSimplePeriod.of(1, YEARS);
2053         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period);
2054     }
2055 
2056     @Test(expectedExceptions=NullPointerException.class)
2057     public void test_minus_TemporalAmount_null() {
2058         TEST_2007_07_15_12_30_40_987654321.minus((TemporalAmount) null);
2059     }
2060 
2061     //-----------------------------------------------------------------------
2062     // minus(long,TemporalUnit)
2063     //-----------------------------------------------------------------------
2064     @Test
2065     public void test_minus_longTemporalUnit_positiveMonths() {
2066         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(7, ChronoUnit.MONTHS);
2067         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
2068     }
2069 
2070     @Test
2071     public void test_minus_longTemporalUnit_negativeDays() {
2072         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(-25, ChronoUnit.DAYS);
2073         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));
2074     }
2075 
2076     @Test(expectedExceptions=NullPointerException.class)
2077     public void test_minus_longTemporalUnit_null() {
2078         TEST_2007_07_15_12_30_40_987654321.minus(1, (TemporalUnit) null);
2079     }
2080 
2081     @Test(expectedExceptions=DateTimeException.class)
2082     public void test_minus_longTemporalUnit_invalidTooLarge() {
2083         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(-1, ChronoUnit.YEARS);
2084     }
2085 
2086     @Test(expectedExceptions=DateTimeException.class)
2087     public void test_minus_longTemporalUnit_invalidTooSmall() {
2088         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(1, ChronoUnit.YEARS);
2089     }
2090 
2091     //-----------------------------------------------------------------------
2092     // minusYears()
2093     //-----------------------------------------------------------------------
2094     @Test
2095     public void test_minusYears_int_normal() {
2096         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(1);
2097         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
2098     }
2099 
2100     @Test
2101     public void test_minusYears_int_negative() {
2102         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1);
2103         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
2104     }
2105 
2106     @Test
2107     public void test_minusYears_int_adjustDay() {
2108         LocalDateTime t = createDateMidnight(2008, 2, 29).minusYears(1);
2109         check(t, 2007, 2, 28, 0, 0, 0, 0);
2110     }
2111 
2112     @Test(expectedExceptions=DateTimeException.class)
2113     public void test_minusYears_int_invalidTooLarge() {
2114         createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1);
2115     }
2116 
2117     @Test(expectedExceptions=DateTimeException.class)
2118     public void test_minusYears_int_invalidTooSmall() {
2119         createDateMidnight(Year.MIN_VALUE, 1, 1).minusYears(1);
2120     }
2121 
2122     //-----------------------------------------------------------------------
2123     // minusMonths()
2124     //-----------------------------------------------------------------------
2125     @Test
2126     public void test_minusMonths_int_normal() {
2127         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(1);
2128         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
2129     }
2130 
2131     @Test
2132     public void test_minusMonths_int_overYears() {
2133         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(25);
2134         check(t, 2005, 6, 15, 12, 30, 40, 987654321);
2135     }
2136 
2137     @Test
2138     public void test_minusMonths_int_negative() {
2139         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-1);
2140         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
2141     }
2142 
2143     @Test
2144     public void test_minusMonths_int_negativeAcrossYear() {
2145         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-7);
2146         check(t, 2008, 2, 15, 12, 30, 40, 987654321);
2147     }
2148 
2149     @Test
2150     public void test_minusMonths_int_negativeOverYears() {
2151         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-31);
2152         check(t, 2010, 2, 15, 12, 30, 40, 987654321);
2153     }
2154 
2155     @Test
2156     public void test_minusMonths_int_adjustDayFromLeapYear() {
2157         LocalDateTime t = createDateMidnight(2008, 2, 29).minusMonths(12);
2158         check(t, 2007, 2, 28, 0, 0, 0, 0);
2159     }
2160 
2161     @Test
2162     public void test_minusMonths_int_adjustDayFromMonthLength() {
2163         LocalDateTime t = createDateMidnight(2007, 3, 31).minusMonths(1);
2164         check(t, 2007, 2, 28, 0, 0, 0, 0);
2165     }
2166 
2167     @Test(expectedExceptions=DateTimeException.class)
2168     public void test_minusMonths_int_invalidTooLarge() {
2169         createDateMidnight(Year.MAX_VALUE, 12, 1).minusMonths(-1);
2170     }
2171 
2172     @Test(expectedExceptions=DateTimeException.class)
2173     public void test_minusMonths_int_invalidTooSmall() {
2174         createDateMidnight(Year.MIN_VALUE, 1, 1).minusMonths(1);
2175     }
2176 
2177     //-----------------------------------------------------------------------
2178     // minusWeeks()
2179     //-----------------------------------------------------------------------
2180     @DataProvider(name="sampleMinusWeeksSymmetry")
2181     Object[][] provider_sampleMinusWeeksSymmetry() {
2182         return new Object[][] {
2183             {createDateMidnight(-1, 1, 1)},
2184             {createDateMidnight(-1, 2, 28)},
2185             {createDateMidnight(-1, 3, 1)},
2186             {createDateMidnight(-1, 12, 31)},
2187             {createDateMidnight(0, 1, 1)},
2188             {createDateMidnight(0, 2, 28)},
2189             {createDateMidnight(0, 2, 29)},
2190             {createDateMidnight(0, 3, 1)},
2191             {createDateMidnight(0, 12, 31)},
2192             {createDateMidnight(2007, 1, 1)},
2193             {createDateMidnight(2007, 2, 28)},
2194             {createDateMidnight(2007, 3, 1)},
2195             {createDateMidnight(2007, 12, 31)},
2196             {createDateMidnight(2008, 1, 1)},
2197             {createDateMidnight(2008, 2, 28)},
2198             {createDateMidnight(2008, 2, 29)},
2199             {createDateMidnight(2008, 3, 1)},
2200             {createDateMidnight(2008, 12, 31)},
2201             {createDateMidnight(2099, 1, 1)},
2202             {createDateMidnight(2099, 2, 28)},
2203             {createDateMidnight(2099, 3, 1)},
2204             {createDateMidnight(2099, 12, 31)},
2205             {createDateMidnight(2100, 1, 1)},
2206             {createDateMidnight(2100, 2, 28)},
2207             {createDateMidnight(2100, 3, 1)},
2208             {createDateMidnight(2100, 12, 31)},
2209         };
2210     }
2211 
2212     @Test(dataProvider="sampleMinusWeeksSymmetry")
2213     public void test_minusWeeks_symmetry(LocalDateTime reference) {
2214         for (int weeks = 0; weeks < 365 * 8; weeks++) {
2215             LocalDateTime t = reference.minusWeeks(weeks).minusWeeks(-weeks);
2216             assertEquals(t, reference);
2217 
2218             t = reference.minusWeeks(-weeks).minusWeeks(weeks);
2219             assertEquals(t, reference);
2220         }
2221     }
2222 
2223     @Test
2224     public void test_minusWeeks_normal() {
2225         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(1);
2226         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
2227     }
2228 
2229     @Test
2230     public void test_minusWeeks_overMonths() {
2231         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9);
2232         check(t, 2007, 5, 13, 12, 30, 40, 987654321);
2233     }
2234 
2235     @Test
2236     public void test_minusWeeks_overYears() {
2237         LocalDateTime t = LocalDateTime.of(2008, 7, 13, 12, 30, 40, 987654321).minusWeeks(52);
2238         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2239     }
2240 
2241     @Test
2242     public void test_minusWeeks_overLeapYears() {
2243         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1).minusWeeks(104);
2244         check(t, 2006, 7, 18, 12, 30, 40, 987654321);
2245     }
2246 
2247     @Test
2248     public void test_minusWeeks_negative() {
2249         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-1);
2250         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
2251     }
2252 
2253     @Test
2254     public void test_minusWeeks_negativeAcrossYear() {
2255         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-28);
2256         check(t, 2008, 1, 27, 12, 30, 40, 987654321);
2257     }
2258 
2259     @Test
2260     public void test_minusWeeks_negativeOverYears() {
2261         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-104);
2262         check(t, 2009, 7, 12, 12, 30, 40, 987654321);
2263     }
2264 
2265     @Test
2266     public void test_minusWeeks_maximum() {
2267         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).minusWeeks(-1);
2268         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2269     }
2270 
2271     @Test
2272     public void test_minusWeeks_minimum() {
2273         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).minusWeeks(1);
2274         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2275     }
2276 
2277     @Test(expectedExceptions=DateTimeException.class)
2278     public void test_minusWeeks_invalidTooLarge() {
2279         createDateMidnight(Year.MAX_VALUE, 12, 25).minusWeeks(-1);
2280     }
2281 
2282     @Test(expectedExceptions=DateTimeException.class)
2283     public void test_minusWeeks_invalidTooSmall() {
2284         createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1);
2285     }
2286 
2287     //-----------------------------------------------------------------------
2288     // minusDays()
2289     //-----------------------------------------------------------------------
2290     @DataProvider(name="sampleMinusDaysSymmetry")
2291     Object[][] provider_sampleMinusDaysSymmetry() {
2292         return new Object[][] {
2293             {createDateMidnight(-1, 1, 1)},
2294             {createDateMidnight(-1, 2, 28)},
2295             {createDateMidnight(-1, 3, 1)},
2296             {createDateMidnight(-1, 12, 31)},
2297             {createDateMidnight(0, 1, 1)},
2298             {createDateMidnight(0, 2, 28)},
2299             {createDateMidnight(0, 2, 29)},
2300             {createDateMidnight(0, 3, 1)},
2301             {createDateMidnight(0, 12, 31)},
2302             {createDateMidnight(2007, 1, 1)},
2303             {createDateMidnight(2007, 2, 28)},
2304             {createDateMidnight(2007, 3, 1)},
2305             {createDateMidnight(2007, 12, 31)},
2306             {createDateMidnight(2008, 1, 1)},
2307             {createDateMidnight(2008, 2, 28)},
2308             {createDateMidnight(2008, 2, 29)},
2309             {createDateMidnight(2008, 3, 1)},
2310             {createDateMidnight(2008, 12, 31)},
2311             {createDateMidnight(2099, 1, 1)},
2312             {createDateMidnight(2099, 2, 28)},
2313             {createDateMidnight(2099, 3, 1)},
2314             {createDateMidnight(2099, 12, 31)},
2315             {createDateMidnight(2100, 1, 1)},
2316             {createDateMidnight(2100, 2, 28)},
2317             {createDateMidnight(2100, 3, 1)},
2318             {createDateMidnight(2100, 12, 31)},
2319         };
2320     }
2321 
2322     @Test(dataProvider="sampleMinusDaysSymmetry")
2323     public void test_minusDays_symmetry(LocalDateTime reference) {
2324         for (int days = 0; days < 365 * 8; days++) {
2325             LocalDateTime t = reference.minusDays(days).minusDays(-days);
2326             assertEquals(t, reference);
2327 
2328             t = reference.minusDays(-days).minusDays(days);
2329             assertEquals(t, reference);
2330         }
2331     }
2332 
2333     @Test
2334     public void test_minusDays_normal() {
2335         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(1);
2336         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
2337     }
2338 
2339     @Test
2340     public void test_minusDays_overMonths() {
2341         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62);
2342         check(t, 2007, 5, 14, 12, 30, 40, 987654321);
2343     }
2344 
2345     @Test
2346     public void test_minusDays_overYears() {
2347         LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367);
2348         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2349     }
2350 
2351     @Test
2352     public void test_minusDays_overLeapYears() {
2353         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(2).minusDays(365 + 366);
2354         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2355     }
2356 
2357     @Test
2358     public void test_minusDays_negative() {
2359         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-1);
2360         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
2361     }
2362 
2363     @Test
2364     public void test_minusDays_negativeAcrossYear() {
2365         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-169);
2366         check(t, 2007, 12, 31, 12, 30, 40, 987654321);
2367     }
2368 
2369     @Test
2370     public void test_minusDays_negativeOverYears() {
2371         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-731);
2372         check(t, 2009, 7, 15, 12, 30, 40, 987654321);
2373     }
2374 
2375     @Test
2376     public void test_minusDays_maximum() {
2377         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).minusDays(-1);
2378         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2379     }
2380 
2381     @Test
2382     public void test_minusDays_minimum() {
2383         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).minusDays(1);
2384         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2385     }
2386 
2387     @Test(expectedExceptions=DateTimeException.class)
2388     public void test_minusDays_invalidTooLarge() {
2389         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1);
2390     }
2391 
2392     @Test(expectedExceptions=DateTimeException.class)
2393     public void test_minusDays_invalidTooSmall() {
2394         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1);
2395     }
2396 
2397     @Test(expectedExceptions=ArithmeticException.class)
2398     public void test_minusDays_overflowTooLarge() {
2399         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(Long.MIN_VALUE);
2400     }
2401 
2402     @Test(expectedExceptions=ArithmeticException.class)
2403     public void test_minusDays_overflowTooSmall() {
2404         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(Long.MAX_VALUE);
2405     }
2406 
2407     //-----------------------------------------------------------------------
2408     // minusHours()
2409     //-----------------------------------------------------------------------
2410     @Test
2411     public void test_minusHours_one() {
2412         LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2413         LocalDate d = t.toLocalDate();
2414 
2415         for (int i = 0; i < 50; i++) {
2416             t = t.minusHours(1);
2417 
2418             if (i % 24 == 0) {
2419                 d = d.minusDays(1);
2420             }
2421 
2422             assertEquals(t.toLocalDate(), d);
2423             assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
2424         }
2425     }
2426 
2427     @Test
2428     public void test_minusHours_fromZero() {
2429         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2430         LocalDate d = base.toLocalDate().plusDays(2);
2431         LocalTime t = LocalTime.of(3, 0);
2432 
2433         for (int i = -50; i < 50; i++) {
2434             LocalDateTime dt = base.minusHours(i);
2435             t = t.minusHours(1);
2436 
2437             if (t.getHour() == 23) {
2438                 d = d.minusDays(1);
2439             }
2440 
2441             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
2442             assertEquals(dt.toLocalTime(), t);
2443         }
2444     }
2445 
2446     @Test
2447     public void test_minusHours_fromOne() {
2448         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
2449         LocalDate d = base.toLocalDate().plusDays(2);
2450         LocalTime t = LocalTime.of(4, 0);
2451 
2452         for (int i = -50; i < 50; i++) {
2453             LocalDateTime dt = base.minusHours(i);
2454 
2455             t = t.minusHours(1);
2456 
2457             if (t.getHour() == 23) {
2458                 d = d.minusDays(1);
2459             }
2460 
2461             assertEquals(dt.toLocalDate(), d, String.valueOf(i));
2462             assertEquals(dt.toLocalTime(), t);
2463         }
2464     }
2465 
2466     //-----------------------------------------------------------------------
2467     // minusMinutes()
2468     //-----------------------------------------------------------------------
2469     @Test
2470     public void test_minusMinutes_one() {
2471         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2472         LocalDate d = t.toLocalDate().minusDays(1);
2473 
2474         int hour = 0;
2475         int min = 0;
2476 
2477         for (int i = 0; i < 70; i++) {
2478             t = t.minusMinutes(1);
2479             min--;
2480             if (min == -1) {
2481                 hour--;
2482                 min = 59;
2483 
2484                 if (hour == -1) {
2485                     hour = 23;
2486                 }
2487             }
2488             assertEquals(t.toLocalDate(), d);
2489             assertEquals(t.getHour(), hour);
2490             assertEquals(t.getMinute(), min);
2491         }
2492     }
2493 
2494     @Test
2495     public void test_minusMinutes_fromZero() {
2496         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2497         LocalDate d = base.toLocalDate().minusDays(1);
2498         LocalTime t = LocalTime.of(22, 49);
2499 
2500         for (int i = 70; i > -70; i--) {
2501             LocalDateTime dt = base.minusMinutes(i);
2502             t = t.plusMinutes(1);
2503 
2504             if (t == LocalTime.MIDNIGHT) {
2505                 d = d.plusDays(1);
2506             }
2507 
2508             assertEquals(dt.toLocalDate(), d);
2509             assertEquals(dt.toLocalTime(), t);
2510         }
2511     }
2512 
2513     @Test
2514     public void test_minusMinutes_noChange_oneDay() {
2515         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMinutes(24 * 60);
2516         assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1));
2517     }
2518 
2519     //-----------------------------------------------------------------------
2520     // minusSeconds()
2521     //-----------------------------------------------------------------------
2522     @Test
2523     public void test_minusSeconds_one() {
2524         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2525         LocalDate d = t.toLocalDate().minusDays(1);
2526 
2527         int hour = 0;
2528         int min = 0;
2529         int sec = 0;
2530 
2531         for (int i = 0; i < 3700; i++) {
2532             t = t.minusSeconds(1);
2533             sec--;
2534             if (sec == -1) {
2535                 min--;
2536                 sec = 59;
2537 
2538                 if (min == -1) {
2539                     hour--;
2540                     min = 59;
2541 
2542                     if (hour == -1) {


2582 
2583                         if (hour == 24) {
2584                             hour = 0;
2585                         }
2586                     }
2587                 }
2588 
2589                 if (i == 0) {
2590                     date = date.plusDays(1);
2591                 }
2592 
2593                 return ret;
2594             }
2595 
2596             public void remove() {
2597                 throw new UnsupportedOperationException();
2598             }
2599         };
2600     }
2601 
2602     @Test(dataProvider="minusSeconds_fromZero")
2603     public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
2604         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2605         LocalDateTime t = base.minusSeconds(seconds);
2606 
2607         assertEquals(date, t.toLocalDate());
2608         assertEquals(hour, t.getHour());
2609         assertEquals(min, t.getMinute());
2610         assertEquals(sec, t.getSecond());
2611     }
2612 
2613     //-----------------------------------------------------------------------
2614     // minusNanos()
2615     //-----------------------------------------------------------------------
2616     @Test
2617     public void test_minusNanos_halfABillion() {
2618         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2619         LocalDate d = t.toLocalDate().minusDays(1);
2620 
2621         int hour = 0;
2622         int min = 0;
2623         int sec = 0;
2624         int nanos = 0;
2625 
2626         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
2627             t = t.minusNanos(500000000);
2628             nanos -= 500000000;
2629 
2630             if (nanos < 0) {
2631                 sec--;
2632                 nanos += 1000000000;
2633 
2634                 if (sec == -1) {
2635                     min--;
2636                     sec += 60;


2687                             hour++;
2688                             min = 0;
2689 
2690                             if (hour == 24) {
2691                                 hour = 0;
2692                                 date = date.plusDays(1);
2693                             }
2694                         }
2695                     }
2696                 }
2697 
2698                 return ret;
2699             }
2700 
2701             public void remove() {
2702                 throw new UnsupportedOperationException();
2703             }
2704         };
2705     }
2706 
2707     @Test(dataProvider="minusNanos_fromZero")
2708     public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
2709         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2710         LocalDateTime t = base.minusNanos(nanoseconds);
2711 
2712         assertEquals(date, t.toLocalDate());
2713         assertEquals(hour, t.getHour());
2714         assertEquals(min, t.getMinute());
2715         assertEquals(sec, t.getSecond());
2716         assertEquals(nanos, t.getNano());
2717     }
2718 
2719     //-----------------------------------------------------------------------
2720     // periodUntil(Temporal, TemporalUnit)
2721     //-----------------------------------------------------------------------
2722     @DataProvider(name="periodUntilUnit")
2723     Object[][] data_periodUntilUnit() {
2724         return new Object[][] {
2725                 // date only
2726                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), DAYS, 0},
2727                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), WEEKS, 0},
2728                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), MONTHS, 0},
2729                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), YEARS, 0},
2730                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), DECADES, 0},
2731                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), CENTURIES, 0},
2732                 {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), MILLENNIA, 0},
2733 
2734                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 14), DAYS, 30},
2735                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 15), DAYS, 31},
2736                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 16), DAYS, 32},
2737 
2738                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 17), WEEKS, 4},
2739                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 18), WEEKS, 4},
2740                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 19), WEEKS, 5},
2741                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 20), WEEKS, 5},
2742 
2743                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 14), MONTHS, 0},
2744                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 15), MONTHS, 1},
2745                 {dtNoon(2000, 1, 15), dtNoon(2000, 2, 16), MONTHS, 1},
2746                 {dtNoon(2000, 1, 15), dtNoon(2000, 3, 14), MONTHS, 1},
2747                 {dtNoon(2000, 1, 15), dtNoon(2000, 3, 15), MONTHS, 2},
2748                 {dtNoon(2000, 1, 15), dtNoon(2000, 3, 16), MONTHS, 2},
2749 
2750                 {dtNoon(2000, 1, 15), dtNoon(2001, 1, 14), YEARS, 0},
2751                 {dtNoon(2000, 1, 15), dtNoon(2001, 1, 15), YEARS, 1},
2752                 {dtNoon(2000, 1, 15), dtNoon(2001, 1, 16), YEARS, 1},
2753                 {dtNoon(2000, 1, 15), dtNoon(2004, 1, 14), YEARS, 3},
2754                 {dtNoon(2000, 1, 15), dtNoon(2004, 1, 15), YEARS, 4},
2755                 {dtNoon(2000, 1, 15), dtNoon(2004, 1, 16), YEARS, 4},
2756 
2757                 {dtNoon(2000, 1, 15), dtNoon(2010, 1, 14), DECADES, 0},
2758                 {dtNoon(2000, 1, 15), dtNoon(2010, 1, 15), DECADES, 1},
2759 
2760                 {dtNoon(2000, 1, 15), dtNoon(2100, 1, 14), CENTURIES, 0},
2761                 {dtNoon(2000, 1, 15), dtNoon(2100, 1, 15), CENTURIES, 1},
2762 
2763                 {dtNoon(2000, 1, 15), dtNoon(3000, 1, 14), MILLENNIA, 0},
2764                 {dtNoon(2000, 1, 15), dtNoon(3000, 1, 15), MILLENNIA, 1},
2765 
2766                 // time only
2767                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), NANOS, 0},
2768                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MICROS, 0},
2769                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MILLIS, 0},
2770                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), SECONDS, 0},
2771                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MINUTES, 0},
2772                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), HOURS, 0},
2773                 {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), HALF_DAYS, 0},
2774 
2775                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), NANOS, 2 * 3600 * 1_000_000_000L},
2776                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MICROS, 2 * 3600 * 1_000_000L},
2777                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MILLIS, 2 * 3600 * 1_000L},
2778                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), SECONDS, 2 * 3600},
2779                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MINUTES, 2 * 60},
2780                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), HOURS, 2},
2781                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), HALF_DAYS, 0},
2782 
2783                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), NANOS, 14 * 3600 * 1_000_000_000L},
2784                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MICROS, 14 * 3600 * 1_000_000L},
2785                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MILLIS, 14 * 3600 * 1_000L},
2786                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), SECONDS, 14 * 3600},
2787                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MINUTES, 14 * 60},
2788                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), HOURS, 14},
2789                 {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), HALF_DAYS, 1},
2790 
2791                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), NANOS, (2 * 3600 + 30 * 60 + 40) * 1_000_000_000L + 1500},
2792                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MICROS, (2 * 3600 + 30 * 60 + 40) * 1_000_000L + 1},
2793                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MILLIS, (2 * 3600 + 30 * 60 + 40) * 1_000L},
2794                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), SECONDS, 2 * 3600 + 30 * 60 + 40},
2795                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MINUTES, 2 * 60 + 30},
2796                 {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), HOURS, 2},
2797 
2798                 // combinations
2799                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), NANOS, -1},
2800                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), NANOS, 0},
2801                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), NANOS, 1},
2802 
2803                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 39, 500), SECONDS, -1},
2804                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 39, 501), SECONDS, 0},
2805                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), SECONDS, 0},
2806                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), SECONDS, 0},
2807                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), SECONDS, 0},
2808                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 41, 499), SECONDS, 0},
2809                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 41, 500), SECONDS, 1},
2810 
2811                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), NANOS, -1 + 86400_000_000_000L},
2812                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), NANOS, 0 + 86400_000_000_000L},
2813                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), NANOS, 1 + 86400_000_000_000L},
2814 
2815                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 499), SECONDS, -2 + 86400L},
2816                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 500), SECONDS, -1 + 86400L},
2817                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 501), SECONDS, -1 + 86400L},
2818                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), SECONDS, -1 + 86400L},
2819                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), SECONDS, 0 + 86400L},
2820                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), SECONDS, 0 + 86400L},
2821                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 41, 499), SECONDS, 0 + 86400L},
2822                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 41, 500), SECONDS, 1 + 86400L},
2823 
2824                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 499), MINUTES, -2 + 24 * 60L},
2825                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 500), MINUTES, -1 + 24 * 60L},
2826                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 501), MINUTES, -1 + 24 * 60L},
2827                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), MINUTES, -1 + 24 * 60L},
2828                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), MINUTES, 0 + 24 * 60L},
2829                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), MINUTES, 0 + 24 * 60L},
2830                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 31, 40, 499), MINUTES, 0 + 24 * 60L},
2831                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 31, 40, 500), MINUTES, 1 + 24 * 60L},
2832 
2833                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 499), HOURS, -2 + 24L},
2834                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 500), HOURS, -1 + 24L},
2835                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 501), HOURS, -1 + 24L},
2836                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), HOURS, -1 + 24L},
2837                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), HOURS, 0 + 24L},
2838                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), HOURS, 0 + 24L},
2839                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 13, 30, 40, 499), HOURS, 0 + 24L},
2840                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 13, 30, 40, 500), HOURS, 1 + 24L},
2841 
2842                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 499), DAYS, -2},
2843                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 500), DAYS, -2},
2844                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 501), DAYS, -1},
2845                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 499), DAYS, -1},
2846                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 500), DAYS, -1},
2847                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 501), DAYS, 0},
2848                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), DAYS, 0},
2849                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), DAYS, 0},
2850                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), DAYS, 0},
2851                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), DAYS, 0},
2852                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), DAYS, 1},
2853                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), DAYS, 1},
2854                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 499), DAYS, 1},
2855                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 500), DAYS, 2},
2856                 {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 501), DAYS, 2},
2857         };
2858     }
2859 
2860     @Test(dataProvider="periodUntilUnit")
2861     public void test_periodUntil_TemporalUnit(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) {
2862         long amount = dt1.periodUntil(dt2, unit);
2863         assertEquals(amount, expected);
2864     }
2865 
2866     @Test(dataProvider="periodUntilUnit")
2867     public void test_periodUntil_TemporalUnit_negated(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) {
2868         long amount = dt2.periodUntil(dt1, unit);
2869         assertEquals(amount, -expected);
2870     }
2871 
2872     @Test(expectedExceptions = NullPointerException.class)
2873     public void test_periodUntil_TemporalUnit_nullEnd() {
2874         TEST_2007_07_15_12_30_40_987654321.periodUntil(null, HOURS);
2875     }
2876 
2877     @Test(expectedExceptions = NullPointerException.class)
2878     public void test_periodUntil_TemporalUnit_nullUnit() {
2879         TEST_2007_07_15_12_30_40_987654321.periodUntil(TEST_2007_07_15_12_30_40_987654321, null);
2880     }
2881 
2882     //-----------------------------------------------------------------------
2883     // format(DateTimeFormatter)
2884     //-----------------------------------------------------------------------
2885     @Test
2886     public void test_format_formatter() {
2887         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2888         String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).format(f);
2889         assertEquals(t, "2010 12 3 11 30 45");
2890     }
2891 
2892     @Test(expectedExceptions=NullPointerException.class)
2893     public void test_format_formatter_null() {
2894         LocalDateTime.of(2010, 12, 3, 11, 30, 45).format(null);
2895     }
2896 
2897     //-----------------------------------------------------------------------
2898     // atOffset()
2899     //-----------------------------------------------------------------------
2900     @Test
2901     public void test_atOffset() {
2902         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2903         assertEquals(t.atOffset(OFFSET_PTWO), OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2904     }
2905 
2906     @Test(expectedExceptions=NullPointerException.class)
2907     public void test_atOffset_nullZoneOffset() {
2908         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2909         t.atOffset((ZoneOffset) null);
2910     }
2911 
2912     //-----------------------------------------------------------------------
2913     // atZone()
2914     //-----------------------------------------------------------------------
2915     @Test
2916     public void test_atZone() {
2917         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2918         assertEquals(t.atZone(ZONE_PARIS),
2919                 ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS));
2920     }
2921 
2922     @Test
2923     public void test_atZone_Offset() {
2924         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2925         assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2926     }
2927 
2928     @Test
2929     public void test_atZone_dstGap() {
2930         LocalDateTime t = LocalDateTime.of(2007, 4, 1, 0, 0);
2931         assertEquals(t.atZone(ZONE_GAZA),
2932                 ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA));
2933     }
2934 
2935     @Test
2936     public void test_atZone_dstOverlap() {
2937         LocalDateTime t = LocalDateTime.of(2007, 10, 28, 2, 30);
2938         assertEquals(t.atZone(ZONE_PARIS),
2939                 ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, ZONE_PARIS));
2940     }
2941 
2942     @Test(expectedExceptions=NullPointerException.class)
2943     public void test_atZone_nullTimeZone() {
2944         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2945         t.atZone((ZoneId) null);
2946     }
2947 
2948     //-----------------------------------------------------------------------
2949     // toEpochSecond()
2950     //-----------------------------------------------------------------------
2951     @Test
2952     public void test_toEpochSecond_afterEpoch() {
2953         for (int i = -5; i < 5; i++) {
2954             ZoneOffset offset = ZoneOffset.ofHours(i);
2955             for (int j = 0; j < 100000; j++) {
2956                 LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j);
2957                 assertEquals(a.toEpochSecond(offset), j - i * 3600);
2958             }
2959         }
2960     }
2961 
2962     @Test
2963     public void test_toEpochSecond_beforeEpoch() {
2964         for (int i = 0; i < 100000; i++) {
2965             LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).minusSeconds(i);
2966             assertEquals(a.toEpochSecond(ZoneOffset.UTC), -i);
2967         }
2968     }
2969 
2970     //-----------------------------------------------------------------------
2971     // compareTo()
2972     //-----------------------------------------------------------------------
2973     @Test
2974     public void test_comparisons() {
2975         test_comparisons_LocalDateTime(
2976                 LocalDate.of(Year.MIN_VALUE, 1, 1),
2977                 LocalDate.of(Year.MIN_VALUE, 12, 31),
2978                 LocalDate.of(-1, 1, 1),
2979                 LocalDate.of(-1, 12, 31),
2980                 LocalDate.of(0, 1, 1),
2981                 LocalDate.of(0, 12, 31),
2982                 LocalDate.of(1, 1, 1),
2983                 LocalDate.of(1, 12, 31),
2984                 LocalDate.of(2008, 1, 1),
2985                 LocalDate.of(2008, 2, 29),
2986                 LocalDate.of(2008, 12, 31),
2987                 LocalDate.of(Year.MAX_VALUE, 1, 1),
2988                 LocalDate.of(Year.MAX_VALUE, 12, 31)
2989         );
2990     }
2991 
2992     void test_comparisons_LocalDateTime(LocalDate... localDates) {
2993         test_comparisons_LocalDateTime(


3034                 if (i < j) {
3035                     assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
3036                     assertEquals(a.isBefore(b), true, a + " <=> " + b);
3037                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
3038                     assertEquals(a.equals(b), false, a + " <=> " + b);
3039                 } else if (i > j) {
3040                     assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
3041                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
3042                     assertEquals(a.isAfter(b), true, a + " <=> " + b);
3043                     assertEquals(a.equals(b), false, a + " <=> " + b);
3044                 } else {
3045                     assertEquals(a.compareTo(b), 0, a + " <=> " + b);
3046                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
3047                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
3048                     assertEquals(a.equals(b), true, a + " <=> " + b);
3049                 }
3050             }
3051         }
3052     }
3053 
3054     @Test(expectedExceptions=NullPointerException.class)
3055     public void test_compareTo_ObjectNull() {
3056         TEST_2007_07_15_12_30_40_987654321.compareTo(null);
3057     }
3058 
3059     @Test(expectedExceptions=NullPointerException.class)
3060     public void test_isBefore_ObjectNull() {
3061         TEST_2007_07_15_12_30_40_987654321.isBefore(null);
3062     }
3063 
3064     @Test(expectedExceptions=NullPointerException.class)
3065     public void test_isAfter_ObjectNull() {
3066         TEST_2007_07_15_12_30_40_987654321.isAfter(null);
3067     }
3068 
3069     @Test(expectedExceptions=ClassCastException.class)
3070     @SuppressWarnings({"unchecked", "rawtypes"})
3071     public void compareToNonLocalDateTime() {
3072        Comparable c = TEST_2007_07_15_12_30_40_987654321;
3073        c.compareTo(new Object());
3074     }
3075 
3076     //-----------------------------------------------------------------------
3077     // equals()
3078     //-----------------------------------------------------------------------
3079     @DataProvider(name="sampleDateTimes")
3080     Iterator<Object[]> provider_sampleDateTimes() {
3081         return new Iterator<Object[]>() {
3082             Object[][] sampleDates = provider_sampleDates();
3083             Object[][] sampleTimes = provider_sampleTimes();
3084             int datesIndex = 0;
3085             int timesIndex = 0;
3086 
3087             public boolean hasNext() {
3088                 return datesIndex < sampleDates.length;
3089             }


3094 
3095                 Object[] ret = new Object[sampleDate.length + sampleTime.length];
3096 
3097                 System.arraycopy(sampleDate, 0, ret, 0, sampleDate.length);
3098                 System.arraycopy(sampleTime, 0, ret, sampleDate.length, sampleTime.length);
3099 
3100                 if (++timesIndex == sampleTimes.length) {
3101                     datesIndex++;
3102                     timesIndex = 0;
3103                 }
3104 
3105                 return ret;
3106             }
3107 
3108             public void remove() {
3109                 throw new UnsupportedOperationException();
3110             }
3111         };
3112     }
3113 
3114     @Test(dataProvider="sampleDateTimes")
3115     public void test_equals_true(int y, int m, int d, int h, int mi, int s, int n) {
3116         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3117         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
3118         assertTrue(a.equals(b));
3119     }
3120 
3121     @Test(dataProvider="sampleDateTimes")
3122     public void test_equals_false_year_differs(int y, int m, int d, int h, int mi, int s, int n) {
3123         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3124         LocalDateTime b = LocalDateTime.of(y + 1, m, d, h, mi, s, n);
3125         assertFalse(a.equals(b));
3126     }
3127 
3128     @Test(dataProvider="sampleDateTimes")
3129     public void test_equals_false_month_differs(int y, int m, int d, int h, int mi, int s, int n) {
3130         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3131         LocalDateTime b = LocalDateTime.of(y, m + 1, d, h, mi, s, n);
3132         assertFalse(a.equals(b));
3133     }
3134 
3135     @Test(dataProvider="sampleDateTimes")
3136     public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) {
3137         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3138         LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n);
3139         assertFalse(a.equals(b));
3140     }
3141 
3142     @Test(dataProvider="sampleDateTimes")
3143     public void test_equals_false_hour_differs(int y, int m, int d, int h, int mi, int s, int n) {
3144         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3145         LocalDateTime b = LocalDateTime.of(y, m, d, h + 1, mi, s, n);
3146         assertFalse(a.equals(b));
3147     }
3148 
3149     @Test(dataProvider="sampleDateTimes")
3150     public void test_equals_false_minute_differs(int y, int m, int d, int h, int mi, int s, int n) {
3151         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3152         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi + 1, s, n);
3153         assertFalse(a.equals(b));
3154     }
3155 
3156     @Test(dataProvider="sampleDateTimes")
3157     public void test_equals_false_second_differs(int y, int m, int d, int h, int mi, int s, int n) {
3158         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3159         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s + 1, n);
3160         assertFalse(a.equals(b));
3161     }
3162 
3163     @Test(dataProvider="sampleDateTimes")
3164     public void test_equals_false_nano_differs(int y, int m, int d, int h, int mi, int s, int n) {
3165         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3166         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n + 1);
3167         assertFalse(a.equals(b));
3168     }
3169 
3170     @Test
3171     public void test_equals_itself_true() {
3172         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(TEST_2007_07_15_12_30_40_987654321), true);
3173     }
3174 
3175     @Test
3176     public void test_equals_string_false() {
3177         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals("2007-07-15T12:30:40.987654321"), false);
3178     }
3179 
3180     @Test
3181     public void test_equals_null_false() {
3182         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(null), false);
3183     }
3184 
3185     //-----------------------------------------------------------------------
3186     // hashCode()
3187     //-----------------------------------------------------------------------
3188     @Test(dataProvider="sampleDateTimes")
3189     public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) {
3190         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3191         assertEquals(a.hashCode(), a.hashCode());
3192         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
3193         assertEquals(a.hashCode(), b.hashCode());
3194     }
3195 
3196     //-----------------------------------------------------------------------
3197     // toString()
3198     //-----------------------------------------------------------------------
3199     @DataProvider(name="sampleToString")
3200     Object[][] provider_sampleToString() {
3201         return new Object[][] {
3202             {2008, 7, 5, 2, 1, 0, 0, "2008-07-05T02:01"},
3203             {2007, 12, 31, 23, 59, 1, 0, "2007-12-31T23:59:01"},
3204             {999, 12, 31, 23, 59, 59, 990000000, "0999-12-31T23:59:59.990"},
3205             {-1, 1, 2, 23, 59, 59, 999990000, "-0001-01-02T23:59:59.999990"},
3206             {-2008, 1, 2, 23, 59, 59, 999999990, "-2008-01-02T23:59:59.999999990"},
3207         };
3208     }
3209 
3210     @Test(dataProvider="sampleToString")
3211     public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
3212         LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
3213         String str = t.toString();
3214         assertEquals(str, expected);
3215     }
3216 
3217     private LocalDateTime dtNoon(int year, int month, int day) {
3218         return LocalDateTime.of(year, month, day, 12, 0);
3219     }
3220 
3221     private LocalDateTime dtEpoch(int hour, int min, int sec, int nano) {
3222         return LocalDateTime.of(1970, 1, 1, hour, min, sec, nano);


3223     }
3224 
3225     private LocalDateTime dt(int year, int month, int day, int hour, int min, int sec, int nano) {
3226         return LocalDateTime.of(year, month, day, hour, min, sec, nano);

3227     }
3228 
3229 }