Faster StopWatchTest.testSimple()

and simpler
This commit is contained in:
Gary Gregory 2024-09-04 11:44:41 -04:00
parent b23c2d3836
commit 66d19b140e
1 changed files with 3 additions and 3 deletions

View File

@ -302,14 +302,14 @@ public class StopWatchTest extends AbstractLangTest {
@Test @Test
public void testSimple() throws InterruptedException { public void testSimple() throws InterruptedException {
final StopWatch watch = StopWatch.createStarted(); final StopWatch watch = StopWatch.createStarted();
sleep(MILLIS_550); final Duration sleepDuration = MILLIS_550;
sleep(sleepDuration);
watch.stop(); watch.stop();
final long time = watch.getTime(); final long time = watch.getTime();
final Duration duration = watch.getDuration(); final Duration duration = watch.getDuration();
assertEquals(time, watch.getTime()); assertEquals(time, watch.getTime());
assertEquals(duration, watch.getDuration()); assertEquals(duration, watch.getDuration());
assertThat("time", time, allOf(greaterThanOrEqualTo(500L), lessThan(2000L))); assertTrue(duration.compareTo(sleepDuration) > 0);
assertThat("duration", duration.toMillis(), allOf(greaterThanOrEqualTo(500L), lessThan(2000L)));
watch.reset(); watch.reset();
assertEquals(0, watch.getTime()); assertEquals(0, watch.getTime());
assertEquals(Duration.ZERO, watch.getDuration()); assertEquals(Duration.ZERO, watch.getDuration());