### Question:
MicrometerRegistry implements Registry { @Override public Timer timer(Id id) { return new MicrometerTimer(id, impl.timer(id.name(), convert(id.tags()))); } MicrometerRegistry(MeterRegistry impl); @Override Clock clock(); @Override Id createId(String name); @Override Id createId(String name, Iterable<Tag> tags); @Override void register(Meter meter); @Override ConcurrentMap<Id, Object> state(); @Override Counter counter(Id id); @Override DistributionSummary distributionSummary(Id id); @Override Timer timer(Id id); @Override Gauge gauge(Id id); @Override Gauge maxGauge(Id id); @Override Meter get(Id id); @Override Iterator<Meter> iterator();  }### Answer:
@Test public void timerRecord() { Timer t = registry.timer("foo"); Assertions.assertEquals(0, t.count()); Assertions.assertEquals(0, t.totalTime()); t.record(42, TimeUnit.SECONDS); Assertions.assertEquals(1, t.count()); Assertions.assertEquals(TimeUnit.SECONDS.toNanos(42), t.totalTime()); }
@Test public void timerRecordRunnable() { Timer t = registry.timer("foo"); t.record((Runnable) () -> clock.add(42, TimeUnit.SECONDS)); Assertions.assertEquals(1, t.count()); Assertions.assertEquals(TimeUnit.SECONDS.toNanos(42), t.totalTime()); }
@Test public void timerRecordCallable() throws Exception { Timer t = registry.timer("foo"); t.record(() -> clock.add(42, TimeUnit.SECONDS)); Assertions.assertEquals(1, t.count()); Assertions.assertEquals(TimeUnit.SECONDS.toNanos(42), t.totalTime()); }
@Test public void timerMeasure() { Timer t = registry.timer("foo"); t.record(42, TimeUnit.SECONDS); int i = 0; for (Measurement m : t.measure()) { ++i; Assertions.assertEquals("foo", m.id().name()); switch (Utils.getTagValue(m.id(), "statistic")) { case "count": Assertions.assertEquals(1.0, m.value(), 1e-12); break; case "total": Assertions.assertEquals(42.0, m.value(), 1e-12); break; case "max": Assertions.assertEquals(42.0, m.value(), 1e-12); break; default: Assertions.fail("invalid statistic for measurment: " + m); } } Assertions.assertEquals(3, i); }