### Question:
CodaHaleMetricRegistry implements MetricRegistry { @Override public Timer timer(String name) { Map<String, Metric> metrics = metricRegistry.getMetrics(); Metric metric = metrics.get(name); if (metric instanceof Timer) { return (Timer) metric; } if (metric == null) { try { return register(name, newTimer()); } catch (IllegalArgumentException e) { Metric added = metrics.get(name); if (added instanceof Timer) { return (Timer) added; } } } throw new IllegalArgumentException(name + " is already used for a different type of metric"); } CodaHaleMetricRegistry(com.codahale.metrics.MetricRegistry metricRegistry);  CodaHaleMetricRegistry(); com.codahale.metrics.MetricRegistry getMetricRegistry(); @Override MetricRegistry scope(String name); @Override T register(String name, T metric); @Override boolean deregister(String name); @Override Counter counter(String name); @Override Histogram histogram(String name); @Override Meter meter(String name); @Override Timer timer(String name); @Override void addListener(MetricRegistryListener listener); @Override void removeListener(MetricRegistryListener listener); @Override SortedSet<String> getNames(); @Override SortedMap<String, Gauge> getGauges(); @Override SortedMap<String, Gauge> getGauges(MetricFilter filter); @Override SortedMap<String, Counter> getCounters(); @Override SortedMap<String, Counter> getCounters(MetricFilter filter); @Override SortedMap<String, Histogram> getHistograms(); @Override SortedMap<String, Histogram> getHistograms(MetricFilter filter); @Override SortedMap<String, Meter> getMeters(); @Override SortedMap<String, Meter> getMeters(MetricFilter filter); @Override SortedMap<String, Timer> getTimers(); @Override SortedMap<String, Timer> getTimers(MetricFilter filter); static String name(String name, String... names); static String name(Class<?> klass, String... names); @Override SortedMap<String, Metric> getMetrics();  }### Answer:
@Test public void retrievesPreviouslyRegisteredTimer() { Timer timer = metricRegistry.timer("newTimer"); assertThat(timer, is(notNullValue())); assertThat(metricRegistry.timer("newTimer"), is(sameInstance(timer))); }
@Test public void createsTimerBackedByLatencyStats() { Timer timer = metricRegistry.timer("timer"); assertThat(timer.getSnapshot(), is(instanceOf(SlidingWindowHistogramReservoir.HistogramSnapshot.class))); }