### Question:
MetricRegistryImpl extends MetricRegistry { @Override public Counter counter(String name) { return findMetricOrCreate(name, COUNTER, new Tag[0]); } MetricRegistryImpl();  MetricRegistryImpl(Clock clock); MetricRegistryImpl addListener(MetricRegistrationListener listener); @Override Counter counter(String name); @Override Counter counter(Metadata metadata); @Override Counter counter(String name, Tag... tags); @Override Counter counter(Metadata metadata, Tag... tags); @Override Histogram histogram(String name); @Override Histogram histogram(Metadata metadata); @Override Meter meter(String name); @Override Meter meter(Metadata metadata); @Override SimpleTimer simpleTimer(String name); @Override SimpleTimer simpleTimer(Metadata metadata); @Override Timer timer(String name); @Override Timer timer(Metadata metadata); @Override ConcurrentGauge concurrentGauge(String name); @Override ConcurrentGauge concurrentGauge(String name, Tag... tags); @Override ConcurrentGauge concurrentGauge(Metadata metadata); @Override ConcurrentGauge concurrentGauge(Metadata metadata, Tag... tags); @Override Histogram histogram(String name, Tag... tags); @Override Histogram histogram(Metadata metadata, Tag... tags); @Override Meter meter(String name, Tag... tags); @Override Meter meter(Metadata metadata, Tag... tags); @Override SimpleTimer simpleTimer(String name, Tag... tags); @Override SimpleTimer simpleTimer(Metadata metadata, Tag... tags); @Override Timer timer(String name, Tag... tags); @Override Timer timer(Metadata metadata, Tag... tags); @Override SortedSet<MetricID> getMetricIDs(); @Override SortedSet<String> getNames(); @Override SortedMap<MetricID, Gauge> getGauges(); @Override SortedMap<MetricID, Gauge> getGauges(MetricFilter filter); @Override SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(); @Override SortedMap<MetricID, ConcurrentGauge> getConcurrentGauges(MetricFilter filter); @Override SortedMap<MetricID, Counter> getCounters(); @Override SortedMap<MetricID, Counter> getCounters(MetricFilter filter); @Override SortedMap<MetricID, Histogram> getHistograms(); @Override SortedMap<MetricID, Histogram> getHistograms(MetricFilter filter); @Override SortedMap<MetricID, Meter> getMeters(); @Override SortedMap<MetricID, Meter> getMeters(MetricFilter filter); @Override SortedMap<MetricID, SimpleTimer> getSimpleTimers(); @Override SortedMap<MetricID, SimpleTimer> getSimpleTimers(MetricFilter filter); @Override SortedMap<MetricID, Timer> getTimers(); @Override SortedMap<MetricID, Timer> getTimers(MetricFilter filter); @Override Map<MetricID, Metric> getMetrics(); @Override Map<String, Metadata> getMetadata(); @Override boolean remove(String name); @Override boolean remove(MetricID metricID); @Override void removeMatching(MetricFilter filter); @Override T register(String name, T metric); @Override T register(Metadata metadata, T metric); @Override T register(Metadata metadata, T metric, Tag... tags); @SuppressWarnings("unchecked") T getMetric(MetricID metricID, Class<T> metricType); Set<MetricID> getMetricsIDs(String name); Map<MetricID, Metric> getMetrics(String name); Metadata getMetadata(String name); @Override String toString();  }### Answer:
@Test public void counterByNameUsesExistingMetadataForSameName() { assertExistingMetadataIsUsed( name -> registry.counter(withName(name)), name -> registry.counter(name)); }
@Test public void counterByNameReceivesExistingCounter() { String name = nextName(); Counter counter = registry.counter(name); assertSame(counter, registry.counter(name)); assertNotSame(counter, registry.counter(nextName())); }
@Test public void counterByMetaThrowsExceptionWhenMetadataIsDifferent() { assertException("Tried to lookup a metric with conflicting metadata, looup is ...", name -> registry.counter(withName(name)), name -> registry.counter(withNameAnd(name).withDisplayName("other").build())); }