Search in sources :

Example 66 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_normalized_min.

@Test(expectedExceptions = ArithmeticException.class)
public void test_normalized_min() {
    Period base = Period.of(Integer.MIN_VALUE, -12, 0);
    base.normalized();
}
Also used : Period(java.time.Period) Test(org.testng.annotations.Test)

Example 67 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method factory_parse.

@Test(dataProvider = "parseSuccess")
public void factory_parse(String text, Period expected) {
    Period p = Period.parse(text);
    assertEquals(p, expected);
}
Also used : Period(java.time.Period) Test(org.testng.annotations.Test)

Example 68 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method factory_parse_minus.

@Test(dataProvider = "parseSuccess")
public void factory_parse_minus(String text, Period expected) {
    Period p = null;
    try {
        p = Period.parse("-" + text);
    } catch (DateTimeParseException ex) {
        assertEquals(expected.getYears() == Integer.MIN_VALUE || expected.getMonths() == Integer.MIN_VALUE || expected.getDays() == Integer.MIN_VALUE, true);
        return;
    }
    // not inside try/catch or it breaks test
    assertEquals(p, expected.negated());
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) Period(java.time.Period) Test(org.testng.annotations.Test)

Example 69 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TestPeriod method test_hashCode.

//-----------------------------------------------------------------------
// hashCode()
//-----------------------------------------------------------------------
@Test
public void test_hashCode() {
    Period test5 = Period.ofDays(5);
    Period test6 = Period.ofDays(6);
    Period test5M = Period.ofMonths(5);
    Period test5Y = Period.ofYears(5);
    assertEquals(test5.hashCode() == test5.hashCode(), true);
    assertEquals(test5.hashCode() == test6.hashCode(), false);
    assertEquals(test5.hashCode() == test5M.hashCode(), false);
    assertEquals(test5.hashCode() == test5Y.hashCode(), false);
}
Also used : Period(java.time.Period) Test(org.testng.annotations.Test)

Example 70 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_plusYears_overflowTooSmall.

@Test(expectedExceptions = ArithmeticException.class)
public void test_plusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.plusYears(-1);
}
Also used : Period(java.time.Period) Test(org.testng.annotations.Test)

Aggregations

Period (java.time.Period)110 Test (org.junit.Test)37 Test (org.testng.annotations.Test)27 LocalDate (java.time.LocalDate)21 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 Duration (java.time.Duration)8 LocalDateTime (java.time.LocalDateTime)7 ZonedDateTime (java.time.ZonedDateTime)7 DateTimeFormatter (java.time.format.DateTimeFormatter)6 Date (java.util.Date)6 Instant (java.time.Instant)5 LocalTime (java.time.LocalTime)5 ZoneId (java.time.ZoneId)5 Test (org.junit.jupiter.api.Test)5 DateTimeParseException (java.time.format.DateTimeParseException)4 TemporalAmount (java.time.temporal.TemporalAmount)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 OffsetTime (java.time.OffsetTime)3