DefaultObjectNameFactory implements ObjectNameFactory { public ObjectName createName(String type, String domain, MetricName metricName) { String name = metricName.getKey(); try { ObjectName objectName = new ObjectName(domain, "name", name); if (objectName.isPattern()) { objectName = new ObjectName(domain, "name", ObjectName.quote(name)); } return objectName; } catch (MalformedObjectNameException e) { try { return new ObjectName(domain, "name", ObjectName.quote(name)); } catch (MalformedObjectNameException e1) { LOGGER.warn("Unable to register {} {}", type, name, e1); throw new RuntimeException(e1); } } }  ObjectName createName(String type, String domain, MetricName metricName);  }
@Test public void createsObjectNameWithDomainInInput() { DefaultObjectNameFactory f = new DefaultObjectNameFactory(); ObjectName on = f.createName("type", "com.domain", MetricName.build("something.with.dots")); Assertions.assertThat(on.getDomain()).isEqualTo("com.domain"); }
@Test public void createsObjectNameWithNameAsKeyPropertyName() { DefaultObjectNameFactory f = new DefaultObjectNameFactory(); ObjectName on = f.createName("type", "com.domain", MetricName.build("something.with.dots")); Assertions.assertThat(on.getKeyProperty("name")).isEqualTo("something.with.dots"); }