### Question:
SpectatorMetricRegistry implements MetricRegistry { @Override public void gauge(String id, Supplier<Number> supplier, String... tagNameValuePairs) { Id metricId = suffixBaseId(id).withTags(tagNameValuePairs); PolledMeter.remove(registry, metricId); PolledMeter.using(registry) .withId(metricId) .monitorValue(supplier, ignore -> supplier.get().doubleValue()); } SpectatorMetricRegistry(Registry registry, Id baseId); @Override SampleListener distribution(String id, String... tagNameValuePairs); @Override void gauge(String id, Supplier<Number> supplier, String... tagNameValuePairs); @Override Counter counter(String id, String... tagNameValuePairs);  }### Answer:
@Test public void testGuage() { DefaultRegistry registry = new DefaultRegistry(); SpectatorMetricRegistry metricRegistry = new SpectatorMetricRegistry(registry, registry.createId("foo")); metricRegistry.gauge("bar", () -> 10); PolledMeter.update(registry); Assert.assertEquals(10.0, registry.gauge(registry.createId("foo.bar")).value(), 0); }
@Test public void testUnregister() { DefaultRegistry registry = new DefaultRegistry(); SpectatorMetricRegistry metricRegistry = new SpectatorMetricRegistry(registry, registry.createId("foo")); metricRegistry.gauge("bar", () -> 10); metricRegistry.gauge("bar", () -> 20); PolledMeter.update(registry); Assert.assertEquals(20.0, registry.gauge(registry.createId("foo.bar")).value(), 0); }