### Question:
PerDocTypeCounter { @VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); }  static void inc(@Nullable Map<String, String> attributes, String name); static void inc(@Nullable Map<String, String> attributes, String name, long n);  }### Answer:
@Test public void getCounterTest() { Map<String, String> attributes = ImmutableMap .of("document_namespace", "telemetry", "document_type", "core", "document_version", "10"); Counter counter = PerDocTypeCounter.getOrCreateCounter(attributes, "my-name"); assertEquals("telemetry/core_v10/my_name", counter.getName().getName()); }
@Test public void getCounterVersionlessTest() { Map<String, String> attributes = ImmutableMap .of("document_namespace", "telemetry", "document_type", "core"); Counter counter = PerDocTypeCounter.getOrCreateCounter(attributes, "my-name"); assertEquals("telemetry/core/my_name", counter.getName().getName()); }
@Test public void getCounterNullTest() { Counter counter = PerDocTypeCounter.getOrCreateCounter(null, "my-name"); assertEquals("unknown_namespace/unknown_doctype/my_name", counter.getName().getName()); }