### Question:
JvmMetrics implements MetricsSource { @Override public void getMetrics(MetricsCollector collector, boolean all) { MetricsRecordBuilder rb = collector.addRecord(JvmMetrics) .setContext("jvm").tag(ProcessName, processName) .tag(SessionId, sessionId); getMemoryUsage(rb); getGcUsage(rb); getThreadUsage(rb); getEventCounters(rb); } JvmMetrics(String processName, String sessionId); static JvmMetrics create(String processName, String sessionId,
                                  MetricsSystem ms); static JvmMetrics initSingleton(String processName, String sessionId); @Override void getMetrics(MetricsCollector collector, boolean all);  }### Answer:
@Test public void testPresence() { MetricsRecordBuilder rb = getMetrics(new JvmMetrics("test", "test")); MetricsCollector mc = rb.parent(); verify(mc).addRecord(JvmMetrics); verify(rb).tag(ProcessName, "test"); verify(rb).tag(SessionId, "test"); for (JvmMetricsInfo info : JvmMetricsInfo.values()) { if (info.name().startsWith("Mem")) verify(rb).addGauge(eq(info), anyFloat()); else if (info.name().startsWith("Gc")) verify(rb).addCounter(eq(info), anyLong()); else if (info.name().startsWith("Threads")) verify(rb).addGauge(eq(info), anyInt()); else if (info.name().startsWith("Log")) verify(rb).addCounter(eq(info), anyLong()); } }