DefaultObjectNameFactory implements ObjectNameFactory { @Override public ObjectName createName(String type, String domain, String name) { try { ObjectName objectName; Hashtable<String, String> properties = new Hashtable<>(); properties.put("name", name); properties.put("type", type); objectName = new ObjectName(domain, properties); if (objectName.isDomainPattern()) { domain = ObjectName.quote(domain); } if (objectName.isPropertyValuePattern("name")) { properties.put("name", ObjectName.quote(name)); } if (objectName.isPropertyValuePattern("type")) { properties.put("type", ObjectName.quote(type)); } objectName = new ObjectName(domain, properties); 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); } } }  @Override ObjectName createName(String type, String domain, String name);  }
@Test public void createsObjectNameWithDomainInInput() { DefaultObjectNameFactory f = new DefaultObjectNameFactory(); ObjectName on = f.createName("type", "com.domain", "something.with.dots"); assertThat(on.getDomain()).isEqualTo("com.domain"); }
@Test public void createsObjectNameWithNameAsKeyPropertyName() { DefaultObjectNameFactory f = new DefaultObjectNameFactory(); ObjectName on = f.createName("type", "com.domain", "something.with.dots"); assertThat(on.getKeyProperty("name")).isEqualTo("something.with.dots"); }