test/java/time/tck/java/time/TCKInstant.java

Print this page




  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.INSTANT_SECONDS;
  63 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  64 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  65 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  66 import static java.time.temporal.ChronoUnit.DAYS;





  67 import static java.time.temporal.ChronoUnit.NANOS;
  68 import static java.time.temporal.ChronoUnit.SECONDS;


  69 import static org.testng.Assert.assertEquals;
  70 import static org.testng.Assert.assertTrue;
  71 
  72 import java.io.ByteArrayOutputStream;
  73 import java.io.DataOutputStream;
  74 import java.util.ArrayList;
  75 import java.util.Arrays;
  76 import java.util.List;
  77 import java.util.Locale;
  78 
  79 import java.time.Clock;
  80 import java.time.DateTimeException;
  81 import java.time.Duration;
  82 import java.time.Instant;
  83 import java.time.LocalDateTime;

  84 import java.time.ZoneOffset;

  85 import java.time.format.DateTimeParseException;
  86 import java.time.temporal.ChronoField;
  87 import java.time.temporal.JulianFields;
  88 import java.time.temporal.Queries;

  89 import java.time.temporal.TemporalAccessor;

  90 import java.time.temporal.TemporalField;






  91 
  92 import org.testng.annotations.BeforeMethod;
  93 import org.testng.annotations.DataProvider;
  94 import org.testng.annotations.Test;
  95 
  96 /**
  97  * Test Instant.
  98  */
  99 @Test
 100 public class TCKInstant extends AbstractDateTimeTest {
 101 
 102     private static final long MIN_SECOND = Instant.MIN.getEpochSecond();
 103     private static final long MAX_SECOND = Instant.MAX.getEpochSecond();
 104 
 105     private Instant TEST_12345_123456789;
 106 
 107     @BeforeMethod
 108     public void setUp() {
 109         TEST_12345_123456789 = Instant.ofEpochSecond(12345, 123456789);
 110     }


 379     @Test
 380     public void test_get_TemporalField() {
 381         Instant test = TEST_12345_123456789;
 382         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 123456789);
 383         assertEquals(test.get(ChronoField.MICRO_OF_SECOND), 123456);
 384         assertEquals(test.get(ChronoField.MILLI_OF_SECOND), 123);
 385     }
 386 
 387     @Test
 388     public void test_getLong_TemporalField() {
 389         Instant test = TEST_12345_123456789;
 390         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 123456789);
 391         assertEquals(test.getLong(ChronoField.MICRO_OF_SECOND), 123456);
 392         assertEquals(test.getLong(ChronoField.MILLI_OF_SECOND), 123);
 393         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), 12345);
 394     }
 395 
 396     //-----------------------------------------------------------------------
 397     // query(TemporalQuery)
 398     //-----------------------------------------------------------------------
 399     @Test
 400     public void test_query_chrono() {
 401         assertEquals(TEST_12345_123456789.query(Queries.chrono()), null);
 402         assertEquals(Queries.chrono().queryFrom(TEST_12345_123456789), null);







 403     }
 404 
 405     @Test
 406     public void test_query_zoneId() {
 407         assertEquals(TEST_12345_123456789.query(Queries.zoneId()), null);
 408         assertEquals(Queries.zoneId().queryFrom(TEST_12345_123456789), null);
 409     }
 410 
 411     @Test
 412     public void test_query_precision() {
 413         assertEquals(TEST_12345_123456789.query(Queries.precision()), NANOS);
 414         assertEquals(Queries.precision().queryFrom(TEST_12345_123456789), NANOS);
 415     }
 416 
 417     @Test
 418     public void test_query_offset() {
 419         assertEquals(TEST_12345_123456789.query(Queries.offset()), null);
 420         assertEquals(Queries.offset().queryFrom(TEST_12345_123456789), null);
 421     }
 422 
 423     @Test
 424     public void test_query_zone() {
 425         assertEquals(TEST_12345_123456789.query(Queries.zone()), null);
 426         assertEquals(Queries.zone().queryFrom(TEST_12345_123456789), null);







 427     }

















 428 
 429     @Test(expectedExceptions=NullPointerException.class)
 430     public void test_query_null() {
 431         TEST_12345_123456789.query(null);










































































































 432     }
 433 
 434     //-----------------------------------------------------------------------
 435     @DataProvider(name="Plus")
 436     Object[][] provider_plus() {
 437         return new Object[][] {
 438                 {MIN_SECOND, 0, -MIN_SECOND, 0, 0, 0},
 439 
 440                 {MIN_SECOND, 0, 1, 0, MIN_SECOND + 1, 0},
 441                 {MIN_SECOND, 0, 0, 500, MIN_SECOND, 500},
 442                 {MIN_SECOND, 0, 0, 1000000000, MIN_SECOND + 1, 0},
 443 
 444                 {MIN_SECOND + 1, 0, -1, 0, MIN_SECOND, 0},
 445                 {MIN_SECOND + 1, 0, 0, -500, MIN_SECOND, 999999500},
 446                 {MIN_SECOND + 1, 0, 0, -1000000000, MIN_SECOND, 0},
 447 
 448                 {-4, 666666667, -4, 666666667, -7, 333333334},
 449                 {-4, 666666667, -3,         0, -7, 666666667},
 450                 {-4, 666666667, -2,         0, -6, 666666667},
 451                 {-4, 666666667, -1,         0, -5, 666666667},


1417     public void minusNanos_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
1418         Instant i = Instant.ofEpochSecond(seconds, nanos);
1419         i = i.minusNanos(amount);
1420         assertEquals(i.getEpochSecond(), expectedSeconds);
1421         assertEquals(i.getNano(), expectedNanoOfSecond);
1422     }
1423 
1424     @Test(expectedExceptions=DateTimeException.class)
1425     public void minusNanos_long_overflowTooBig() {
1426         Instant i = Instant.ofEpochSecond(MAX_SECOND, 999999999);
1427         i.minusNanos(-1);
1428     }
1429 
1430     @Test(expectedExceptions=DateTimeException.class)
1431     public void minusNanos_long_overflowTooSmall() {
1432         Instant i = Instant.ofEpochSecond(MIN_SECOND, 0);
1433         i.minusNanos(1);
1434     }
1435 
1436     //-----------------------------------------------------------------------












































1437     // toEpochMilli()
1438     //-----------------------------------------------------------------------
1439     @Test
1440     public void test_toEpochMilli() {
1441         assertEquals(Instant.ofEpochSecond(1L, 1000000).toEpochMilli(), 1001L);
1442         assertEquals(Instant.ofEpochSecond(1L, 2000000).toEpochMilli(), 1002L);
1443         assertEquals(Instant.ofEpochSecond(1L, 567).toEpochMilli(), 1000L);
1444         assertEquals(Instant.ofEpochSecond(Long.MAX_VALUE / 1000).toEpochMilli(), (Long.MAX_VALUE / 1000) * 1000);
1445         assertEquals(Instant.ofEpochSecond(Long.MIN_VALUE / 1000).toEpochMilli(), (Long.MIN_VALUE / 1000) * 1000);
1446         assertEquals(Instant.ofEpochSecond(0L, -1000000).toEpochMilli(), -1L);
1447         assertEquals(Instant.ofEpochSecond(0L, 1000000).toEpochMilli(), 1);
1448         assertEquals(Instant.ofEpochSecond(0L, 999999).toEpochMilli(), 0);
1449         assertEquals(Instant.ofEpochSecond(0L, 1).toEpochMilli(), 0);
1450         assertEquals(Instant.ofEpochSecond(0L, 0).toEpochMilli(), 0);
1451         assertEquals(Instant.ofEpochSecond(0L, -1).toEpochMilli(), -1L);
1452         assertEquals(Instant.ofEpochSecond(0L, -999999).toEpochMilli(), -1L);
1453         assertEquals(Instant.ofEpochSecond(0L, -1000000).toEpochMilli(), -1L);
1454         assertEquals(Instant.ofEpochSecond(0L, -1000001).toEpochMilli(), -2L);
1455     }
1456 




  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.INSTANT_SECONDS;
  63 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  64 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  65 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  66 import static java.time.temporal.ChronoUnit.DAYS;
  67 import static java.time.temporal.ChronoUnit.HOURS;
  68 import static java.time.temporal.ChronoUnit.MICROS;
  69 import static java.time.temporal.ChronoUnit.MILLIS;
  70 import static java.time.temporal.ChronoUnit.MINUTES;
  71 import static java.time.temporal.ChronoUnit.MONTHS;
  72 import static java.time.temporal.ChronoUnit.NANOS;
  73 import static java.time.temporal.ChronoUnit.SECONDS;
  74 import static java.time.temporal.ChronoUnit.WEEKS;
  75 import static java.time.temporal.ChronoUnit.YEARS;
  76 import static org.testng.Assert.assertEquals;
  77 import static org.testng.Assert.assertTrue;
  78 
  79 import java.io.ByteArrayOutputStream;
  80 import java.io.DataOutputStream;





  81 import java.time.Clock;
  82 import java.time.DateTimeException;
  83 import java.time.Duration;
  84 import java.time.Instant;
  85 import java.time.LocalDateTime;
  86 import java.time.OffsetDateTime;
  87 import java.time.ZoneOffset;
  88 import java.time.ZonedDateTime;
  89 import java.time.format.DateTimeParseException;
  90 import java.time.temporal.ChronoField;
  91 import java.time.temporal.JulianFields;
  92 import java.time.temporal.Queries;
  93 import java.time.temporal.Temporal;
  94 import java.time.temporal.TemporalAccessor;
  95 import java.time.temporal.TemporalAmount;
  96 import java.time.temporal.TemporalField;
  97 import java.time.temporal.TemporalQuery;
  98 import java.time.temporal.TemporalUnit;
  99 import java.util.ArrayList;
 100 import java.util.Arrays;
 101 import java.util.List;
 102 import java.util.Locale;
 103 
 104 import org.testng.annotations.BeforeMethod;
 105 import org.testng.annotations.DataProvider;
 106 import org.testng.annotations.Test;
 107 
 108 /**
 109  * Test Instant.
 110  */
 111 @Test
 112 public class TCKInstant extends AbstractDateTimeTest {
 113 
 114     private static final long MIN_SECOND = Instant.MIN.getEpochSecond();
 115     private static final long MAX_SECOND = Instant.MAX.getEpochSecond();
 116 
 117     private Instant TEST_12345_123456789;
 118 
 119     @BeforeMethod
 120     public void setUp() {
 121         TEST_12345_123456789 = Instant.ofEpochSecond(12345, 123456789);
 122     }


 391     @Test
 392     public void test_get_TemporalField() {
 393         Instant test = TEST_12345_123456789;
 394         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 123456789);
 395         assertEquals(test.get(ChronoField.MICRO_OF_SECOND), 123456);
 396         assertEquals(test.get(ChronoField.MILLI_OF_SECOND), 123);
 397     }
 398 
 399     @Test
 400     public void test_getLong_TemporalField() {
 401         Instant test = TEST_12345_123456789;
 402         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 123456789);
 403         assertEquals(test.getLong(ChronoField.MICRO_OF_SECOND), 123456);
 404         assertEquals(test.getLong(ChronoField.MILLI_OF_SECOND), 123);
 405         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), 12345);
 406     }
 407 
 408     //-----------------------------------------------------------------------
 409     // query(TemporalQuery)
 410     //-----------------------------------------------------------------------
 411     @DataProvider(name="query")
 412     Object[][] data_query() {
 413         return new Object[][] {
 414                 {TEST_12345_123456789, Queries.chronology(), null},
 415                 {TEST_12345_123456789, Queries.zoneId(), null},
 416                 {TEST_12345_123456789, Queries.precision(), NANOS},
 417                 {TEST_12345_123456789, Queries.zone(), null},
 418                 {TEST_12345_123456789, Queries.offset(), null},
 419                 {TEST_12345_123456789, Queries.localDate(), null},
 420                 {TEST_12345_123456789, Queries.localTime(), null},
 421         };
 422     }
 423 
 424     @Test(dataProvider="query")
 425     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 426         assertEquals(temporal.query(query), expected);

 427     }
 428 
 429     @Test(dataProvider="query")
 430     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 431         assertEquals(query.queryFrom(temporal), expected);

 432     }
 433 
 434     @Test(expectedExceptions=NullPointerException.class)
 435     public void test_query_null() {
 436         TEST_12345_123456789.query(null);

 437     }
 438 
 439     //-----------------------------------------------------------------------
 440     // truncated(TemporalUnit)
 441     //-----------------------------------------------------------------------
 442     TemporalUnit NINETY_MINS = new TemporalUnit() {
 443         @Override
 444         public String getName() {
 445             return "NinetyMins";
 446         }
 447         @Override
 448         public Duration getDuration() {
 449             return Duration.ofMinutes(90);
 450         }
 451         @Override
 452         public boolean isDurationEstimated() {
 453             return false;
 454         }
 455         @Override
 456         public boolean isSupportedBy(Temporal temporal) {
 457             return false;
 458         }
 459         @Override
 460         public <R extends Temporal> R addTo(R temporal, long amount) {
 461             throw new UnsupportedOperationException();
 462         }
 463         @Override
 464         public long between(Temporal temporal1, Temporal temporal2) {
 465             throw new UnsupportedOperationException();
 466         }
 467     };
 468 
 469     TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
 470         @Override
 471         public String getName() {
 472             return "NinetyFiveMins";
 473         }
 474         @Override
 475         public Duration getDuration() {
 476             return Duration.ofMinutes(95);
 477         }
 478         @Override
 479         public boolean isDurationEstimated() {
 480             return false;
 481         }
 482         @Override
 483         public boolean isSupportedBy(Temporal temporal) {
 484             return false;
 485         }
 486         @Override
 487         public <R extends Temporal> R addTo(R temporal, long amount) {
 488             throw new UnsupportedOperationException();
 489         }
 490         @Override
 491         public long between(Temporal temporal1, Temporal temporal2) {
 492             throw new UnsupportedOperationException();
 493         }
 494     };
 495 
 496     @DataProvider(name="truncatedToValid")
 497     Object[][] data_truncatedToValid() {
 498         return new Object[][] {
 499                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), NANOS, Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789)},
 500                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), MICROS, Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_000)},
 501                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), MILLIS, Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 1230_00_000)},
 502                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), SECONDS, Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 0)},
 503                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), MINUTES, Instant.ofEpochSecond(86400 + 3600 + 60, 0)},
 504                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), HOURS, Instant.ofEpochSecond(86400 + 3600, 0)},
 505                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), DAYS, Instant.ofEpochSecond(86400, 0)},
 506 
 507                 {Instant.ofEpochSecond(86400 + 3600 + 60 + 1, 123_456_789), NINETY_MINS, Instant.ofEpochSecond(86400 + 0, 0)},
 508                 {Instant.ofEpochSecond(86400 + 7200 + 60 + 1, 123_456_789), NINETY_MINS, Instant.ofEpochSecond(86400 + 5400, 0)},
 509                 {Instant.ofEpochSecond(86400 + 10800 + 60 + 1, 123_456_789), NINETY_MINS, Instant.ofEpochSecond(86400 + 10800, 0)},
 510         };
 511     }
 512     @Test(groups={"tck"}, dataProvider="truncatedToValid")
 513     public void test_truncatedTo_valid(Instant input, TemporalUnit unit, Instant expected) {
 514         assertEquals(input.truncatedTo(unit), expected);
 515     }
 516 
 517     @DataProvider(name="truncatedToInvalid")
 518     Object[][] data_truncatedToInvalid() {
 519         return new Object[][] {
 520                 {Instant.ofEpochSecond(1, 123_456_789), NINETY_FIVE_MINS},
 521                 {Instant.ofEpochSecond(1, 123_456_789), WEEKS},
 522                 {Instant.ofEpochSecond(1, 123_456_789), MONTHS},
 523                 {Instant.ofEpochSecond(1, 123_456_789), YEARS},
 524         };
 525     }
 526 
 527     @Test(groups={"tck"}, dataProvider="truncatedToInvalid", expectedExceptions=DateTimeException.class)
 528     public void test_truncatedTo_invalid(Instant input, TemporalUnit unit) {
 529         input.truncatedTo(unit);
 530     }
 531 
 532     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 533     public void test_truncatedTo_null() {
 534         TEST_12345_123456789.truncatedTo(null);
 535     }
 536 
 537     //-----------------------------------------------------------------------
 538     // plus(TemporalAmount)
 539     //-----------------------------------------------------------------------
 540     @DataProvider(name="plusTemporalAmount")
 541     Object[][] data_plusTemporalAmount() {
 542         return new Object[][] {
 543                 {DAYS, MockSimplePeriod.of(1, DAYS), 86401, 0},
 544                 {HOURS, MockSimplePeriod.of(2, HOURS), 7201, 0},
 545                 {MINUTES, MockSimplePeriod.of(4, MINUTES), 241, 0},
 546                 {SECONDS, MockSimplePeriod.of(5, SECONDS), 6, 0},
 547                 {NANOS, MockSimplePeriod.of(6, NANOS), 1, 6},
 548                 {DAYS, MockSimplePeriod.of(10, DAYS), 864001, 0},
 549                 {HOURS, MockSimplePeriod.of(11, HOURS), 39601, 0},
 550                 {MINUTES, MockSimplePeriod.of(12, MINUTES), 721, 0},
 551                 {SECONDS, MockSimplePeriod.of(13, SECONDS), 14, 0},
 552                 {NANOS, MockSimplePeriod.of(14, NANOS), 1, 14},
 553                 {SECONDS, Duration.ofSeconds(20, 40), 21, 40},
 554                 {NANOS, Duration.ofSeconds(30, 300), 31, 300},
 555         };
 556     }
 557 
 558     @Test(dataProvider="plusTemporalAmount")
 559     public void test_plusTemporalAmount(TemporalUnit unit, TemporalAmount amount, int seconds, int nanos) {
 560         Instant inst = Instant.ofEpochMilli(1000);
 561         Instant actual = inst.plus(amount);
 562         Instant expected = Instant.ofEpochSecond(seconds, nanos);
 563         assertEquals(actual, expected, "plus(TemporalAmount) failed");
 564     }
 565 
 566     @DataProvider(name="badTemporalAmount")
 567     Object[][] data_badPlusTemporalAmount() {
 568         return new Object[][] {
 569                 {MockSimplePeriod.of(2, YEARS)},
 570                 {MockSimplePeriod.of(2, MONTHS)},
 571         };
 572     }
 573 
 574     @Test(dataProvider="badTemporalAmount",expectedExceptions=DateTimeException.class)
 575     public void test_badPlusTemporalAmount(TemporalAmount amount) {
 576         Instant inst = Instant.ofEpochMilli(1000);
 577         inst.plus(amount);
 578     }
 579 
 580     //-----------------------------------------------------------------------
 581     @DataProvider(name="Plus")
 582     Object[][] provider_plus() {
 583         return new Object[][] {
 584                 {MIN_SECOND, 0, -MIN_SECOND, 0, 0, 0},
 585 
 586                 {MIN_SECOND, 0, 1, 0, MIN_SECOND + 1, 0},
 587                 {MIN_SECOND, 0, 0, 500, MIN_SECOND, 500},
 588                 {MIN_SECOND, 0, 0, 1000000000, MIN_SECOND + 1, 0},
 589 
 590                 {MIN_SECOND + 1, 0, -1, 0, MIN_SECOND, 0},
 591                 {MIN_SECOND + 1, 0, 0, -500, MIN_SECOND, 999999500},
 592                 {MIN_SECOND + 1, 0, 0, -1000000000, MIN_SECOND, 0},
 593 
 594                 {-4, 666666667, -4, 666666667, -7, 333333334},
 595                 {-4, 666666667, -3,         0, -7, 666666667},
 596                 {-4, 666666667, -2,         0, -6, 666666667},
 597                 {-4, 666666667, -1,         0, -5, 666666667},


1563     public void minusNanos_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
1564         Instant i = Instant.ofEpochSecond(seconds, nanos);
1565         i = i.minusNanos(amount);
1566         assertEquals(i.getEpochSecond(), expectedSeconds);
1567         assertEquals(i.getNano(), expectedNanoOfSecond);
1568     }
1569 
1570     @Test(expectedExceptions=DateTimeException.class)
1571     public void minusNanos_long_overflowTooBig() {
1572         Instant i = Instant.ofEpochSecond(MAX_SECOND, 999999999);
1573         i.minusNanos(-1);
1574     }
1575 
1576     @Test(expectedExceptions=DateTimeException.class)
1577     public void minusNanos_long_overflowTooSmall() {
1578         Instant i = Instant.ofEpochSecond(MIN_SECOND, 0);
1579         i.minusNanos(1);
1580     }
1581 
1582     //-----------------------------------------------------------------------
1583     // atOffset()
1584     //-----------------------------------------------------------------------
1585     @Test
1586     public void test_atOffset() {
1587         for (int i = 0; i < (24 * 60 * 60); i++) {
1588             Instant instant = Instant.ofEpochSecond(i);
1589             OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1));
1590             assertEquals(test.getYear(), 1970);
1591             assertEquals(test.getMonthValue(), 1);
1592             assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
1593             assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
1594             assertEquals(test.getMinute(), (i / 60) % 60);
1595             assertEquals(test.getSecond(), i % 60);
1596         }
1597     }
1598 
1599     @Test(expectedExceptions=NullPointerException.class)
1600     public void test_atOffset_null() {
1601         TEST_12345_123456789.atOffset(null);
1602     }
1603 
1604     //-----------------------------------------------------------------------
1605     // atZone()
1606     //-----------------------------------------------------------------------
1607     @Test
1608     public void test_atZone() {
1609         for (int i = 0; i < (24 * 60 * 60); i++) {
1610             Instant instant = Instant.ofEpochSecond(i);
1611             ZonedDateTime test = instant.atZone(ZoneOffset.ofHours(1));
1612             assertEquals(test.getYear(), 1970);
1613             assertEquals(test.getMonthValue(), 1);
1614             assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
1615             assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
1616             assertEquals(test.getMinute(), (i / 60) % 60);
1617             assertEquals(test.getSecond(), i % 60);
1618         }
1619     }
1620 
1621     @Test(expectedExceptions=NullPointerException.class)
1622     public void test_atZone_null() {
1623         TEST_12345_123456789.atZone(null);
1624     }
1625 
1626     //-----------------------------------------------------------------------
1627     // toEpochMilli()
1628     //-----------------------------------------------------------------------
1629     @Test
1630     public void test_toEpochMilli() {
1631         assertEquals(Instant.ofEpochSecond(1L, 1000000).toEpochMilli(), 1001L);
1632         assertEquals(Instant.ofEpochSecond(1L, 2000000).toEpochMilli(), 1002L);
1633         assertEquals(Instant.ofEpochSecond(1L, 567).toEpochMilli(), 1000L);
1634         assertEquals(Instant.ofEpochSecond(Long.MAX_VALUE / 1000).toEpochMilli(), (Long.MAX_VALUE / 1000) * 1000);
1635         assertEquals(Instant.ofEpochSecond(Long.MIN_VALUE / 1000).toEpochMilli(), (Long.MIN_VALUE / 1000) * 1000);
1636         assertEquals(Instant.ofEpochSecond(0L, -1000000).toEpochMilli(), -1L);
1637         assertEquals(Instant.ofEpochSecond(0L, 1000000).toEpochMilli(), 1);
1638         assertEquals(Instant.ofEpochSecond(0L, 999999).toEpochMilli(), 0);
1639         assertEquals(Instant.ofEpochSecond(0L, 1).toEpochMilli(), 0);
1640         assertEquals(Instant.ofEpochSecond(0L, 0).toEpochMilli(), 0);
1641         assertEquals(Instant.ofEpochSecond(0L, -1).toEpochMilli(), -1L);
1642         assertEquals(Instant.ofEpochSecond(0L, -999999).toEpochMilli(), -1L);
1643         assertEquals(Instant.ofEpochSecond(0L, -1000000).toEpochMilli(), -1L);
1644         assertEquals(Instant.ofEpochSecond(0L, -1000001).toEpochMilli(), -2L);
1645     }
1646