ObjectNameFactory { public ObjectName create(final String domain, final String key, final String value) { try { return new ObjectName(domain, key, value); } catch (final MalformedObjectNameException exception) { throw new ObjectNameException(format( "Unable to create ObjectName: domain='%s', key='%s', value='%s'", domain, key, value), exception); } }  ObjectName create(final String domain, final String key, final String value);  }
@Test public void shouldCreateAnObjectName() throws Exception { final String domain = "domain"; final String key = "key"; final String value = "value"; final ObjectName objectName = objectNameFactory.create(domain, key, value); assertThat(objectName.getDomain(), is(domain)); assertThat(objectName.getCanonicalName(), is("domain:key=value")); }
@Test public void shouldThrowExceptionIfCreatingObjectNameThrowsMalformedObjectNameException() throws Exception { try { objectNameFactory.create("fred:fred", "type", "value"); fail(); } catch (final ObjectNameException expected) { assertThat(expected.getMessage(), is("Unable to create ObjectName: domain='fred:fred', key='type', value='value'")); assertThat(expected.getCause(), is(CoreMatchers.instanceOf(MalformedObjectNameException.class))); } }