Stopwatch { public static Duration measure(@Nonnull Runnable runnable) { DockerCloudUtils.requireNonNull(runnable, "Runnable cannot be null."); Stopwatch sw = start(); runnable.run(); return sw.getDuration(); } private  Stopwatch(long startTime); static Stopwatch start(); static Duration measure(@Nonnull Runnable runnable); @Nonnull Duration getDuration();  }
@Test public void measure() { Stopwatch sw = Stopwatch.start(); TestUtils.waitSec(1); assertThat(sw.getDuration().toMillis()).isCloseTo(1000L, offset(150L)); }
@Test public void measureRunnable() { Runnable runnable = () -> TestUtils.waitSec(1); assertThat(Stopwatch.measure(runnable).toMillis()).isCloseTo(1000L, offset(150L)); }