GCStat { long elapsed() { long previous = previousElapsed; long current = bean.getCollectionTime(); previousElapsed = current; if (previous == -1) return 0; return (current - previous) * 1_000_000; } private  GCStat(GarbageCollectorMXBean bean, String name);   }
@Test void elapsed() { when(bean.getCollectionTime()).thenReturn(500L, 1000L, 3000L); assertThat(stat.elapsed()).isEqualTo(Duration.ZERO.toNanos()); assertThat(stat.elapsed()).isEqualTo(Duration.ofMillis(500).toNanos()); assertThat(stat.elapsed()).isEqualTo(Duration.ofMillis(2000).toNanos()); }