ClassBasedTransformer implements Transformer { @Override public Map<String, String> getTags(String metricsName) { Map<String, String> tags = new HashMap<String, String>(); tags.put("metricName", metricsName); Matcher packageMatcher = PACKAGE.matcher(metricsName); if(packageMatcher.find()) { tags.put("package", packageMatcher.group(1)); } Matcher classMatcher = CLASS_NAME.matcher(metricsName); if(classMatcher.find()) { tags.put("className", classMatcher.group(1)); } Matcher methodMatcher = METHOD.matcher(metricsName); if(methodMatcher.find()) { tags.put("method", methodMatcher.group(1)); } return tags; }  @Override Map<String, String> getTags(String metricsName);  }
@Test public void shouldFindClassNames() { assertThat(new ClassBasedTransformer().getTags("com.izettle.metrics.influxdb.tags.ClassBasedTransformer.count")) .containsEntry("package", "com.izettle.metrics.influxdb.tags") .containsEntry("className", "ClassBasedTransformer") .containsEntry("method", "count"); assertThat(new ClassBasedTransformer().getTags("com.izettle.metrics.influxdb.tags.ClassBasedTransformer")) .containsEntry("package", "com.izettle.metrics.influxdb.tags") .containsEntry("className", "ClassBasedTransformer") .doesNotContainKeys("method"); assertThat(new ClassBasedTransformer().getTags("metric.without.class")) .containsEntry("metricName", "metric.without.class") .doesNotContainKeys("package") .doesNotContainKeys("className") .doesNotContainKeys("method"); }