### Question:
JvmGcMetrics extends AbstractLifecycleListener { void bindTo(final MetricRegistry registry) { for (final GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { final Labels tags = Labels.Mutable.of("name", garbageCollectorMXBean.getName()); registry.addUnlessNegative("jvm.gc.count", tags, new DoubleSupplier() { @Override public double get() { return garbageCollectorMXBean.getCollectionCount(); } }); registry.addUnlessNegative("jvm.gc.time", tags, new DoubleSupplier() { @Override public double get() { return garbageCollectorMXBean.getCollectionTime(); } }); } try { final Class<?> sunBeanClass = Class.forName("com.sun.management.ThreadMXBean"); if (sunBeanClass.isInstance(ManagementFactory.getThreadMXBean())) { registry.add("jvm.gc.alloc", Labels.EMPTY, (DoubleSupplier) Class.forName(getClass().getName() + "$HotspotAllocationSupplier").getEnumConstants()[0]); } } catch (ClassNotFoundException ignore) { } }  @Override void start(ElasticApmTracer tracer);  }### Answer:
@Test void testGcMetrics() { jvmGcMetrics.bindTo(registry); verify(registry, atLeastOnce()).addUnlessNegative(eq("jvm.gc.count"), any(), any()); verify(registry, atLeastOnce()).addUnlessNegative(eq("jvm.gc.time"), any(), any()); verify(registry, atLeastOnce()).add(eq("jvm.gc.alloc"), any(), any()); }