### Question:
MetricProducerMethodBean { @Timed(name = "calls") public void cachedMethod(boolean hit) { if (hit) hits.mark(); }  @Timed(name = "calls") void cachedMethod(boolean hit);  }### Answer:
@Test @InSequence(2) public void callCachedMethodMultipleTimes() { assertThat("Metrics are not registered correctly", registry.getMetrics(), allOf( hasKey(CALLS_METRIC), hasKey(HITS_METRIC), hasKey(CACHE_HITS_METRIC), not(hasKey("not_registered_metric")) ) ); Timer calls = registry.getTimers().get(CALLS_METRIC); Meter hits = registry.getMeters().get(HITS_METRIC); @SuppressWarnings("unchecked") Gauge<Double> gauge = (Gauge<Double>) registry.getGauges().get(CACHE_HITS_METRIC); long count = 10 + Math.round(Math.random() * 10); for (int i = 0; i < count; i++) bean.cachedMethod((Math.random() < 0.5)); assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo((double) hits.getCount() / (double) calls.getCount()))); }