Polish "Fix duration to microseconds conversion"

See gh-27149
This commit is contained in:
Stephane Nicoll 2021-07-06 09:07:36 +02:00
parent a406a46fa1
commit 5ec0c7ed12
2 changed files with 10 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -183,7 +183,7 @@ public enum DurationStyle {
/**
* Microseconds.
*/
MICROS(ChronoUnit.MICROS, "us", duration -> duration.toNanos() / 1000L),
MICROS(ChronoUnit.MICROS, "us", (duration) -> duration.toNanos() / 1000L),
/**
* Milliseconds.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -231,10 +231,15 @@ class DurationStyleTests {
}
@Test
void printSimpleWithUnitShouldPrintInUnit() {
void printSimpleWithSecondsUnitShouldPrintInUnit() {
Duration duration = Duration.ofMillis(1000);
assertThat(DurationStyle.SIMPLE.print(duration, ChronoUnit.SECONDS)).isEqualTo("1s");
assertThat(DurationStyle.SIMPLE.print(Duration.ofNanos(2000), ChronoUnit.MICROS)).isEqualTo("2us");
}
@Test
void printSimpleWithMicrosUnitShouldPrintInUnit() {
Duration duration = Duration.ofNanos(2000);
assertThat(DurationStyle.SIMPLE.print(duration, ChronoUnit.MICROS)).isEqualTo("2us");
}
}