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