Search in sources :

Example 16 with Duration

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

the class TCKDuration method dividedBy_max.

@Test
public void dividedBy_max() {
    Duration test = Duration.ofSeconds(Long.MAX_VALUE);
    assertEquals(test.dividedBy(Long.MAX_VALUE), Duration.ofSeconds(1));
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 17 with Duration

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

the class TCKDuration method factory_seconds_long_long.

//-----------------------------------------------------------------------
// ofSeconds(long,long)
//-----------------------------------------------------------------------
@Test
public void factory_seconds_long_long() {
    for (long i = -2; i <= 2; i++) {
        for (int j = 0; j < 10; j++) {
            Duration t = Duration.ofSeconds(i, j);
            assertEquals(t.getSeconds(), i);
            assertEquals(t.getNano(), j);
        }
        for (int j = -10; j < 0; j++) {
            Duration t = Duration.ofSeconds(i, j);
            assertEquals(t.getSeconds(), i - 1);
            assertEquals(t.getNano(), j + 1000000000);
        }
        for (int j = 999999990; j < 1000000000; j++) {
            Duration t = Duration.ofSeconds(i, j);
            assertEquals(t.getSeconds(), i);
            assertEquals(t.getNano(), j);
        }
    }
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 18 with Duration

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

the class TCKDuration method factory_between_TemporalTemporal_Instant.

@Test(dataProvider = "durationBetweenInstant")
public void factory_between_TemporalTemporal_Instant(long secs1, int nanos1, long secs2, int nanos2, long expectedSeconds, int expectedNanoOfSecond) {
    Instant start = Instant.ofEpochSecond(secs1, nanos1);
    Instant end = Instant.ofEpochSecond(secs2, nanos2);
    Duration t = Duration.between(start, end);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 19 with Duration

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

the class TCKDuration method minusMillis_long.

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

Example 20 with Duration

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

the class TCKDuration method factory_minutes_max.

@Test
public void factory_minutes_max() {
    Duration test = Duration.ofMinutes(Long.MAX_VALUE / 60);
    assertEquals(test.getSeconds(), (Long.MAX_VALUE / 60) * 60);
    assertEquals(test.getNano(), 0);
}
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