Search in sources :

Example 6 with Duration

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

the class TCKDuration method plusNanos_long.

@Test(dataProvider = "PlusNanos")
public void plusNanos_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.plusNanos(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 7 with Duration

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

the class TCKDuration method factory_parse_minus.

@Test(dataProvider = "parseSuccess")
public void factory_parse_minus(String text, long expectedSeconds, int expectedNanoOfSecond) {
    Duration test;
    try {
        test = Duration.parse("-" + text);
    } catch (DateTimeParseException ex) {
        assertEquals(expectedSeconds == Long.MIN_VALUE, true);
        return;
    }
    // not inside try/catch or it breaks test
    assertEquals(test, Duration.ofSeconds(expectedSeconds, expectedNanoOfSecond).negated());
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 8 with Duration

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

the class TCKDuration method minusOverflowTooSmall.

@Test(expectedExceptions = ArithmeticException.class)
public void minusOverflowTooSmall() {
    Duration t = Duration.ofSeconds(Long.MIN_VALUE);
    t.minus(Duration.ofSeconds(0, 1));
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 9 with Duration

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

the class TCKDuration method factory_nanos_max.

@Test
public void factory_nanos_max() {
    Duration test = Duration.ofNanos(Long.MAX_VALUE);
    assertEquals(test.getSeconds(), Long.MAX_VALUE / 1000000000);
    assertEquals(test.getNano(), Long.MAX_VALUE % 1000000000);
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 10 with Duration

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

the class TCKDuration method plusMillis_long_minusOneLess.

@Test(dataProvider = "PlusMillis")
public void plusMillis_long_minusOneLess(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds - 1, nanos);
    t = t.plusMillis(amount);
    assertEquals(t.getSeconds(), expectedSeconds - 1);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Aggregations

Duration (java.time.Duration)1205 Test (org.junit.Test)418 Test (org.testng.annotations.Test)139 Instant (java.time.Instant)128 Test (org.junit.jupiter.api.Test)83 List (java.util.List)82 ArrayList (java.util.ArrayList)81 CompletableFuture (java.util.concurrent.CompletableFuture)81 Collectors (java.util.stream.Collectors)73 Collections (java.util.Collections)62 Preconditions (com.google.common.base.Preconditions)61 Map (java.util.Map)60 Slf4j (lombok.extern.slf4j.Slf4j)59 lombok.val (lombok.val)55 HashMap (java.util.HashMap)54 Arrays (java.util.Arrays)52 Function (java.util.function.Function)51 IOException (java.io.IOException)49 HashSet (java.util.HashSet)47 TimeUnit (java.util.concurrent.TimeUnit)47