### Question:
OpenMetricsExporter implements MetricExporter { @Override public void export(MetricID metricID, Counter counter, Metadata metadata) { String total = globalName(metricID, "_total"); appendTYPE(total, OpenMetricsType.counter); appendHELP(total, metadata); appendValue(total, metricID.getTagsAsArray(), counter.getCount()); } OpenMetricsExporter(Writer out); protected  OpenMetricsExporter(Type scope, PrintWriter out, Set<String> typeWrittenByGlobalName,
            Set<String> helpWrittenByGlobalName); @Override MetricExporter in(Type scope, boolean asNode); @Override void exportComplete(); @Override void export(MetricID metricID, Counter counter, Metadata metadata); @Override void export(MetricID metricID, ConcurrentGauge gauge, Metadata metadata); @Override void export(MetricID metricID, Gauge<?> gauge, Metadata metadata); @Override void export(MetricID metricID, Histogram histogram, Metadata metadata); @Override void export(MetricID metricID, Meter meter, Metadata metadata); @Override void export(MetricID metricID, SimpleTimer timer, Metadata metadata); @Override void export(MetricID metricID, Timer timer, Metadata metadata); static String sanitizeMetricName(String name);  }### Answer:
@Test public void eachTypeAndHelpLineOccursOnlyOnceForEachOpenMetricsName() { Gauge<Long> g1 = () -> 1L; MetricID g1ID = new MetricID("common", new Tag("a", "b")); Gauge<Long> g2 = () -> 2L; MetricID g2ID = new MetricID("common", new Tag("some", "other")); Metadata metadata = Metadata.builder() .withName("common") .withDescription("description") .build(); exporter.export(g1ID, g1, metadata); exporter.export(g2ID, g2, metadata); assertEquals("# TYPE application_common gauge\n" + "# HELP application_common description\n" + "application_common{a=\"b\"} 1\n" + "application_common{some=\"other\"} 2\n", actual.getBuffer().toString()); }
@Test public void quantilesAreAppendedOtherTags() { Histogram histogram = mock(Histogram.class); Snapshot snapshot = mock(Snapshot.class); when(histogram.getSnapshot()).thenReturn(snapshot); MetricID metricID = new MetricID("test6", new Tag("custom", "tag-value")); Metadata metadata = Metadata.builder() .withName(metricID.getName()) .withUnit(MetricUnits.MILLISECONDS) .build(); exporter.export(metricID, histogram, metadata); String actualOutput = actual.getBuffer().toString(); assertTrue(actualOutput.contains("application_test6_seconds{custom=\"tag-value\",quantile=\"0.5\"} 0")); }