1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * This file is available under and governed by the GNU General Public
  26  * License version 2 only, as published by the Free Software Foundation.
  27  * However, the following notice accompanied the original version of this
  28  * file:
  29  *
  30  * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
  31  *
  32  * All rights reserved.
  33  *
  34  * Redistribution and use in source and binary forms, with or without
  35  * modification, are permitted provided that the following conditions are met:
  36  *
  37  *  * Redistributions of source code must retain the above copyright notice,
  38  *    this list of conditions and the following disclaimer.
  39  *
  40  *  * Redistributions in binary form must reproduce the above copyright notice,
  41  *    this list of conditions and the following disclaimer in the documentation
  42  *    and/or other materials provided with the distribution.
  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  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.NANOS;
  92 import static java.time.temporal.ChronoUnit.SECONDS;
  93 import static org.testng.Assert.assertEquals;
  94 import static org.testng.Assert.assertFalse;
  95 import static org.testng.Assert.assertSame;
  96 import static org.testng.Assert.assertTrue;
  97 
  98 import java.io.ByteArrayOutputStream;
  99 import java.io.DataOutputStream;
 100 import java.io.IOException;
 101 import java.util.ArrayList;
 102 import java.util.Arrays;
 103 import java.util.Iterator;
 104 import java.util.List;
 105 
 106 import java.time.Clock;
 107 import java.time.DateTimeException;
 108 import java.time.DayOfWeek;
 109 import java.time.Instant;
 110 import java.time.LocalDate;
 111 import java.time.LocalDateTime;
 112 import java.time.LocalTime;
 113 import java.time.Month;
 114 import java.time.Period;
 115 import java.time.ZoneId;
 116 import java.time.ZoneOffset;
 117 import java.time.ZonedDateTime;
 118 import java.time.format.DateTimeFormatter;
 119 import java.time.format.DateTimeFormatters;
 120 import java.time.format.DateTimeParseException;
 121 import java.time.temporal.ChronoField;
 122 import java.time.temporal.ChronoUnit;
 123 import java.time.temporal.ISOChrono;
 124 import java.time.temporal.JulianFields;
 125 import java.time.temporal.OffsetDateTime;
 126 import java.time.temporal.Queries;
 127 import java.time.temporal.Temporal;
 128 import java.time.temporal.TemporalAccessor;
 129 import java.time.temporal.TemporalAdder;
 130 import java.time.temporal.TemporalAdjuster;
 131 import java.time.temporal.TemporalField;
 132 import java.time.temporal.TemporalQuery;
 133 import java.time.temporal.TemporalSubtractor;
 134 import java.time.temporal.TemporalUnit;
 135 import java.time.temporal.Year;
 136 
 137 import org.testng.annotations.BeforeMethod;
 138 import org.testng.annotations.DataProvider;
 139 import org.testng.annotations.Test;
 140 import test.java.time.MockSimplePeriod;
 141 
 142 /**
 143  * Test LocalDateTime.
 144  */
 145 @Test
 146 public class TCKLocalDateTime extends AbstractDateTimeTest {
 147 
 148     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 149     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 150     private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2);
 151     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 152     private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza");
 153 
 154     private LocalDateTime TEST_2007_07_15_12_30_40_987654321 = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 155     private LocalDateTime MAX_DATE_TIME;
 156     private LocalDateTime MIN_DATE_TIME;
 157     private Instant MAX_INSTANT;
 158     private Instant MIN_INSTANT;
 159 
 160     @BeforeMethod(groups={"implementation","tck"})
 161     public void setUp() {
 162         MAX_DATE_TIME = LocalDateTime.MAX;
 163         MIN_DATE_TIME = LocalDateTime.MIN;
 164         MAX_INSTANT = MAX_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 165         MIN_INSTANT = MIN_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
 166     }
 167 
 168     //-----------------------------------------------------------------------
 169     @Override
 170     protected List<TemporalAccessor> samples() {
 171         TemporalAccessor[] array = {TEST_2007_07_15_12_30_40_987654321, LocalDateTime.MAX, LocalDateTime.MIN, };
 172         return Arrays.asList(array);
 173     }
 174 
 175     @Override
 176     protected List<TemporalField> validFields() {
 177         TemporalField[] array = {
 178             NANO_OF_SECOND,
 179             NANO_OF_DAY,
 180             MICRO_OF_SECOND,
 181             MICRO_OF_DAY,
 182             MILLI_OF_SECOND,
 183             MILLI_OF_DAY,
 184             SECOND_OF_MINUTE,
 185             SECOND_OF_DAY,
 186             MINUTE_OF_HOUR,
 187             MINUTE_OF_DAY,
 188             CLOCK_HOUR_OF_AMPM,
 189             HOUR_OF_AMPM,
 190             CLOCK_HOUR_OF_DAY,
 191             HOUR_OF_DAY,
 192             AMPM_OF_DAY,
 193             DAY_OF_WEEK,
 194             ALIGNED_DAY_OF_WEEK_IN_MONTH,
 195             ALIGNED_DAY_OF_WEEK_IN_YEAR,
 196             DAY_OF_MONTH,
 197             DAY_OF_YEAR,
 198             EPOCH_DAY,
 199             ALIGNED_WEEK_OF_MONTH,
 200             ALIGNED_WEEK_OF_YEAR,
 201             MONTH_OF_YEAR,
 202             EPOCH_MONTH,
 203             YEAR_OF_ERA,
 204             YEAR,
 205             ERA,
 206             JulianFields.JULIAN_DAY,
 207             JulianFields.MODIFIED_JULIAN_DAY,
 208             JulianFields.RATA_DIE,
 209         };
 210         return Arrays.asList(array);
 211     }
 212 
 213     @Override
 214     protected List<TemporalField> invalidFields() {
 215         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 216         list.removeAll(validFields());
 217         return list;
 218     }
 219 
 220     //-----------------------------------------------------------------------
 221     private void check(LocalDateTime test, int y, int m, int d, int h, int mi, int s, int n) {
 222         assertEquals(test.getYear(), y);
 223         assertEquals(test.getMonth().getValue(), m);
 224         assertEquals(test.getDayOfMonth(), d);
 225         assertEquals(test.getHour(), h);
 226         assertEquals(test.getMinute(), mi);
 227         assertEquals(test.getSecond(), s);
 228         assertEquals(test.getNano(), n);
 229         assertEquals(test, test);
 230         assertEquals(test.hashCode(), test.hashCode());
 231         assertEquals(LocalDateTime.of(y, m, d, h, mi, s, n), test);
 232     }
 233 
 234     private LocalDateTime createDateMidnight(int year, int month, int day) {
 235         return LocalDateTime.of(year, month, day, 0, 0);
 236     }
 237 
 238     //-----------------------------------------------------------------------
 239     @Test
 240     public void test_serialization() throws Exception {
 241         assertSerializable(TEST_2007_07_15_12_30_40_987654321);
 242         assertSerializable(LocalDateTime.MIN);
 243         assertSerializable(LocalDateTime.MAX);
 244     }
 245 
 246     @Test
 247     public void test_serialization_format() throws Exception {
 248         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 249         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 250             dos.writeByte(5);
 251             dos.writeInt(2012);
 252             dos.writeByte(9);
 253             dos.writeByte(16);
 254             dos.writeByte(22);
 255             dos.writeByte(17);
 256             dos.writeByte(59);
 257             dos.writeInt(459_000_000);
 258         }
 259         byte[] bytes = baos.toByteArray();
 260         assertSerializedBySer(LocalDateTime.of(2012, 9, 16, 22, 17, 59, 459_000_000), bytes);
 261     }
 262 
 263     //-----------------------------------------------------------------------
 264     // constants
 265     //-----------------------------------------------------------------------
 266     @Test
 267     public void constant_MIN() {
 268         check(LocalDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
 269     }
 270 
 271     @Test
 272     public void constant_MAX() {
 273         check(LocalDateTime.MAX, Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999);
 274     }
 275 
 276     //-----------------------------------------------------------------------
 277     // now()
 278     //-----------------------------------------------------------------------
 279     @Test(timeOut=30000, groups={"tck"})  // TODO: remove when time zone loading is faster
 280     public void now() {
 281         LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone());
 282         LocalDateTime test = LocalDateTime.now();
 283         long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 284         if (diff >= 100000000) {
 285             // may be date change
 286             expected = LocalDateTime.now(Clock.systemDefaultZone());
 287             test = LocalDateTime.now();
 288             diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 289         }
 290         assertTrue(diff < 100000000);  // less than 0.1 secs
 291     }
 292 
 293     //-----------------------------------------------------------------------
 294     // now(ZoneId)
 295     //-----------------------------------------------------------------------
 296     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 297     public void now_ZoneId_nullZoneId() {
 298         LocalDateTime.now((ZoneId) null);
 299     }
 300 
 301     @Test(groups={"tck"})
 302     public void now_ZoneId() {
 303         ZoneId zone = ZoneId.of("UTC+01:02:03");
 304         LocalDateTime expected = LocalDateTime.now(Clock.system(zone));
 305         LocalDateTime test = LocalDateTime.now(zone);
 306         for (int i = 0; i < 100; i++) {
 307             if (expected.equals(test)) {
 308                 return;
 309             }
 310             expected = LocalDateTime.now(Clock.system(zone));
 311             test = LocalDateTime.now(zone);
 312         }
 313         assertEquals(test, expected);
 314     }
 315 
 316     //-----------------------------------------------------------------------
 317     // now(Clock)
 318     //-----------------------------------------------------------------------
 319     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 320     public void now_Clock_nullClock() {
 321         LocalDateTime.now((Clock) null);
 322     }
 323 
 324     @Test(groups={"tck"})
 325     public void now_Clock_allSecsInDay_utc() {
 326         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 327             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 328             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 329             LocalDateTime test = LocalDateTime.now(clock);
 330             assertEquals(test.getYear(), 1970);
 331             assertEquals(test.getMonth(), Month.JANUARY);
 332             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 333             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 334             assertEquals(test.getMinute(), (i / 60) % 60);
 335             assertEquals(test.getSecond(), i % 60);
 336             assertEquals(test.getNano(), 123456789);
 337         }
 338     }
 339 
 340     @Test(groups={"tck"})
 341     public void now_Clock_allSecsInDay_offset() {
 342         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 343             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 344             Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
 345             LocalDateTime test = LocalDateTime.now(clock);
 346             assertEquals(test.getYear(), 1970);
 347             assertEquals(test.getMonth(), Month.JANUARY);
 348             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
 349             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 350             assertEquals(test.getMinute(), (i / 60) % 60);
 351             assertEquals(test.getSecond(), i % 60);
 352             assertEquals(test.getNano(), 123456789);
 353         }
 354     }
 355 
 356     @Test(groups={"tck"})
 357     public void now_Clock_allSecsInDay_beforeEpoch() {
 358         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 359         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 360             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 361             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 362             LocalDateTime test = LocalDateTime.now(clock);
 363             assertEquals(test.getYear(), 1969);
 364             assertEquals(test.getMonth(), Month.DECEMBER);
 365             assertEquals(test.getDayOfMonth(), 31);
 366             expected = expected.minusSeconds(1);
 367             assertEquals(test.getTime(), expected);
 368         }
 369     }
 370 
 371     //-----------------------------------------------------------------------
 372     @Test(groups={"tck"})
 373     public void now_Clock_maxYear() {
 374         Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC);
 375         LocalDateTime test = LocalDateTime.now(clock);
 376         assertEquals(test, MAX_DATE_TIME);
 377     }
 378 
 379     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 380     public void now_Clock_tooBig() {
 381         Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC);
 382         LocalDateTime.now(clock);
 383     }
 384 
 385     @Test(groups={"tck"})
 386     public void now_Clock_minYear() {
 387         Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC);
 388         LocalDateTime test = LocalDateTime.now(clock);
 389         assertEquals(test, MIN_DATE_TIME);
 390     }
 391 
 392     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 393     public void now_Clock_tooLow() {
 394         Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC);
 395         LocalDateTime.now(clock);
 396     }
 397 
 398     //-----------------------------------------------------------------------
 399     // of() factories
 400     //-----------------------------------------------------------------------
 401     //-----------------------------------------------------------------------
 402     @Test(groups={"tck"})
 403     public void factory_of_4intsMonth() {
 404         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30);
 405         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 406     }
 407 
 408     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 409     public void factory_of_4intsMonth_yearTooLow() {
 410         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30);
 411     }
 412 
 413     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 414     public void factory_of_4intsMonth_nullMonth() {
 415         LocalDateTime.of(2007, null, 15, 12, 30);
 416     }
 417 
 418     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 419     public void factory_of_4intsMonth_dayTooLow() {
 420         LocalDateTime.of(2007, Month.JULY, -1, 12, 30);
 421     }
 422 
 423     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 424     public void factory_of_4intsMonth_dayTooHigh() {
 425         LocalDateTime.of(2007, Month.JULY, 32, 12, 30);
 426     }
 427 
 428     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 429     public void factory_of_4intsMonth_hourTooLow() {
 430         LocalDateTime.of(2007, Month.JULY, 15, -1, 30);
 431     }
 432 
 433     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 434     public void factory_of_4intsMonth_hourTooHigh() {
 435         LocalDateTime.of(2007, Month.JULY, 15, 24, 30);
 436     }
 437 
 438     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 439     public void factory_of_4intsMonth_minuteTooLow() {
 440         LocalDateTime.of(2007, Month.JULY, 15, 12, -1);
 441     }
 442 
 443     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 444     public void factory_of_4intsMonth_minuteTooHigh() {
 445         LocalDateTime.of(2007, Month.JULY, 15, 12, 60);
 446     }
 447 
 448     //-----------------------------------------------------------------------
 449     @Test(groups={"tck"})
 450     public void factory_of_5intsMonth() {
 451         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40);
 452         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 453     }
 454 
 455     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 456     public void factory_of_5intsMonth_yearTooLow() {
 457         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40);
 458     }
 459 
 460     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 461     public void factory_of_5intsMonth_nullMonth() {
 462         LocalDateTime.of(2007, null, 15, 12, 30, 40);
 463     }
 464 
 465     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 466     public void factory_of_5intsMonth_dayTooLow() {
 467         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40);
 468     }
 469 
 470     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 471     public void factory_of_5intsMonth_dayTooHigh() {
 472         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40);
 473     }
 474 
 475     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 476     public void factory_of_5intsMonth_hourTooLow() {
 477         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40);
 478     }
 479 
 480     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 481     public void factory_of_5intsMonth_hourTooHigh() {
 482         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40);
 483     }
 484 
 485     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 486     public void factory_of_5intsMonth_minuteTooLow() {
 487         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40);
 488     }
 489 
 490     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 491     public void factory_of_5intsMonth_minuteTooHigh() {
 492         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40);
 493     }
 494 
 495     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 496     public void factory_of_5intsMonth_secondTooLow() {
 497         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1);
 498     }
 499 
 500     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 501     public void factory_of_5intsMonth_secondTooHigh() {
 502         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60);
 503     }
 504 
 505     //-----------------------------------------------------------------------
 506     @Test(groups={"tck"})
 507     public void factory_of_6intsMonth() {
 508         LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 987654321);
 509         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 510     }
 511 
 512     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 513     public void factory_of_6intsMonth_yearTooLow() {
 514         LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321);
 515     }
 516 
 517     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 518     public void factory_of_6intsMonth_nullMonth() {
 519         LocalDateTime.of(2007, null, 15, 12, 30, 40, 987654321);
 520     }
 521 
 522     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 523     public void factory_of_6intsMonth_dayTooLow() {
 524         LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40, 987654321);
 525     }
 526 
 527     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 528     public void factory_of_6intsMonth_dayTooHigh() {
 529         LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40, 987654321);
 530     }
 531 
 532     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 533     public void factory_of_6intsMonth_hourTooLow() {
 534         LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40, 987654321);
 535     }
 536 
 537     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 538     public void factory_of_6intsMonth_hourTooHigh() {
 539         LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40, 987654321);
 540     }
 541 
 542     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 543     public void factory_of_6intsMonth_minuteTooLow() {
 544         LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40, 987654321);
 545     }
 546 
 547     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 548     public void factory_of_6intsMonth_minuteTooHigh() {
 549         LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40, 987654321);
 550     }
 551 
 552     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 553     public void factory_of_6intsMonth_secondTooLow() {
 554         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321);
 555     }
 556 
 557     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 558     public void factory_of_6intsMonth_secondTooHigh() {
 559         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60, 987654321);
 560     }
 561 
 562     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 563     public void factory_of_6intsMonth_nanoTooLow() {
 564         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, -1);
 565     }
 566 
 567     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 568     public void factory_of_6intsMonth_nanoTooHigh() {
 569         LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 1000000000);
 570     }
 571 
 572     //-----------------------------------------------------------------------
 573     @Test(groups={"tck"})
 574     public void factory_of_5ints() {
 575         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30);
 576         check(dateTime, 2007, 7, 15, 12, 30, 0, 0);
 577     }
 578 
 579     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 580     public void factory_of_5ints_yearTooLow() {
 581         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30);
 582     }
 583 
 584     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 585     public void factory_of_5ints_monthTooLow() {
 586         LocalDateTime.of(2007, 0, 15, 12, 30);
 587     }
 588 
 589     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 590     public void factory_of_5ints_monthTooHigh() {
 591         LocalDateTime.of(2007, 13, 15, 12, 30);
 592     }
 593 
 594     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 595     public void factory_of_5ints_dayTooLow() {
 596         LocalDateTime.of(2007, 7, -1, 12, 30);
 597     }
 598 
 599     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 600     public void factory_of_5ints_dayTooHigh() {
 601         LocalDateTime.of(2007, 7, 32, 12, 30);
 602     }
 603 
 604     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 605     public void factory_of_5ints_hourTooLow() {
 606         LocalDateTime.of(2007, 7, 15, -1, 30);
 607     }
 608 
 609     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 610     public void factory_of_5ints_hourTooHigh() {
 611         LocalDateTime.of(2007, 7, 15, 24, 30);
 612     }
 613 
 614     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 615     public void factory_of_5ints_minuteTooLow() {
 616         LocalDateTime.of(2007, 7, 15, 12, -1);
 617     }
 618 
 619     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 620     public void factory_of_5ints_minuteTooHigh() {
 621         LocalDateTime.of(2007, 7, 15, 12, 60);
 622     }
 623 
 624     //-----------------------------------------------------------------------
 625     @Test(groups={"tck"})
 626     public void factory_of_6ints() {
 627         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40);
 628         check(dateTime, 2007, 7, 15, 12, 30, 40, 0);
 629     }
 630 
 631     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 632     public void factory_of_6ints_yearTooLow() {
 633         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40);
 634     }
 635 
 636     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 637     public void factory_of_6ints_monthTooLow() {
 638         LocalDateTime.of(2007, 0, 15, 12, 30, 40);
 639     }
 640 
 641     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 642     public void factory_of_6ints_monthTooHigh() {
 643         LocalDateTime.of(2007, 13, 15, 12, 30, 40);
 644     }
 645 
 646     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 647     public void factory_of_6ints_dayTooLow() {
 648         LocalDateTime.of(2007, 7, -1, 12, 30, 40);
 649     }
 650 
 651     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 652     public void factory_of_6ints_dayTooHigh() {
 653         LocalDateTime.of(2007, 7, 32, 12, 30, 40);
 654     }
 655 
 656     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 657     public void factory_of_6ints_hourTooLow() {
 658         LocalDateTime.of(2007, 7, 15, -1, 30, 40);
 659     }
 660 
 661     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 662     public void factory_of_6ints_hourTooHigh() {
 663         LocalDateTime.of(2007, 7, 15, 24, 30, 40);
 664     }
 665 
 666     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 667     public void factory_of_6ints_minuteTooLow() {
 668         LocalDateTime.of(2007, 7, 15, 12, -1, 40);
 669     }
 670 
 671     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 672     public void factory_of_6ints_minuteTooHigh() {
 673         LocalDateTime.of(2007, 7, 15, 12, 60, 40);
 674     }
 675 
 676     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 677     public void factory_of_6ints_secondTooLow() {
 678         LocalDateTime.of(2007, 7, 15, 12, 30, -1);
 679     }
 680 
 681     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 682     public void factory_of_6ints_secondTooHigh() {
 683         LocalDateTime.of(2007, 7, 15, 12, 30, 60);
 684     }
 685 
 686     //-----------------------------------------------------------------------
 687     @Test(groups={"tck"})
 688     public void factory_of_7ints() {
 689         LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
 690         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 691     }
 692 
 693     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 694     public void factory_of_7ints_yearTooLow() {
 695         LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40, 987654321);
 696     }
 697 
 698     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 699     public void factory_of_7ints_monthTooLow() {
 700         LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321);
 701     }
 702 
 703     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 704     public void factory_of_7ints_monthTooHigh() {
 705         LocalDateTime.of(2007, 13, 15, 12, 30, 40, 987654321);
 706     }
 707 
 708     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 709     public void factory_of_7ints_dayTooLow() {
 710         LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321);
 711     }
 712 
 713     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 714     public void factory_of_7ints_dayTooHigh() {
 715         LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321);
 716     }
 717 
 718     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 719     public void factory_of_7ints_hourTooLow() {
 720         LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321);
 721     }
 722 
 723     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 724     public void factory_of_7ints_hourTooHigh() {
 725         LocalDateTime.of(2007, 7, 15, 24, 30, 40, 987654321);
 726     }
 727 
 728     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 729     public void factory_of_7ints_minuteTooLow() {
 730         LocalDateTime.of(2007, 7, 15, 12, -1, 40, 987654321);
 731     }
 732 
 733     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 734     public void factory_of_7ints_minuteTooHigh() {
 735         LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321);
 736     }
 737 
 738     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 739     public void factory_of_7ints_secondTooLow() {
 740         LocalDateTime.of(2007, 7, 15, 12, 30, -1, 987654321);
 741     }
 742 
 743     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 744     public void factory_of_7ints_secondTooHigh() {
 745         LocalDateTime.of(2007, 7, 15, 12, 30, 60, 987654321);
 746     }
 747 
 748     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 749     public void factory_of_7ints_nanoTooLow() {
 750         LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1);
 751     }
 752 
 753     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 754     public void factory_of_7ints_nanoTooHigh() {
 755         LocalDateTime.of(2007, 7, 15, 12, 30, 40, 1000000000);
 756     }
 757 
 758     //-----------------------------------------------------------------------
 759     @Test(groups={"tck"})
 760     public void factory_of_LocalDate_LocalTime() {
 761         LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(12, 30, 40, 987654321));
 762         check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321);
 763     }
 764 
 765     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 766     public void factory_of_LocalDate_LocalTime_nullLocalDate() {
 767         LocalDateTime.of(null, LocalTime.of(12, 30, 40, 987654321));
 768     }
 769 
 770     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 771     public void factory_of_LocalDate_LocalTime_nullLocalTime() {
 772         LocalDateTime.of(LocalDate.of(2007, 7, 15), null);
 773     }
 774 
 775     //-----------------------------------------------------------------------
 776     // ofInstant()
 777     //-----------------------------------------------------------------------
 778     @DataProvider(name="instantFactory")
 779     Object[][] data_instantFactory() {
 780         return new Object[][] {
 781                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), ZONE_PARIS, LocalDateTime.of(1970, 1, 2, 2, 2, 4, 500)},
 782                 {Instant.ofEpochSecond(86400 + 3600 + 120 + 4, 500), OFFSET_MTWO, LocalDateTime.of(1970, 1, 1, 23, 2, 4, 500)},
 783                 {Instant.ofEpochSecond(-86400 + 4, 500), OFFSET_PTWO, LocalDateTime.of(1969, 12, 31, 2, 0, 4, 500)},
 784                 {OffsetDateTime.of(LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0), ZoneOffset.UTC).toInstant(),
 785                         ZoneOffset.UTC, LocalDateTime.MIN},
 786                 {OffsetDateTime.of(LocalDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 59, 999_999_999), ZoneOffset.UTC).toInstant(),
 787                         ZoneOffset.UTC, LocalDateTime.MAX},
 788         };
 789     }
 790 
 791     @Test(dataProvider="instantFactory")
 792     public void factory_ofInstant(Instant instant, ZoneId zone, LocalDateTime expected) {
 793         LocalDateTime test = LocalDateTime.ofInstant(instant, zone);
 794         assertEquals(test, expected);
 795     }
 796 
 797     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 798     public void factory_ofInstant_instantTooBig() {
 799         LocalDateTime.ofInstant(Instant.MAX, OFFSET_PONE) ;
 800     }
 801 
 802     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 803     public void factory_ofInstant_instantTooSmall() {
 804         LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ;
 805     }
 806 
 807     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 808     public void factory_ofInstant_nullInstant() {
 809         LocalDateTime.ofInstant((Instant) null, ZONE_GAZA);
 810     }
 811 
 812     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 813     public void factory_ofInstant_nullZone() {
 814         LocalDateTime.ofInstant(Instant.EPOCH, (ZoneId) null);
 815     }
 816 
 817     //-----------------------------------------------------------------------
 818     // ofEpochSecond()
 819     //-----------------------------------------------------------------------
 820     @Test(groups={"tck"})
 821     public void factory_ofEpochSecond_longOffset_afterEpoch() {
 822         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 823         for (int i = 0; i < 100000; i++) {
 824             LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO);
 825             assertEquals(test, base.plusSeconds(i));
 826         }
 827     }
 828 
 829     @Test(groups={"tck"})
 830     public void factory_ofEpochSecond_longOffset_beforeEpoch() {
 831         LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
 832         for (int i = 0; i < 100000; i++) {
 833             LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO);
 834             assertEquals(test, base.minusSeconds(i));
 835         }
 836     }
 837 
 838     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 839     public void factory_ofEpochSecond_longOffset_tooBig() {
 840         LocalDateTime.ofEpochSecond(Long.MAX_VALUE, 500, OFFSET_PONE);  // TODO: better test
 841     }
 842 
 843     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 844     public void factory_ofEpochSecond_longOffset_tooSmall() {
 845         LocalDateTime.ofEpochSecond(Long.MIN_VALUE, 500, OFFSET_PONE);  // TODO: better test
 846     }
 847 
 848     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 849     public void factory_ofEpochSecond_badNanos_toBig() {
 850         LocalDateTime.ofEpochSecond(0, 1_000_000_000, OFFSET_PONE);
 851     }
 852 
 853     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 854     public void factory_ofEpochSecond_badNanos_toSmall() {
 855         LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE);
 856     }
 857 
 858     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 859     public void factory_ofEpochSecond_longOffset_nullOffset() {
 860         LocalDateTime.ofEpochSecond(0L, 500, null);
 861     }
 862 
 863     //-----------------------------------------------------------------------
 864     // from()
 865     //-----------------------------------------------------------------------
 866     @Test(groups={"tck"})
 867     public void test_from_TemporalAccessor() {
 868         LocalDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30);
 869         assertEquals(LocalDateTime.from(base), base);
 870         assertEquals(LocalDateTime.from(ZonedDateTime.of(base, ZoneOffset.ofHours(2))), base);
 871     }
 872 
 873     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 874     public void test_from_TemporalAccessor_invalid_noDerive() {
 875         LocalDateTime.from(LocalTime.of(12, 30));
 876     }
 877 
 878     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 879     public void test_from_TemporalAccessor_null() {
 880         LocalDateTime.from((TemporalAccessor) null);
 881     }
 882 
 883     //-----------------------------------------------------------------------
 884     // parse()
 885     //-----------------------------------------------------------------------
 886     @Test(dataProvider="sampleToString", groups={"tck"})
 887     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String text) {
 888         LocalDateTime t = LocalDateTime.parse(text);
 889         assertEquals(t.getYear(), y);
 890         assertEquals(t.getMonth().getValue(), month);
 891         assertEquals(t.getDayOfMonth(), d);
 892         assertEquals(t.getHour(), h);
 893         assertEquals(t.getMinute(), m);
 894         assertEquals(t.getSecond(), s);
 895         assertEquals(t.getNano(), n);
 896     }
 897 
 898     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 899     public void factory_parse_illegalValue() {
 900         LocalDateTime.parse("2008-06-32T11:15");
 901     }
 902 
 903     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 904     public void factory_parse_invalidValue() {
 905         LocalDateTime.parse("2008-06-31T11:15");
 906     }
 907 
 908     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 909     public void factory_parse_nullText() {
 910         LocalDateTime.parse((String) null);
 911     }
 912 
 913     //-----------------------------------------------------------------------
 914     // parse(DateTimeFormatter)
 915     //-----------------------------------------------------------------------
 916     @Test(groups={"tck"})
 917     public void factory_parse_formatter() {
 918         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
 919         LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f);
 920         assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45));
 921     }
 922 
 923     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 924     public void factory_parse_formatter_nullText() {
 925         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
 926         LocalDateTime.parse((String) null, f);
 927     }
 928 
 929     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 930     public void factory_parse_formatter_nullFormatter() {
 931         LocalDateTime.parse("ANY", null);
 932     }
 933 
 934     //-----------------------------------------------------------------------
 935     // get(TemporalField)
 936     //-----------------------------------------------------------------------
 937     @Test
 938     public void test_get_TemporalField() {
 939         LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
 940         assertEquals(test.get(ChronoField.YEAR), 2008);
 941         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 942         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 943         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 944         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 945 
 946         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 947         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 948         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 949         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 950         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 951         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 952     }
 953 
 954     @Test
 955     public void test_getLong_TemporalField() {
 956         LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
 957         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 958         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 959         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 960         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 961         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 962 
 963         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 964         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 965         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 966         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 967         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 968         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 969     }
 970 
 971     //-----------------------------------------------------------------------
 972     // query(TemporalQuery)
 973     //-----------------------------------------------------------------------
 974     @Test
 975     public void test_query_chrono() {
 976         assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.chrono()), ISOChrono.INSTANCE);
 977         assertEquals(Queries.chrono().queryFrom(TEST_2007_07_15_12_30_40_987654321), ISOChrono.INSTANCE);
 978     }
 979 
 980     @Test
 981     public void test_query_zoneId() {
 982         assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.zoneId()), null);
 983         assertEquals(Queries.zoneId().queryFrom(TEST_2007_07_15_12_30_40_987654321), null);
 984     }
 985 
 986     @Test
 987     public void test_query_precision() {
 988         assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.precision()), NANOS);
 989         assertEquals(Queries.precision().queryFrom(TEST_2007_07_15_12_30_40_987654321), NANOS);
 990     }
 991 
 992     @Test
 993     public void test_query_offset() {
 994         assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.offset()), null);
 995         assertEquals(Queries.offset().queryFrom(TEST_2007_07_15_12_30_40_987654321), null);
 996     }
 997 
 998     @Test
 999     public void test_query_zone() {
1000         assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.zone()), null);
1001         assertEquals(Queries.zone().queryFrom(TEST_2007_07_15_12_30_40_987654321), null);
1002     }
1003 
1004     @Test(expectedExceptions=NullPointerException.class)
1005     public void test_query_null() {
1006         TEST_2007_07_15_12_30_40_987654321.query(null);
1007     }
1008 
1009     //-----------------------------------------------------------------------
1010     @DataProvider(name="sampleDates")
1011     Object[][] provider_sampleDates() {
1012         return new Object[][] {
1013             {2008, 7, 5},
1014             {2007, 7, 5},
1015             {2006, 7, 5},
1016             {2005, 7, 5},
1017             {2004, 1, 1},
1018             {-1, 1, 2},
1019         };
1020     }
1021 
1022     @DataProvider(name="sampleTimes")
1023     Object[][] provider_sampleTimes() {
1024         return new Object[][] {
1025             {0, 0, 0, 0},
1026             {0, 0, 0, 1},
1027             {0, 0, 1, 0},
1028             {0, 0, 1, 1},
1029             {0, 1, 0, 0},
1030             {0, 1, 0, 1},
1031             {0, 1, 1, 0},
1032             {0, 1, 1, 1},
1033             {1, 0, 0, 0},
1034             {1, 0, 0, 1},
1035             {1, 0, 1, 0},
1036             {1, 0, 1, 1},
1037             {1, 1, 0, 0},
1038             {1, 1, 0, 1},
1039             {1, 1, 1, 0},
1040             {1, 1, 1, 1},
1041         };
1042     }
1043 
1044     //-----------------------------------------------------------------------
1045     // get*()
1046     //-----------------------------------------------------------------------
1047     @Test(dataProvider="sampleDates", groups={"tck"})
1048     public void test_get_dates(int y, int m, int d) {
1049         LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30);
1050         assertEquals(a.getYear(), y);
1051         assertEquals(a.getMonth(), Month.of(m));
1052         assertEquals(a.getDayOfMonth(), d);
1053     }
1054 
1055     @Test(dataProvider="sampleDates", groups={"tck"})
1056     public void test_getDOY(int y, int m, int d) {
1057         LocalDateTime a = LocalDateTime.of(y, m, d, 12 ,30);
1058         int total = 0;
1059         for (int i = 1; i < m; i++) {
1060             total += Month.of(i).length(isIsoLeap(y));
1061         }
1062         int doy = total + d;
1063         assertEquals(a.getDayOfYear(), doy);
1064     }
1065 
1066     @Test(dataProvider="sampleTimes", groups={"tck"})
1067     public void test_get_times(int h, int m, int s, int ns) {
1068         LocalDateTime a = LocalDateTime.of(TEST_2007_07_15_12_30_40_987654321.getDate(), LocalTime.of(h, m, s, ns));
1069         assertEquals(a.getHour(), h);
1070         assertEquals(a.getMinute(), m);
1071         assertEquals(a.getSecond(), s);
1072         assertEquals(a.getNano(), ns);
1073     }
1074 
1075     //-----------------------------------------------------------------------
1076     // getDayOfWeek()
1077     //-----------------------------------------------------------------------
1078     @Test(groups={"tck"})
1079     public void test_getDayOfWeek() {
1080         DayOfWeek dow = DayOfWeek.MONDAY;
1081         for (Month month : Month.values()) {
1082             int length = month.length(false);
1083             for (int i = 1; i <= length; i++) {
1084                 LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i),
1085                         TEST_2007_07_15_12_30_40_987654321.getTime());
1086                 assertSame(d.getDayOfWeek(), dow);
1087                 dow = dow.plus(1);
1088             }
1089         }
1090     }
1091 
1092     //-----------------------------------------------------------------------
1093     // with()
1094     //-----------------------------------------------------------------------
1095     @Test(groups={"tck"})
1096     public void test_with_adjustment() {
1097         final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5);
1098         TemporalAdjuster adjuster = new TemporalAdjuster() {
1099             @Override
1100             public Temporal adjustInto(Temporal dateTime) {
1101                 return sample;
1102             }
1103         };
1104         assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample);
1105     }
1106 
1107     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1108     public void test_with_adjustment_null() {
1109         TEST_2007_07_15_12_30_40_987654321.with((TemporalAdjuster) null);
1110     }
1111 
1112     //-----------------------------------------------------------------------
1113     // withYear()
1114     //-----------------------------------------------------------------------
1115     @Test(groups={"tck"})
1116     public void test_withYear_int_normal() {
1117         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withYear(2008);
1118         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1119     }
1120 
1121     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1122     public void test_withYear_int_invalid() {
1123         TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1);
1124     }
1125 
1126     @Test(groups={"tck"})
1127     public void test_withYear_int_adjustDay() {
1128         LocalDateTime t = LocalDateTime.of(2008, 2, 29, 12, 30).withYear(2007);
1129         LocalDateTime expected = LocalDateTime.of(2007, 2, 28, 12, 30);
1130         assertEquals(t, expected);
1131     }
1132 
1133     //-----------------------------------------------------------------------
1134     // withMonth()
1135     //-----------------------------------------------------------------------
1136     @Test(groups={"tck"})
1137     public void test_withMonth_int_normal() {
1138         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withMonth(1);
1139         check(t, 2007, 1, 15, 12, 30, 40, 987654321);
1140     }
1141 
1142     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1143     public void test_withMonth_int_invalid() {
1144         TEST_2007_07_15_12_30_40_987654321.withMonth(13);
1145     }
1146 
1147     @Test(groups={"tck"})
1148     public void test_withMonth_int_adjustDay() {
1149         LocalDateTime t = LocalDateTime.of(2007, 12, 31, 12, 30).withMonth(11);
1150         LocalDateTime expected = LocalDateTime.of(2007, 11, 30, 12, 30);
1151         assertEquals(t, expected);
1152     }
1153 
1154     //-----------------------------------------------------------------------
1155     // withDayOfMonth()
1156     //-----------------------------------------------------------------------
1157     @Test(groups={"tck"})
1158     public void test_withDayOfMonth_normal() {
1159         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfMonth(1);
1160         check(t, 2007, 7, 1, 12, 30, 40, 987654321);
1161     }
1162 
1163     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1164     public void test_withDayOfMonth_invalid() {
1165         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(32);
1166     }
1167 
1168     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1169     public void test_withDayOfMonth_invalidCombination() {
1170         LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(31);
1171     }
1172 
1173     //-----------------------------------------------------------------------
1174     // withDayOfYear(int)
1175     //-----------------------------------------------------------------------
1176     @Test(groups={"tck"})
1177     public void test_withDayOfYear_normal() {
1178         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfYear(33);
1179         assertEquals(t, LocalDateTime.of(2007, 2, 2, 12, 30, 40, 987654321));
1180     }
1181 
1182     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1183     public void test_withDayOfYear_illegal() {
1184         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(367);
1185     }
1186 
1187     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1188     public void test_withDayOfYear_invalid() {
1189         TEST_2007_07_15_12_30_40_987654321.withDayOfYear(366);
1190     }
1191 
1192     //-----------------------------------------------------------------------
1193     // withHour()
1194     //-----------------------------------------------------------------------
1195     @Test(groups={"tck"})
1196     public void test_withHour_normal() {
1197         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1198         for (int i = 0; i < 24; i++) {
1199             t = t.withHour(i);
1200             assertEquals(t.getHour(), i);
1201         }
1202     }
1203 
1204     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1205     public void test_withHour_hourTooLow() {
1206         TEST_2007_07_15_12_30_40_987654321.withHour(-1);
1207     }
1208 
1209     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1210     public void test_withHour_hourTooHigh() {
1211         TEST_2007_07_15_12_30_40_987654321.withHour(24);
1212     }
1213 
1214     //-----------------------------------------------------------------------
1215     // withMinute()
1216     //-----------------------------------------------------------------------
1217     @Test(groups={"tck"})
1218     public void test_withMinute_normal() {
1219         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1220         for (int i = 0; i < 60; i++) {
1221             t = t.withMinute(i);
1222             assertEquals(t.getMinute(), i);
1223         }
1224     }
1225 
1226     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1227     public void test_withMinute_minuteTooLow() {
1228         TEST_2007_07_15_12_30_40_987654321.withMinute(-1);
1229     }
1230 
1231     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1232     public void test_withMinute_minuteTooHigh() {
1233         TEST_2007_07_15_12_30_40_987654321.withMinute(60);
1234     }
1235 
1236     //-----------------------------------------------------------------------
1237     // withSecond()
1238     //-----------------------------------------------------------------------
1239     @Test(groups={"tck"})
1240     public void test_withSecond_normal() {
1241         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1242         for (int i = 0; i < 60; i++) {
1243             t = t.withSecond(i);
1244             assertEquals(t.getSecond(), i);
1245         }
1246     }
1247 
1248     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1249     public void test_withSecond_secondTooLow() {
1250         TEST_2007_07_15_12_30_40_987654321.withSecond(-1);
1251     }
1252 
1253     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1254     public void test_withSecond_secondTooHigh() {
1255         TEST_2007_07_15_12_30_40_987654321.withSecond(60);
1256     }
1257 
1258     //-----------------------------------------------------------------------
1259     // withNano()
1260     //-----------------------------------------------------------------------
1261     @Test(groups={"tck"})
1262     public void test_withNanoOfSecond_normal() {
1263         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
1264         t = t.withNano(1);
1265         assertEquals(t.getNano(), 1);
1266         t = t.withNano(10);
1267         assertEquals(t.getNano(), 10);
1268         t = t.withNano(100);
1269         assertEquals(t.getNano(), 100);
1270         t = t.withNano(999999999);
1271         assertEquals(t.getNano(), 999999999);
1272     }
1273 
1274     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1275     public void test_withNanoOfSecond_nanoTooLow() {
1276         TEST_2007_07_15_12_30_40_987654321.withNano(-1);
1277     }
1278 
1279     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1280     public void test_withNanoOfSecond_nanoTooHigh() {
1281         TEST_2007_07_15_12_30_40_987654321.withNano(1000000000);
1282     }
1283 
1284     //-----------------------------------------------------------------------
1285     // truncatedTo(TemporalUnit)
1286     //-----------------------------------------------------------------------
1287     @Test(groups={"tck"})
1288     public void test_truncatedTo_normal() {
1289         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(NANOS), TEST_2007_07_15_12_30_40_987654321);
1290         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(SECONDS), TEST_2007_07_15_12_30_40_987654321.withNano(0));
1291         assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(DAYS), TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT));
1292     }
1293 
1294     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1295     public void test_truncatedTo_null() {
1296         TEST_2007_07_15_12_30_40_987654321.truncatedTo(null);
1297     }
1298 
1299     //-----------------------------------------------------------------------
1300     // plus(adjuster)
1301     //-----------------------------------------------------------------------
1302     @Test(groups={"tck"})
1303     public void test_plus_adjuster() {
1304         Period p = Period.ofTime(0, 0, 62, 3);
1305         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(p);
1306         assertEquals(t, LocalDateTime.of(2007, 7, 15, 12, 31, 42, 987654324));
1307     }
1308 
1309     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1310     public void test_plus_adjuster_null() {
1311         TEST_2007_07_15_12_30_40_987654321.plus((TemporalAdder) null);
1312     }
1313 
1314     //-----------------------------------------------------------------------
1315     // plus(Period)
1316     //-----------------------------------------------------------------------
1317     @Test(groups={"tck"})
1318     public void test_plus_Period_positiveMonths() {
1319         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1320         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1321         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1322     }
1323 
1324     @Test(groups={"tck"})
1325     public void test_plus_Period_negativeDays() {
1326         MockSimplePeriod period = MockSimplePeriod.of(-25, ChronoUnit.DAYS);
1327         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period);
1328         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1329     }
1330 
1331     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1332     public void test_plus_Period_null() {
1333         TEST_2007_07_15_12_30_40_987654321.plus((MockSimplePeriod) null);
1334     }
1335 
1336     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1337     public void test_plus_Period_invalidTooLarge() {
1338         MockSimplePeriod period = MockSimplePeriod.of(1, ChronoUnit.YEARS);
1339         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(period);
1340     }
1341 
1342     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1343     public void test_plus_Period_invalidTooSmall() {
1344         MockSimplePeriod period = MockSimplePeriod.of(-1, ChronoUnit.YEARS);
1345         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(period);
1346     }
1347 
1348     //-----------------------------------------------------------------------
1349     // plus(long,TemporalUnit)
1350     //-----------------------------------------------------------------------
1351     @Test(groups={"tck"})
1352     public void test_plus_longTemporalUnit_positiveMonths() {
1353         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(7, ChronoUnit.MONTHS);
1354         assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321));
1355     }
1356 
1357     @Test(groups={"tck"})
1358     public void test_plus_longTemporalUnit_negativeDays() {
1359         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(-25, ChronoUnit.DAYS);
1360         assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321));
1361     }
1362 
1363     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1364     public void test_plus_longTemporalUnit_null() {
1365         TEST_2007_07_15_12_30_40_987654321.plus(1, (TemporalUnit) null);
1366     }
1367 
1368     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1369     public void test_plus_longTemporalUnit_invalidTooLarge() {
1370         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(1, ChronoUnit.YEARS);
1371     }
1372 
1373     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1374     public void test_plus_longTemporalUnit_invalidTooSmall() {
1375         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(-1, ChronoUnit.YEARS);
1376     }
1377 
1378     //-----------------------------------------------------------------------
1379     // plusYears()
1380     //-----------------------------------------------------------------------
1381     @Test(groups={"tck"})
1382     public void test_plusYears_int_normal() {
1383         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1);
1384         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1385     }
1386 
1387     @Test(groups={"tck"})
1388     public void test_plusYears_int_negative() {
1389         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1);
1390         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
1391     }
1392 
1393     @Test(groups={"tck"})
1394     public void test_plusYears_int_adjustDay() {
1395         LocalDateTime t = createDateMidnight(2008, 2, 29).plusYears(1);
1396         check(t, 2009, 2, 28, 0, 0, 0, 0);
1397     }
1398 
1399     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1400     public void test_plusYears_int_invalidTooLarge() {
1401         createDateMidnight(Year.MAX_VALUE, 1, 1).plusYears(1);
1402     }
1403 
1404     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1405     public void test_plusYears_int_invalidTooSmall() {
1406         LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-1);
1407     }
1408 
1409     //-----------------------------------------------------------------------
1410     // plusMonths()
1411     //-----------------------------------------------------------------------
1412     @Test(groups={"tck"})
1413     public void test_plusMonths_int_normal() {
1414         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(1);
1415         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
1416     }
1417 
1418     @Test(groups={"tck"})
1419     public void test_plusMonths_int_overYears() {
1420         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(25);
1421         check(t, 2009, 8, 15, 12, 30, 40, 987654321);
1422     }
1423 
1424     @Test(groups={"tck"})
1425     public void test_plusMonths_int_negative() {
1426         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-1);
1427         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
1428     }
1429 
1430     @Test(groups={"tck"})
1431     public void test_plusMonths_int_negativeAcrossYear() {
1432         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-7);
1433         check(t, 2006, 12, 15, 12, 30, 40, 987654321);
1434     }
1435 
1436     @Test(groups={"tck"})
1437     public void test_plusMonths_int_negativeOverYears() {
1438         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-31);
1439         check(t, 2004, 12, 15, 12, 30, 40, 987654321);
1440     }
1441 
1442     @Test(groups={"tck"})
1443     public void test_plusMonths_int_adjustDayFromLeapYear() {
1444         LocalDateTime t = createDateMidnight(2008, 2, 29).plusMonths(12);
1445         check(t, 2009, 2, 28, 0, 0, 0, 0);
1446     }
1447 
1448     @Test(groups={"tck"})
1449     public void test_plusMonths_int_adjustDayFromMonthLength() {
1450         LocalDateTime t = createDateMidnight(2007, 3, 31).plusMonths(1);
1451         check(t, 2007, 4, 30, 0, 0, 0, 0);
1452     }
1453 
1454     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1455     public void test_plusMonths_int_invalidTooLarge() {
1456         createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1);
1457     }
1458 
1459     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1460     public void test_plusMonths_int_invalidTooSmall() {
1461         createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1);
1462     }
1463 
1464     //-----------------------------------------------------------------------
1465     // plusWeeks()
1466     //-----------------------------------------------------------------------
1467     @DataProvider(name="samplePlusWeeksSymmetry")
1468     Object[][] provider_samplePlusWeeksSymmetry() {
1469         return new Object[][] {
1470             {createDateMidnight(-1, 1, 1)},
1471             {createDateMidnight(-1, 2, 28)},
1472             {createDateMidnight(-1, 3, 1)},
1473             {createDateMidnight(-1, 12, 31)},
1474             {createDateMidnight(0, 1, 1)},
1475             {createDateMidnight(0, 2, 28)},
1476             {createDateMidnight(0, 2, 29)},
1477             {createDateMidnight(0, 3, 1)},
1478             {createDateMidnight(0, 12, 31)},
1479             {createDateMidnight(2007, 1, 1)},
1480             {createDateMidnight(2007, 2, 28)},
1481             {createDateMidnight(2007, 3, 1)},
1482             {createDateMidnight(2007, 12, 31)},
1483             {createDateMidnight(2008, 1, 1)},
1484             {createDateMidnight(2008, 2, 28)},
1485             {createDateMidnight(2008, 2, 29)},
1486             {createDateMidnight(2008, 3, 1)},
1487             {createDateMidnight(2008, 12, 31)},
1488             {createDateMidnight(2099, 1, 1)},
1489             {createDateMidnight(2099, 2, 28)},
1490             {createDateMidnight(2099, 3, 1)},
1491             {createDateMidnight(2099, 12, 31)},
1492             {createDateMidnight(2100, 1, 1)},
1493             {createDateMidnight(2100, 2, 28)},
1494             {createDateMidnight(2100, 3, 1)},
1495             {createDateMidnight(2100, 12, 31)},
1496         };
1497     }
1498 
1499     @Test(dataProvider="samplePlusWeeksSymmetry", groups={"tck"})
1500     public void test_plusWeeks_symmetry(LocalDateTime reference) {
1501         for (int weeks = 0; weeks < 365 * 8; weeks++) {
1502             LocalDateTime t = reference.plusWeeks(weeks).plusWeeks(-weeks);
1503             assertEquals(t, reference);
1504 
1505             t = reference.plusWeeks(-weeks).plusWeeks(weeks);
1506             assertEquals(t, reference);
1507         }
1508     }
1509 
1510     @Test(groups={"tck"})
1511     public void test_plusWeeks_normal() {
1512         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(1);
1513         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
1514     }
1515 
1516     @Test(groups={"tck"})
1517     public void test_plusWeeks_overMonths() {
1518         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(9);
1519         check(t, 2007, 9, 16, 12, 30, 40, 987654321);
1520     }
1521 
1522     @Test(groups={"tck"})
1523     public void test_plusWeeks_overYears() {
1524         LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52);
1525         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1526     }
1527 
1528     @Test(groups={"tck"})
1529     public void test_plusWeeks_overLeapYears() {
1530         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusWeeks(104);
1531         check(t, 2008, 7, 12, 12, 30, 40, 987654321);
1532     }
1533 
1534     @Test(groups={"tck"})
1535     public void test_plusWeeks_negative() {
1536         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-1);
1537         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
1538     }
1539 
1540     @Test(groups={"tck"})
1541     public void test_plusWeeks_negativeAcrossYear() {
1542         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-28);
1543         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1544     }
1545 
1546     @Test(groups={"tck"})
1547     public void test_plusWeeks_negativeOverYears() {
1548         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-104);
1549         check(t, 2005, 7, 17, 12, 30, 40, 987654321);
1550     }
1551 
1552     @Test(groups={"tck"})
1553     public void test_plusWeeks_maximum() {
1554         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).plusWeeks(1);
1555         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1556     }
1557 
1558     @Test(groups={"tck"})
1559     public void test_plusWeeks_minimum() {
1560         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).plusWeeks(-1);
1561         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1562     }
1563 
1564     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1565     public void test_plusWeeks_invalidTooLarge() {
1566         createDateMidnight(Year.MAX_VALUE, 12, 25).plusWeeks(1);
1567     }
1568 
1569     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1570     public void test_plusWeeks_invalidTooSmall() {
1571         createDateMidnight(Year.MIN_VALUE, 1, 7).plusWeeks(-1);
1572     }
1573 
1574     //-----------------------------------------------------------------------
1575     // plusDays()
1576     //-----------------------------------------------------------------------
1577     @DataProvider(name="samplePlusDaysSymmetry")
1578     Object[][] provider_samplePlusDaysSymmetry() {
1579         return new Object[][] {
1580             {createDateMidnight(-1, 1, 1)},
1581             {createDateMidnight(-1, 2, 28)},
1582             {createDateMidnight(-1, 3, 1)},
1583             {createDateMidnight(-1, 12, 31)},
1584             {createDateMidnight(0, 1, 1)},
1585             {createDateMidnight(0, 2, 28)},
1586             {createDateMidnight(0, 2, 29)},
1587             {createDateMidnight(0, 3, 1)},
1588             {createDateMidnight(0, 12, 31)},
1589             {createDateMidnight(2007, 1, 1)},
1590             {createDateMidnight(2007, 2, 28)},
1591             {createDateMidnight(2007, 3, 1)},
1592             {createDateMidnight(2007, 12, 31)},
1593             {createDateMidnight(2008, 1, 1)},
1594             {createDateMidnight(2008, 2, 28)},
1595             {createDateMidnight(2008, 2, 29)},
1596             {createDateMidnight(2008, 3, 1)},
1597             {createDateMidnight(2008, 12, 31)},
1598             {createDateMidnight(2099, 1, 1)},
1599             {createDateMidnight(2099, 2, 28)},
1600             {createDateMidnight(2099, 3, 1)},
1601             {createDateMidnight(2099, 12, 31)},
1602             {createDateMidnight(2100, 1, 1)},
1603             {createDateMidnight(2100, 2, 28)},
1604             {createDateMidnight(2100, 3, 1)},
1605             {createDateMidnight(2100, 12, 31)},
1606         };
1607     }
1608 
1609     @Test(dataProvider="samplePlusDaysSymmetry", groups={"tck"})
1610     public void test_plusDays_symmetry(LocalDateTime reference) {
1611         for (int days = 0; days < 365 * 8; days++) {
1612             LocalDateTime t = reference.plusDays(days).plusDays(-days);
1613             assertEquals(t, reference);
1614 
1615             t = reference.plusDays(-days).plusDays(days);
1616             assertEquals(t, reference);
1617         }
1618     }
1619 
1620     @Test(groups={"tck"})
1621     public void test_plusDays_normal() {
1622         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(1);
1623         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
1624     }
1625 
1626     @Test(groups={"tck"})
1627     public void test_plusDays_overMonths() {
1628         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(62);
1629         check(t, 2007, 9, 15, 12, 30, 40, 987654321);
1630     }
1631 
1632     @Test(groups={"tck"})
1633     public void test_plusDays_overYears() {
1634         LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366);
1635         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
1636     }
1637 
1638     @Test(groups={"tck"})
1639     public void test_plusDays_overLeapYears() {
1640         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusDays(365 + 366);
1641         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
1642     }
1643 
1644     @Test(groups={"tck"})
1645     public void test_plusDays_negative() {
1646         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-1);
1647         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
1648     }
1649 
1650     @Test(groups={"tck"})
1651     public void test_plusDays_negativeAcrossYear() {
1652         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-196);
1653         check(t, 2006, 12, 31, 12, 30, 40, 987654321);
1654     }
1655 
1656     @Test(groups={"tck"})
1657     public void test_plusDays_negativeOverYears() {
1658         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-730);
1659         check(t, 2005, 7, 15, 12, 30, 40, 987654321);
1660     }
1661 
1662     @Test(groups={"tck"})
1663     public void test_plusDays_maximum() {
1664         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).plusDays(1);
1665         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
1666     }
1667 
1668     @Test(groups={"tck"})
1669     public void test_plusDays_minimum() {
1670         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).plusDays(-1);
1671         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
1672     }
1673 
1674     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1675     public void test_plusDays_invalidTooLarge() {
1676         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(1);
1677     }
1678 
1679     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1680     public void test_plusDays_invalidTooSmall() {
1681         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(-1);
1682     }
1683 
1684     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
1685     public void test_plusDays_overflowTooLarge() {
1686         createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(Long.MAX_VALUE);
1687     }
1688 
1689     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
1690     public void test_plusDays_overflowTooSmall() {
1691         createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(Long.MIN_VALUE);
1692     }
1693 
1694     //-----------------------------------------------------------------------
1695     // plusHours()
1696     //-----------------------------------------------------------------------
1697     @Test(groups={"tck"})
1698     public void test_plusHours_one() {
1699         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1700         LocalDate d = t.getDate();
1701 
1702         for (int i = 0; i < 50; i++) {
1703             t = t.plusHours(1);
1704 
1705             if ((i + 1) % 24 == 0) {
1706                 d = d.plusDays(1);
1707             }
1708 
1709             assertEquals(t.getDate(), d);
1710             assertEquals(t.getHour(), (i + 1) % 24);
1711         }
1712     }
1713 
1714     @Test(groups={"tck"})
1715     public void test_plusHours_fromZero() {
1716         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1717         LocalDate d = base.getDate().minusDays(3);
1718         LocalTime t = LocalTime.of(21, 0);
1719 
1720         for (int i = -50; i < 50; i++) {
1721             LocalDateTime dt = base.plusHours(i);
1722             t = t.plusHours(1);
1723 
1724             if (t.getHour() == 0) {
1725                 d = d.plusDays(1);
1726             }
1727 
1728             assertEquals(dt.getDate(), d);
1729             assertEquals(dt.getTime(), t);
1730         }
1731     }
1732 
1733     @Test(groups={"tck"})
1734     public void test_plusHours_fromOne() {
1735         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
1736         LocalDate d = base.getDate().minusDays(3);
1737         LocalTime t = LocalTime.of(22, 0);
1738 
1739         for (int i = -50; i < 50; i++) {
1740             LocalDateTime dt = base.plusHours(i);
1741 
1742             t = t.plusHours(1);
1743 
1744             if (t.getHour() == 0) {
1745                 d = d.plusDays(1);
1746             }
1747 
1748             assertEquals(dt.getDate(), d);
1749             assertEquals(dt.getTime(), t);
1750         }
1751     }
1752 
1753     //-----------------------------------------------------------------------
1754     // plusMinutes()
1755     //-----------------------------------------------------------------------
1756     @Test(groups={"tck"})
1757     public void test_plusMinutes_one() {
1758         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1759         LocalDate d = t.getDate();
1760 
1761         int hour = 0;
1762         int min = 0;
1763 
1764         for (int i = 0; i < 70; i++) {
1765             t = t.plusMinutes(1);
1766             min++;
1767             if (min == 60) {
1768                 hour++;
1769                 min = 0;
1770             }
1771 
1772             assertEquals(t.getDate(), d);
1773             assertEquals(t.getHour(), hour);
1774             assertEquals(t.getMinute(), min);
1775         }
1776     }
1777 
1778     @Test(groups={"tck"})
1779     public void test_plusMinutes_fromZero() {
1780         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1781         LocalDate d = base.getDate().minusDays(1);
1782         LocalTime t = LocalTime.of(22, 49);
1783 
1784         for (int i = -70; i < 70; i++) {
1785             LocalDateTime dt = base.plusMinutes(i);
1786             t = t.plusMinutes(1);
1787 
1788             if (t == LocalTime.MIDNIGHT) {
1789                 d = d.plusDays(1);
1790             }
1791 
1792             assertEquals(dt.getDate(), d, String.valueOf(i));
1793             assertEquals(dt.getTime(), t, String.valueOf(i));
1794         }
1795     }
1796 
1797     @Test(groups={"tck"})
1798     public void test_plusMinutes_noChange_oneDay() {
1799         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60);
1800         assertEquals(t.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().plusDays(1));
1801     }
1802 
1803     //-----------------------------------------------------------------------
1804     // plusSeconds()
1805     //-----------------------------------------------------------------------
1806     @Test(groups={"tck"})
1807     public void test_plusSeconds_one() {
1808         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1809         LocalDate d = t.getDate();
1810 
1811         int hour = 0;
1812         int min = 0;
1813         int sec = 0;
1814 
1815         for (int i = 0; i < 3700; i++) {
1816             t = t.plusSeconds(1);
1817             sec++;
1818             if (sec == 60) {
1819                 min++;
1820                 sec = 0;
1821             }
1822             if (min == 60) {
1823                 hour++;
1824                 min = 0;
1825             }
1826 
1827             assertEquals(t.getDate(), d);
1828             assertEquals(t.getHour(), hour);
1829             assertEquals(t.getMinute(), min);
1830             assertEquals(t.getSecond(), sec);
1831         }
1832     }
1833 
1834     @DataProvider(name="plusSeconds_fromZero")
1835     Iterator<Object[]> plusSeconds_fromZero() {
1836         return new Iterator<Object[]>() {
1837             int delta = 30;
1838 
1839             int i = -3660;
1840             LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1);
1841             int hour = 22;
1842             int min = 59;
1843             int sec = 0;
1844 
1845             public boolean hasNext() {
1846                 return i <= 3660;
1847             }
1848 
1849             public Object[] next() {
1850                 final Object[] ret = new Object[] {i, date, hour, min, sec};
1851                 i += delta;
1852                 sec += delta;
1853 
1854                 if (sec >= 60) {
1855                     min++;
1856                     sec -= 60;
1857 
1858                     if (min == 60) {
1859                         hour++;
1860                         min = 0;
1861 
1862                         if (hour == 24) {
1863                             hour = 0;
1864                         }
1865                     }
1866                 }
1867 
1868                 if (i == 0) {
1869                     date = date.plusDays(1);
1870                 }
1871 
1872                 return ret;
1873             }
1874 
1875             public void remove() {
1876                 throw new UnsupportedOperationException();
1877             }
1878         };
1879     }
1880 
1881     @Test(dataProvider="plusSeconds_fromZero", groups={"tck"})
1882     public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
1883         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1884         LocalDateTime t = base.plusSeconds(seconds);
1885 
1886         assertEquals(date, t.getDate());
1887         assertEquals(hour, t.getHour());
1888         assertEquals(min, t.getMinute());
1889         assertEquals(sec, t.getSecond());
1890     }
1891 
1892     @Test(groups={"tck"})
1893     public void test_plusSeconds_noChange_oneDay() {
1894         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusSeconds(24 * 60 * 60);
1895         assertEquals(t.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().plusDays(1));
1896     }
1897 
1898     //-----------------------------------------------------------------------
1899     // plusNanos()
1900     //-----------------------------------------------------------------------
1901     @Test(groups={"tck"})
1902     public void test_plusNanos_halfABillion() {
1903         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1904         LocalDate d = t.getDate();
1905 
1906         int hour = 0;
1907         int min = 0;
1908         int sec = 0;
1909         int nanos = 0;
1910 
1911         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
1912             t = t.plusNanos(500000000);
1913             nanos += 500000000;
1914             if (nanos == 1000000000) {
1915                 sec++;
1916                 nanos = 0;
1917             }
1918             if (sec == 60) {
1919                 min++;
1920                 sec = 0;
1921             }
1922             if (min == 60) {
1923                 hour++;
1924                 min = 0;
1925             }
1926 
1927             assertEquals(t.getDate(), d, String.valueOf(i));
1928             assertEquals(t.getHour(), hour);
1929             assertEquals(t.getMinute(), min);
1930             assertEquals(t.getSecond(), sec);
1931             assertEquals(t.getNano(), nanos);
1932         }
1933     }
1934 
1935     @DataProvider(name="plusNanos_fromZero")
1936     Iterator<Object[]> plusNanos_fromZero() {
1937         return new Iterator<Object[]>() {
1938             long delta = 7500000000L;
1939 
1940             long i = -3660 * 1000000000L;
1941             LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1);
1942             int hour = 22;
1943             int min = 59;
1944             int sec = 0;
1945             long nanos = 0;
1946 
1947             public boolean hasNext() {
1948                 return i <= 3660 * 1000000000L;
1949             }
1950 
1951             public Object[] next() {
1952                 final Object[] ret = new Object[] {i, date, hour, min, sec, (int)nanos};
1953                 i += delta;
1954                 nanos += delta;
1955 
1956                 if (nanos >= 1000000000L) {
1957                     sec += nanos / 1000000000L;
1958                     nanos %= 1000000000L;
1959 
1960                     if (sec >= 60) {
1961                         min++;
1962                         sec %= 60;
1963 
1964                         if (min == 60) {
1965                             hour++;
1966                             min = 0;
1967 
1968                             if (hour == 24) {
1969                                 hour = 0;
1970                                 date = date.plusDays(1);
1971                             }
1972                         }
1973                     }
1974                 }
1975 
1976                 return ret;
1977             }
1978 
1979             public void remove() {
1980                 throw new UnsupportedOperationException();
1981             }
1982         };
1983     }
1984 
1985     @Test(dataProvider="plusNanos_fromZero", groups={"tck"})
1986     public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
1987         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
1988         LocalDateTime t = base.plusNanos(nanoseconds);
1989 
1990         assertEquals(date, t.getDate());
1991         assertEquals(hour, t.getHour());
1992         assertEquals(min, t.getMinute());
1993         assertEquals(sec, t.getSecond());
1994         assertEquals(nanos, t.getNano());
1995     }
1996 
1997     @Test(groups={"tck"})
1998     public void test_plusNanos_noChange_oneDay() {
1999         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L);
2000         assertEquals(t.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().plusDays(1));
2001     }
2002 
2003     //-----------------------------------------------------------------------
2004     // minus(adjuster)
2005     //-----------------------------------------------------------------------
2006     @Test(groups={"tck"})
2007     public void test_minus_adjuster() {
2008         Period p = Period.ofTime(0, 0, 62, 3);
2009         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(p);
2010         assertEquals(t, LocalDateTime.of(2007, 7, 15, 12, 29, 38, 987654318));
2011     }
2012 
2013     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2014     public void test_minus_adjuster_null() {
2015         TEST_2007_07_15_12_30_40_987654321.minus((TemporalSubtractor) null);
2016     }
2017 
2018     //-----------------------------------------------------------------------
2019     // minus(Period)
2020     //-----------------------------------------------------------------------
2021     @Test(groups={"tck"})
2022     public void test_minus_Period_positiveMonths() {
2023         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
2024         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
2025         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
2026     }
2027 
2028     @Test(groups={"tck"})
2029     public void test_minus_Period_negativeDays() {
2030         MockSimplePeriod period = MockSimplePeriod.of(-25, ChronoUnit.DAYS);
2031         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period);
2032         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));
2033     }
2034 
2035     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2036     public void test_minus_Period_null() {
2037         TEST_2007_07_15_12_30_40_987654321.minus((MockSimplePeriod) null);
2038     }
2039 
2040     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2041     public void test_minus_Period_invalidTooLarge() {
2042         MockSimplePeriod period = MockSimplePeriod.of(-1, ChronoUnit.YEARS);
2043         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(period);
2044     }
2045 
2046     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2047     public void test_minus_Period_invalidTooSmall() {
2048         MockSimplePeriod period = MockSimplePeriod.of(1, ChronoUnit.YEARS);
2049         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period);
2050     }
2051 
2052     //-----------------------------------------------------------------------
2053     // minus(long,TemporalUnit)
2054     //-----------------------------------------------------------------------
2055     @Test(groups={"tck"})
2056     public void test_minus_longTemporalUnit_positiveMonths() {
2057         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(7, ChronoUnit.MONTHS);
2058         assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321));
2059     }
2060 
2061     @Test(groups={"tck"})
2062     public void test_minus_longTemporalUnit_negativeDays() {
2063         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(-25, ChronoUnit.DAYS);
2064         assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321));
2065     }
2066 
2067     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2068     public void test_minus_longTemporalUnit_null() {
2069         TEST_2007_07_15_12_30_40_987654321.minus(1, (TemporalUnit) null);
2070     }
2071 
2072     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2073     public void test_minus_longTemporalUnit_invalidTooLarge() {
2074         LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(-1, ChronoUnit.YEARS);
2075     }
2076 
2077     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2078     public void test_minus_longTemporalUnit_invalidTooSmall() {
2079         LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(1, ChronoUnit.YEARS);
2080     }
2081 
2082     //-----------------------------------------------------------------------
2083     // minusYears()
2084     //-----------------------------------------------------------------------
2085     @Test(groups={"tck"})
2086     public void test_minusYears_int_normal() {
2087         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(1);
2088         check(t, 2006, 7, 15, 12, 30, 40, 987654321);
2089     }
2090 
2091     @Test(groups={"tck"})
2092     public void test_minusYears_int_negative() {
2093         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1);
2094         check(t, 2008, 7, 15, 12, 30, 40, 987654321);
2095     }
2096 
2097     @Test(groups={"tck"})
2098     public void test_minusYears_int_adjustDay() {
2099         LocalDateTime t = createDateMidnight(2008, 2, 29).minusYears(1);
2100         check(t, 2007, 2, 28, 0, 0, 0, 0);
2101     }
2102 
2103     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2104     public void test_minusYears_int_invalidTooLarge() {
2105         createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1);
2106     }
2107 
2108     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2109     public void test_minusYears_int_invalidTooSmall() {
2110         createDateMidnight(Year.MIN_VALUE, 1, 1).minusYears(1);
2111     }
2112 
2113     //-----------------------------------------------------------------------
2114     // minusMonths()
2115     //-----------------------------------------------------------------------
2116     @Test(groups={"tck"})
2117     public void test_minusMonths_int_normal() {
2118         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(1);
2119         check(t, 2007, 6, 15, 12, 30, 40, 987654321);
2120     }
2121 
2122     @Test(groups={"tck"})
2123     public void test_minusMonths_int_overYears() {
2124         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(25);
2125         check(t, 2005, 6, 15, 12, 30, 40, 987654321);
2126     }
2127 
2128     @Test(groups={"tck"})
2129     public void test_minusMonths_int_negative() {
2130         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-1);
2131         check(t, 2007, 8, 15, 12, 30, 40, 987654321);
2132     }
2133 
2134     @Test(groups={"tck"})
2135     public void test_minusMonths_int_negativeAcrossYear() {
2136         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-7);
2137         check(t, 2008, 2, 15, 12, 30, 40, 987654321);
2138     }
2139 
2140     @Test(groups={"tck"})
2141     public void test_minusMonths_int_negativeOverYears() {
2142         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-31);
2143         check(t, 2010, 2, 15, 12, 30, 40, 987654321);
2144     }
2145 
2146     @Test(groups={"tck"})
2147     public void test_minusMonths_int_adjustDayFromLeapYear() {
2148         LocalDateTime t = createDateMidnight(2008, 2, 29).minusMonths(12);
2149         check(t, 2007, 2, 28, 0, 0, 0, 0);
2150     }
2151 
2152     @Test(groups={"tck"})
2153     public void test_minusMonths_int_adjustDayFromMonthLength() {
2154         LocalDateTime t = createDateMidnight(2007, 3, 31).minusMonths(1);
2155         check(t, 2007, 2, 28, 0, 0, 0, 0);
2156     }
2157 
2158     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2159     public void test_minusMonths_int_invalidTooLarge() {
2160         createDateMidnight(Year.MAX_VALUE, 12, 1).minusMonths(-1);
2161     }
2162 
2163     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2164     public void test_minusMonths_int_invalidTooSmall() {
2165         createDateMidnight(Year.MIN_VALUE, 1, 1).minusMonths(1);
2166     }
2167 
2168     //-----------------------------------------------------------------------
2169     // minusWeeks()
2170     //-----------------------------------------------------------------------
2171     @DataProvider(name="sampleMinusWeeksSymmetry")
2172     Object[][] provider_sampleMinusWeeksSymmetry() {
2173         return new Object[][] {
2174             {createDateMidnight(-1, 1, 1)},
2175             {createDateMidnight(-1, 2, 28)},
2176             {createDateMidnight(-1, 3, 1)},
2177             {createDateMidnight(-1, 12, 31)},
2178             {createDateMidnight(0, 1, 1)},
2179             {createDateMidnight(0, 2, 28)},
2180             {createDateMidnight(0, 2, 29)},
2181             {createDateMidnight(0, 3, 1)},
2182             {createDateMidnight(0, 12, 31)},
2183             {createDateMidnight(2007, 1, 1)},
2184             {createDateMidnight(2007, 2, 28)},
2185             {createDateMidnight(2007, 3, 1)},
2186             {createDateMidnight(2007, 12, 31)},
2187             {createDateMidnight(2008, 1, 1)},
2188             {createDateMidnight(2008, 2, 28)},
2189             {createDateMidnight(2008, 2, 29)},
2190             {createDateMidnight(2008, 3, 1)},
2191             {createDateMidnight(2008, 12, 31)},
2192             {createDateMidnight(2099, 1, 1)},
2193             {createDateMidnight(2099, 2, 28)},
2194             {createDateMidnight(2099, 3, 1)},
2195             {createDateMidnight(2099, 12, 31)},
2196             {createDateMidnight(2100, 1, 1)},
2197             {createDateMidnight(2100, 2, 28)},
2198             {createDateMidnight(2100, 3, 1)},
2199             {createDateMidnight(2100, 12, 31)},
2200         };
2201     }
2202 
2203     @Test(dataProvider="sampleMinusWeeksSymmetry", groups={"tck"})
2204     public void test_minusWeeks_symmetry(LocalDateTime reference) {
2205         for (int weeks = 0; weeks < 365 * 8; weeks++) {
2206             LocalDateTime t = reference.minusWeeks(weeks).minusWeeks(-weeks);
2207             assertEquals(t, reference);
2208 
2209             t = reference.minusWeeks(-weeks).minusWeeks(weeks);
2210             assertEquals(t, reference);
2211         }
2212     }
2213 
2214     @Test(groups={"tck"})
2215     public void test_minusWeeks_normal() {
2216         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(1);
2217         check(t, 2007, 7, 8, 12, 30, 40, 987654321);
2218     }
2219 
2220     @Test(groups={"tck"})
2221     public void test_minusWeeks_overMonths() {
2222         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9);
2223         check(t, 2007, 5, 13, 12, 30, 40, 987654321);
2224     }
2225 
2226     @Test(groups={"tck"})
2227     public void test_minusWeeks_overYears() {
2228         LocalDateTime t = LocalDateTime.of(2008, 7, 13, 12, 30, 40, 987654321).minusWeeks(52);
2229         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2230     }
2231 
2232     @Test(groups={"tck"})
2233     public void test_minusWeeks_overLeapYears() {
2234         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1).minusWeeks(104);
2235         check(t, 2006, 7, 18, 12, 30, 40, 987654321);
2236     }
2237 
2238     @Test(groups={"tck"})
2239     public void test_minusWeeks_negative() {
2240         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-1);
2241         check(t, 2007, 7, 22, 12, 30, 40, 987654321);
2242     }
2243 
2244     @Test(groups={"tck"})
2245     public void test_minusWeeks_negativeAcrossYear() {
2246         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-28);
2247         check(t, 2008, 1, 27, 12, 30, 40, 987654321);
2248     }
2249 
2250     @Test(groups={"tck"})
2251     public void test_minusWeeks_negativeOverYears() {
2252         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-104);
2253         check(t, 2009, 7, 12, 12, 30, 40, 987654321);
2254     }
2255 
2256     @Test(groups={"tck"})
2257     public void test_minusWeeks_maximum() {
2258         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).minusWeeks(-1);
2259         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2260     }
2261 
2262     @Test(groups={"tck"})
2263     public void test_minusWeeks_minimum() {
2264         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).minusWeeks(1);
2265         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2266     }
2267 
2268     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2269     public void test_minusWeeks_invalidTooLarge() {
2270         createDateMidnight(Year.MAX_VALUE, 12, 25).minusWeeks(-1);
2271     }
2272 
2273     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2274     public void test_minusWeeks_invalidTooSmall() {
2275         createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1);
2276     }
2277 
2278     //-----------------------------------------------------------------------
2279     // minusDays()
2280     //-----------------------------------------------------------------------
2281     @DataProvider(name="sampleMinusDaysSymmetry")
2282     Object[][] provider_sampleMinusDaysSymmetry() {
2283         return new Object[][] {
2284             {createDateMidnight(-1, 1, 1)},
2285             {createDateMidnight(-1, 2, 28)},
2286             {createDateMidnight(-1, 3, 1)},
2287             {createDateMidnight(-1, 12, 31)},
2288             {createDateMidnight(0, 1, 1)},
2289             {createDateMidnight(0, 2, 28)},
2290             {createDateMidnight(0, 2, 29)},
2291             {createDateMidnight(0, 3, 1)},
2292             {createDateMidnight(0, 12, 31)},
2293             {createDateMidnight(2007, 1, 1)},
2294             {createDateMidnight(2007, 2, 28)},
2295             {createDateMidnight(2007, 3, 1)},
2296             {createDateMidnight(2007, 12, 31)},
2297             {createDateMidnight(2008, 1, 1)},
2298             {createDateMidnight(2008, 2, 28)},
2299             {createDateMidnight(2008, 2, 29)},
2300             {createDateMidnight(2008, 3, 1)},
2301             {createDateMidnight(2008, 12, 31)},
2302             {createDateMidnight(2099, 1, 1)},
2303             {createDateMidnight(2099, 2, 28)},
2304             {createDateMidnight(2099, 3, 1)},
2305             {createDateMidnight(2099, 12, 31)},
2306             {createDateMidnight(2100, 1, 1)},
2307             {createDateMidnight(2100, 2, 28)},
2308             {createDateMidnight(2100, 3, 1)},
2309             {createDateMidnight(2100, 12, 31)},
2310         };
2311     }
2312 
2313     @Test(dataProvider="sampleMinusDaysSymmetry", groups={"tck"})
2314     public void test_minusDays_symmetry(LocalDateTime reference) {
2315         for (int days = 0; days < 365 * 8; days++) {
2316             LocalDateTime t = reference.minusDays(days).minusDays(-days);
2317             assertEquals(t, reference);
2318 
2319             t = reference.minusDays(-days).minusDays(days);
2320             assertEquals(t, reference);
2321         }
2322     }
2323 
2324     @Test(groups={"tck"})
2325     public void test_minusDays_normal() {
2326         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(1);
2327         check(t, 2007, 7, 14, 12, 30, 40, 987654321);
2328     }
2329 
2330     @Test(groups={"tck"})
2331     public void test_minusDays_overMonths() {
2332         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62);
2333         check(t, 2007, 5, 14, 12, 30, 40, 987654321);
2334     }
2335 
2336     @Test(groups={"tck"})
2337     public void test_minusDays_overYears() {
2338         LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367);
2339         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2340     }
2341 
2342     @Test(groups={"tck"})
2343     public void test_minusDays_overLeapYears() {
2344         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(2).minusDays(365 + 366);
2345         assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
2346     }
2347 
2348     @Test(groups={"tck"})
2349     public void test_minusDays_negative() {
2350         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-1);
2351         check(t, 2007, 7, 16, 12, 30, 40, 987654321);
2352     }
2353 
2354     @Test(groups={"tck"})
2355     public void test_minusDays_negativeAcrossYear() {
2356         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-169);
2357         check(t, 2007, 12, 31, 12, 30, 40, 987654321);
2358     }
2359 
2360     @Test(groups={"tck"})
2361     public void test_minusDays_negativeOverYears() {
2362         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-731);
2363         check(t, 2009, 7, 15, 12, 30, 40, 987654321);
2364     }
2365 
2366     @Test(groups={"tck"})
2367     public void test_minusDays_maximum() {
2368         LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).minusDays(-1);
2369         check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0);
2370     }
2371 
2372     @Test(groups={"tck"})
2373     public void test_minusDays_minimum() {
2374         LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).minusDays(1);
2375         check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0);
2376     }
2377 
2378     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2379     public void test_minusDays_invalidTooLarge() {
2380         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1);
2381     }
2382 
2383     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
2384     public void test_minusDays_invalidTooSmall() {
2385         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1);
2386     }
2387 
2388     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
2389     public void test_minusDays_overflowTooLarge() {
2390         createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(Long.MIN_VALUE);
2391     }
2392 
2393     @Test(expectedExceptions=ArithmeticException.class, groups={"tck"})
2394     public void test_minusDays_overflowTooSmall() {
2395         createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(Long.MAX_VALUE);
2396     }
2397 
2398     //-----------------------------------------------------------------------
2399     // minusHours()
2400     //-----------------------------------------------------------------------
2401     @Test(groups={"tck"})
2402     public void test_minusHours_one() {
2403         LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2404         LocalDate d = t.getDate();
2405 
2406         for (int i = 0; i < 50; i++) {
2407             t = t.minusHours(1);
2408 
2409             if (i % 24 == 0) {
2410                 d = d.minusDays(1);
2411             }
2412 
2413             assertEquals(t.getDate(), d);
2414             assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
2415         }
2416     }
2417 
2418     @Test(groups={"tck"})
2419     public void test_minusHours_fromZero() {
2420         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2421         LocalDate d = base.getDate().plusDays(2);
2422         LocalTime t = LocalTime.of(3, 0);
2423 
2424         for (int i = -50; i < 50; i++) {
2425             LocalDateTime dt = base.minusHours(i);
2426             t = t.minusHours(1);
2427 
2428             if (t.getHour() == 23) {
2429                 d = d.minusDays(1);
2430             }
2431 
2432             assertEquals(dt.getDate(), d, String.valueOf(i));
2433             assertEquals(dt.getTime(), t);
2434         }
2435     }
2436 
2437     @Test(groups={"tck"})
2438     public void test_minusHours_fromOne() {
2439         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
2440         LocalDate d = base.getDate().plusDays(2);
2441         LocalTime t = LocalTime.of(4, 0);
2442 
2443         for (int i = -50; i < 50; i++) {
2444             LocalDateTime dt = base.minusHours(i);
2445 
2446             t = t.minusHours(1);
2447 
2448             if (t.getHour() == 23) {
2449                 d = d.minusDays(1);
2450             }
2451 
2452             assertEquals(dt.getDate(), d, String.valueOf(i));
2453             assertEquals(dt.getTime(), t);
2454         }
2455     }
2456 
2457     //-----------------------------------------------------------------------
2458     // minusMinutes()
2459     //-----------------------------------------------------------------------
2460     @Test(groups={"tck"})
2461     public void test_minusMinutes_one() {
2462         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2463         LocalDate d = t.getDate().minusDays(1);
2464 
2465         int hour = 0;
2466         int min = 0;
2467 
2468         for (int i = 0; i < 70; i++) {
2469             t = t.minusMinutes(1);
2470             min--;
2471             if (min == -1) {
2472                 hour--;
2473                 min = 59;
2474 
2475                 if (hour == -1) {
2476                     hour = 23;
2477                 }
2478             }
2479             assertEquals(t.getDate(), d);
2480             assertEquals(t.getHour(), hour);
2481             assertEquals(t.getMinute(), min);
2482         }
2483     }
2484 
2485     @Test(groups={"tck"})
2486     public void test_minusMinutes_fromZero() {
2487         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2488         LocalDate d = base.getDate().minusDays(1);
2489         LocalTime t = LocalTime.of(22, 49);
2490 
2491         for (int i = 70; i > -70; i--) {
2492             LocalDateTime dt = base.minusMinutes(i);
2493             t = t.plusMinutes(1);
2494 
2495             if (t == LocalTime.MIDNIGHT) {
2496                 d = d.plusDays(1);
2497             }
2498 
2499             assertEquals(dt.getDate(), d);
2500             assertEquals(dt.getTime(), t);
2501         }
2502     }
2503 
2504     @Test(groups={"tck"})
2505     public void test_minusMinutes_noChange_oneDay() {
2506         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMinutes(24 * 60);
2507         assertEquals(t.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1));
2508     }
2509 
2510     //-----------------------------------------------------------------------
2511     // minusSeconds()
2512     //-----------------------------------------------------------------------
2513     @Test(groups={"tck"})
2514     public void test_minusSeconds_one() {
2515         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2516         LocalDate d = t.getDate().minusDays(1);
2517 
2518         int hour = 0;
2519         int min = 0;
2520         int sec = 0;
2521 
2522         for (int i = 0; i < 3700; i++) {
2523             t = t.minusSeconds(1);
2524             sec--;
2525             if (sec == -1) {
2526                 min--;
2527                 sec = 59;
2528 
2529                 if (min == -1) {
2530                     hour--;
2531                     min = 59;
2532 
2533                     if (hour == -1) {
2534                         hour = 23;
2535                     }
2536                 }
2537             }
2538 
2539             assertEquals(t.getDate(), d);
2540             assertEquals(t.getHour(), hour);
2541             assertEquals(t.getMinute(), min);
2542             assertEquals(t.getSecond(), sec);
2543         }
2544     }
2545 
2546     @DataProvider(name="minusSeconds_fromZero")
2547     Iterator<Object[]> minusSeconds_fromZero() {
2548         return new Iterator<Object[]>() {
2549             int delta = 30;
2550 
2551             int i = 3660;
2552             LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1);
2553             int hour = 22;
2554             int min = 59;
2555             int sec = 0;
2556 
2557             public boolean hasNext() {
2558                 return i >= -3660;
2559             }
2560 
2561             public Object[] next() {
2562                 final Object[] ret = new Object[] {i, date, hour, min, sec};
2563                 i -= delta;
2564                 sec += delta;
2565 
2566                 if (sec >= 60) {
2567                     min++;
2568                     sec -= 60;
2569 
2570                     if (min == 60) {
2571                         hour++;
2572                         min = 0;
2573 
2574                         if (hour == 24) {
2575                             hour = 0;
2576                         }
2577                     }
2578                 }
2579 
2580                 if (i == 0) {
2581                     date = date.plusDays(1);
2582                 }
2583 
2584                 return ret;
2585             }
2586 
2587             public void remove() {
2588                 throw new UnsupportedOperationException();
2589             }
2590         };
2591     }
2592 
2593     @Test(dataProvider="minusSeconds_fromZero", groups={"tck"})
2594     public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
2595         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2596         LocalDateTime t = base.minusSeconds(seconds);
2597 
2598         assertEquals(date, t.getDate());
2599         assertEquals(hour, t.getHour());
2600         assertEquals(min, t.getMinute());
2601         assertEquals(sec, t.getSecond());
2602     }
2603 
2604     //-----------------------------------------------------------------------
2605     // minusNanos()
2606     //-----------------------------------------------------------------------
2607     @Test(groups={"tck"})
2608     public void test_minusNanos_halfABillion() {
2609         LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2610         LocalDate d = t.getDate().minusDays(1);
2611 
2612         int hour = 0;
2613         int min = 0;
2614         int sec = 0;
2615         int nanos = 0;
2616 
2617         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
2618             t = t.minusNanos(500000000);
2619             nanos -= 500000000;
2620 
2621             if (nanos < 0) {
2622                 sec--;
2623                 nanos += 1000000000;
2624 
2625                 if (sec == -1) {
2626                     min--;
2627                     sec += 60;
2628 
2629                     if (min == -1) {
2630                         hour--;
2631                         min += 60;
2632 
2633                         if (hour == -1) {
2634                             hour += 24;
2635                         }
2636                     }
2637                 }
2638             }
2639 
2640             assertEquals(t.getDate(), d);
2641             assertEquals(t.getHour(), hour);
2642             assertEquals(t.getMinute(), min);
2643             assertEquals(t.getSecond(), sec);
2644             assertEquals(t.getNano(), nanos);
2645         }
2646     }
2647 
2648     @DataProvider(name="minusNanos_fromZero")
2649     Iterator<Object[]> minusNanos_fromZero() {
2650         return new Iterator<Object[]>() {
2651             long delta = 7500000000L;
2652 
2653             long i = 3660 * 1000000000L;
2654             LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1);
2655             int hour = 22;
2656             int min = 59;
2657             int sec = 0;
2658             long nanos = 0;
2659 
2660             public boolean hasNext() {
2661                 return i >= -3660 * 1000000000L;
2662             }
2663 
2664             public Object[] next() {
2665                 final Object[] ret = new Object[] {i, date, hour, min, sec, (int)nanos};
2666                 i -= delta;
2667                 nanos += delta;
2668 
2669                 if (nanos >= 1000000000L) {
2670                     sec += nanos / 1000000000L;
2671                     nanos %= 1000000000L;
2672 
2673                     if (sec >= 60) {
2674                         min++;
2675                         sec %= 60;
2676 
2677                         if (min == 60) {
2678                             hour++;
2679                             min = 0;
2680 
2681                             if (hour == 24) {
2682                                 hour = 0;
2683                                 date = date.plusDays(1);
2684                             }
2685                         }
2686                     }
2687                 }
2688 
2689                 return ret;
2690             }
2691 
2692             public void remove() {
2693                 throw new UnsupportedOperationException();
2694             }
2695         };
2696     }
2697 
2698     @Test(dataProvider="minusNanos_fromZero", groups={"tck"})
2699     public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
2700         LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
2701         LocalDateTime t = base.minusNanos(nanoseconds);
2702 
2703         assertEquals(date, t.getDate());
2704         assertEquals(hour, t.getHour());
2705         assertEquals(min, t.getMinute());
2706         assertEquals(sec, t.getSecond());
2707         assertEquals(nanos, t.getNano());
2708     }
2709 
2710     //-----------------------------------------------------------------------
2711     // atOffset()
2712     //-----------------------------------------------------------------------
2713     @Test(groups={"tck"})
2714     public void test_atOffset() {
2715         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2716         assertEquals(t.atOffset(OFFSET_PTWO), OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2717     }
2718 
2719     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2720     public void test_atOffset_nullZoneOffset() {
2721         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2722         t.atOffset((ZoneOffset) null);
2723     }
2724 
2725     //-----------------------------------------------------------------------
2726     // atZone()
2727     //-----------------------------------------------------------------------
2728     @Test(groups={"tck"})
2729     public void test_atZone() {
2730         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2731         assertEquals(t.atZone(ZONE_PARIS),
2732                 ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS));
2733     }
2734 
2735     @Test(groups={"tck"})
2736     public void test_atZone_Offset() {
2737         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2738         assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO));
2739     }
2740 
2741     @Test(groups={"tck"})
2742     public void test_atZone_dstGap() {
2743         LocalDateTime t = LocalDateTime.of(2007, 4, 1, 0, 0);
2744         assertEquals(t.atZone(ZONE_GAZA),
2745                 ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA));
2746     }
2747 
2748     @Test(groups={"tck"})
2749     public void test_atZone_dstOverlap() {
2750         LocalDateTime t = LocalDateTime.of(2007, 10, 28, 2, 30);
2751         assertEquals(t.atZone(ZONE_PARIS),
2752                 ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, ZONE_PARIS));
2753     }
2754 
2755     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2756     public void test_atZone_nullTimeZone() {
2757         LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
2758         t.atZone((ZoneId) null);
2759     }
2760 
2761     //-----------------------------------------------------------------------
2762     // toEpochSecond()
2763     //-----------------------------------------------------------------------
2764     @Test(groups={"tck"})
2765     public void test_toEpochSecond_afterEpoch() {
2766         for (int i = -5; i < 5; i++) {
2767             ZoneOffset offset = ZoneOffset.ofHours(i);
2768             for (int j = 0; j < 100000; j++) {
2769                 LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j);
2770                 assertEquals(a.toEpochSecond(offset), j - i * 3600);
2771             }
2772         }
2773     }
2774 
2775     @Test(groups={"tck"})
2776     public void test_toEpochSecond_beforeEpoch() {
2777         for (int i = 0; i < 100000; i++) {
2778             LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).minusSeconds(i);
2779             assertEquals(a.toEpochSecond(ZoneOffset.UTC), -i);
2780         }
2781     }
2782 
2783     //-----------------------------------------------------------------------
2784     // compareTo()
2785     //-----------------------------------------------------------------------
2786     @Test(groups={"tck"})
2787     public void test_comparisons() {
2788         test_comparisons_LocalDateTime(
2789             LocalDate.of(Year.MIN_VALUE, 1, 1),
2790             LocalDate.of(Year.MIN_VALUE, 12, 31),
2791             LocalDate.of(-1, 1, 1),
2792             LocalDate.of(-1, 12, 31),
2793             LocalDate.of(0, 1, 1),
2794             LocalDate.of(0, 12, 31),
2795             LocalDate.of(1, 1, 1),
2796             LocalDate.of(1, 12, 31),
2797             LocalDate.of(2008, 1, 1),
2798             LocalDate.of(2008, 2, 29),
2799             LocalDate.of(2008, 12, 31),
2800             LocalDate.of(Year.MAX_VALUE, 1, 1),
2801             LocalDate.of(Year.MAX_VALUE, 12, 31)
2802         );
2803     }
2804 
2805     void test_comparisons_LocalDateTime(LocalDate... localDates) {
2806         test_comparisons_LocalDateTime(
2807             localDates,
2808             LocalTime.MIDNIGHT,
2809             LocalTime.of(0, 0, 0, 999999999),
2810             LocalTime.of(0, 0, 59, 0),
2811             LocalTime.of(0, 0, 59, 999999999),
2812             LocalTime.of(0, 59, 0, 0),
2813             LocalTime.of(0, 59, 59, 999999999),
2814             LocalTime.NOON,
2815             LocalTime.of(12, 0, 0, 999999999),
2816             LocalTime.of(12, 0, 59, 0),
2817             LocalTime.of(12, 0, 59, 999999999),
2818             LocalTime.of(12, 59, 0, 0),
2819             LocalTime.of(12, 59, 59, 999999999),
2820             LocalTime.of(23, 0, 0, 0),
2821             LocalTime.of(23, 0, 0, 999999999),
2822             LocalTime.of(23, 0, 59, 0),
2823             LocalTime.of(23, 0, 59, 999999999),
2824             LocalTime.of(23, 59, 0, 0),
2825             LocalTime.of(23, 59, 59, 999999999)
2826         );
2827     }
2828 
2829     void test_comparisons_LocalDateTime(LocalDate[] localDates, LocalTime... localTimes) {
2830         LocalDateTime[] localDateTimes = new LocalDateTime[localDates.length * localTimes.length];
2831         int i = 0;
2832 
2833         for (LocalDate localDate : localDates) {
2834             for (LocalTime localTime : localTimes) {
2835                 localDateTimes[i++] = LocalDateTime.of(localDate, localTime);
2836             }
2837         }
2838 
2839         doTest_comparisons_LocalDateTime(localDateTimes);
2840     }
2841 
2842     void doTest_comparisons_LocalDateTime(LocalDateTime[] localDateTimes) {
2843         for (int i = 0; i < localDateTimes.length; i++) {
2844             LocalDateTime a = localDateTimes[i];
2845             for (int j = 0; j < localDateTimes.length; j++) {
2846                 LocalDateTime b = localDateTimes[j];
2847                 if (i < j) {
2848                     assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
2849                     assertEquals(a.isBefore(b), true, a + " <=> " + b);
2850                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2851                     assertEquals(a.equals(b), false, a + " <=> " + b);
2852                 } else if (i > j) {
2853                     assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
2854                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2855                     assertEquals(a.isAfter(b), true, a + " <=> " + b);
2856                     assertEquals(a.equals(b), false, a + " <=> " + b);
2857                 } else {
2858                     assertEquals(a.compareTo(b), 0, a + " <=> " + b);
2859                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2860                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2861                     assertEquals(a.equals(b), true, a + " <=> " + b);
2862                 }
2863             }
2864         }
2865     }
2866 
2867     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2868     public void test_compareTo_ObjectNull() {
2869         TEST_2007_07_15_12_30_40_987654321.compareTo(null);
2870     }
2871 
2872     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2873     public void test_isBefore_ObjectNull() {
2874         TEST_2007_07_15_12_30_40_987654321.isBefore(null);
2875     }
2876 
2877     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2878     public void test_isAfter_ObjectNull() {
2879         TEST_2007_07_15_12_30_40_987654321.isAfter(null);
2880     }
2881 
2882     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
2883     @SuppressWarnings({"unchecked", "rawtypes"})
2884     public void compareToNonLocalDateTime() {
2885        Comparable c = TEST_2007_07_15_12_30_40_987654321;
2886        c.compareTo(new Object());
2887     }
2888 
2889     //-----------------------------------------------------------------------
2890     // equals()
2891     //-----------------------------------------------------------------------
2892     @DataProvider(name="sampleDateTimes")
2893     Iterator<Object[]> provider_sampleDateTimes() {
2894         return new Iterator<Object[]>() {
2895             Object[][] sampleDates = provider_sampleDates();
2896             Object[][] sampleTimes = provider_sampleTimes();
2897             int datesIndex = 0;
2898             int timesIndex = 0;
2899 
2900             public boolean hasNext() {
2901                 return datesIndex < sampleDates.length;
2902             }
2903 
2904             public Object[] next() {
2905                 Object[] sampleDate = sampleDates[datesIndex];
2906                 Object[] sampleTime = sampleTimes[timesIndex];
2907 
2908                 Object[] ret = new Object[sampleDate.length + sampleTime.length];
2909 
2910                 System.arraycopy(sampleDate, 0, ret, 0, sampleDate.length);
2911                 System.arraycopy(sampleTime, 0, ret, sampleDate.length, sampleTime.length);
2912 
2913                 if (++timesIndex == sampleTimes.length) {
2914                     datesIndex++;
2915                     timesIndex = 0;
2916                 }
2917 
2918                 return ret;
2919             }
2920 
2921             public void remove() {
2922                 throw new UnsupportedOperationException();
2923             }
2924         };
2925     }
2926 
2927     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2928     public void test_equals_true(int y, int m, int d, int h, int mi, int s, int n) {
2929         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2930         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
2931         assertTrue(a.equals(b));
2932     }
2933 
2934     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2935     public void test_equals_false_year_differs(int y, int m, int d, int h, int mi, int s, int n) {
2936         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2937         LocalDateTime b = LocalDateTime.of(y + 1, m, d, h, mi, s, n);
2938         assertFalse(a.equals(b));
2939     }
2940 
2941     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2942     public void test_equals_false_month_differs(int y, int m, int d, int h, int mi, int s, int n) {
2943         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2944         LocalDateTime b = LocalDateTime.of(y, m + 1, d, h, mi, s, n);
2945         assertFalse(a.equals(b));
2946     }
2947 
2948     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2949     public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) {
2950         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2951         LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n);
2952         assertFalse(a.equals(b));
2953     }
2954 
2955     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2956     public void test_equals_false_hour_differs(int y, int m, int d, int h, int mi, int s, int n) {
2957         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2958         LocalDateTime b = LocalDateTime.of(y, m, d, h + 1, mi, s, n);
2959         assertFalse(a.equals(b));
2960     }
2961 
2962     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2963     public void test_equals_false_minute_differs(int y, int m, int d, int h, int mi, int s, int n) {
2964         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2965         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi + 1, s, n);
2966         assertFalse(a.equals(b));
2967     }
2968 
2969     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2970     public void test_equals_false_second_differs(int y, int m, int d, int h, int mi, int s, int n) {
2971         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2972         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s + 1, n);
2973         assertFalse(a.equals(b));
2974     }
2975 
2976     @Test(dataProvider="sampleDateTimes", groups={"tck"})
2977     public void test_equals_false_nano_differs(int y, int m, int d, int h, int mi, int s, int n) {
2978         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
2979         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n + 1);
2980         assertFalse(a.equals(b));
2981     }
2982 
2983     @Test(groups={"tck"})
2984     public void test_equals_itself_true() {
2985         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(TEST_2007_07_15_12_30_40_987654321), true);
2986     }
2987 
2988     @Test(groups={"tck"})
2989     public void test_equals_string_false() {
2990         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals("2007-07-15T12:30:40.987654321"), false);
2991     }
2992 
2993     @Test(groups={"tck"})
2994     public void test_equals_null_false() {
2995         assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(null), false);
2996     }
2997 
2998     //-----------------------------------------------------------------------
2999     // hashCode()
3000     //-----------------------------------------------------------------------
3001     @Test(dataProvider="sampleDateTimes", groups={"tck"})
3002     public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) {
3003         LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
3004         assertEquals(a.hashCode(), a.hashCode());
3005         LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n);
3006         assertEquals(a.hashCode(), b.hashCode());
3007     }
3008 
3009     //-----------------------------------------------------------------------
3010     // toString()
3011     //-----------------------------------------------------------------------
3012     @DataProvider(name="sampleToString")
3013     Object[][] provider_sampleToString() {
3014         return new Object[][] {
3015             {2008, 7, 5, 2, 1, 0, 0, "2008-07-05T02:01"},
3016             {2007, 12, 31, 23, 59, 1, 0, "2007-12-31T23:59:01"},
3017             {999, 12, 31, 23, 59, 59, 990000000, "0999-12-31T23:59:59.990"},
3018             {-1, 1, 2, 23, 59, 59, 999990000, "-0001-01-02T23:59:59.999990"},
3019             {-2008, 1, 2, 23, 59, 59, 999999990, "-2008-01-02T23:59:59.999999990"},
3020         };
3021     }
3022 
3023     @Test(dataProvider="sampleToString", groups={"tck"})
3024     public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) {
3025         LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n);
3026         String str = t.toString();
3027         assertEquals(str, expected);
3028     }
3029 
3030     //-----------------------------------------------------------------------
3031     // toString(DateTimeFormatter)
3032     //-----------------------------------------------------------------------
3033     @Test(groups={"tck"})
3034     public void test_toString_formatter() {
3035         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
3036         String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(f);
3037         assertEquals(t, "2010 12 3 11 30 45");
3038     }
3039 
3040     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
3041     public void test_toString_formatter_null() {
3042         LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(null);
3043     }
3044 
3045 }