### Question:
MetricUtil { public static synchronized void registerGauge(MetricRegistry metricReg, final String key, Gauge gauge) { if (metricReg != null) { try { SortedMap<String, Gauge> existingGauges = metricReg.getGauges(new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.equals(key); } }); if (existingGauges.isEmpty()) { gauge = new ChangeableGauge(gauge); metricReg.register(key, gauge); } else { ChangeableGauge cGauge = (ChangeableGauge) existingGauges.values().iterator().next(); cGauge.setGauge(gauge); } } catch (IllegalArgumentException ex) { } } }  static synchronized void registerGauge(MetricRegistry metricReg,
      final String key, Gauge gauge); static void registerTimer(MetricRegistry metricReg, String key); static void registerMeter(MetricRegistry metricReg, String key); static void time(MetricRegistry metricReg, String key, long msTime,
      Object logContext); static void meter(MetricRegistry metricReg, String key, int count);  }### Answer:
@Test public void testGaugeRegistration() { MetricRegistry mr = new MetricRegistry(); Gauge<Integer> g1 = new MyGauge(1); MetricUtil.registerGauge(mr, "g", g1); Assert.assertEquals(1, mr.getGauges().entrySet().size()); Map.Entry<String, Gauge> entry = mr.getGauges().entrySet().iterator().next(); Assert.assertEquals("g", entry.getKey()); Assert.assertEquals(1, entry.getValue().getValue()); Gauge<Integer> g2 = new MyGauge(2); MetricUtil.registerGauge(mr, "g", g2); Assert.assertEquals(1, mr.getGauges().entrySet().size()); entry = mr.getGauges().entrySet().iterator().next(); Assert.assertEquals("g", entry.getKey()); Assert.assertEquals(2, entry.getValue().getValue()); }