Search in sources :

Example 86 with Period

use of java.time.Period in project j2objc by google.

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.junit.Test)

Example 87 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method factory_parse.

@Test()
@UseDataProvider("data_factory_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.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 88 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method factory_parse_minus.

@Test()
@UseDataProvider("data_factory_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.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 89 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method test_plusYears_overflowTooSmall.

@Test(expected = 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.junit.Test)

Example 90 with Period

use of java.time.Period in project j2objc by google.

the class TCKPeriod method test_minusYears_overflowTooBig.

@Test(expected = ArithmeticException.class)
public void test_minusYears_overflowTooBig() {
    Period test = Period.ofYears(Integer.MAX_VALUE);
    test.minusYears(-1);
}
Also used : Period(java.time.Period) Test(org.junit.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