ThingId extends NamespacedEntityIdWithType { public static ThingId of(final CharSequence thingId) { if (thingId instanceof ThingId) { return (ThingId) thingId; } return wrapInThingIdInvalidException(() -> new ThingId(DefaultNamespacedEntityId.of(thingId))); } private  ThingId(final NamespacedEntityId entityId); static ThingId of(final CharSequence thingId); static ThingId of(final String namespace, final String name); static ThingId inDefaultNamespace(final String name); static ThingId generateRandom(); static ThingId dummy(); @Override EntityType getEntityType();  }
@Test public void invalidNamespaceThrowsThingInvalidException() { assertThatExceptionOfType(ThingIdInvalidException.class) .isThrownBy(() -> ThingId.of(".invalidNamespace", "validName")); assertThatExceptionOfType(ThingIdInvalidException.class) .isThrownBy(() -> ThingId.of(".invalidNamespace:validName")); }
@Test public void manuallyCreatedDummyIsDummy() { softly.assertThat(ThingId.of("", "_").isDummy()).isTrue(); softly.assertThat(ThingId.of(":_").isDummy()).isTrue(); }
@Test public void validThingIdIsNoDummy() { softly.assertThat(ThingId.of("namespace", "name").isDummy()).isFalse(); softly.assertThat(ThingId.of("namespace:name").isDummy()).isFalse(); }
@Test public void toStringConcatenatesNamespaceAndName() { softly.assertThat(ThingId.of("namespace", "name").toString()).isEqualTo("namespace:name"); softly.assertThat(ThingId.of("namespace:name").toString()).isEqualTo("namespace:name"); }
@Test public void returnsCorrectNamespace() { softly.assertThat(ThingId.of("namespace", "name").getNamespace()).isEqualTo("namespace"); softly.assertThat(ThingId.of("namespace:name").getNamespace()).isEqualTo("namespace"); }
@Test public void returnsCorrectName() { softly.assertThat(ThingId.of("namespace", "name").getName()).isEqualTo("name"); softly.assertThat(ThingId.of("namespace:name").getName()).isEqualTo("name"); }
@Test public void thingIdOfThingIdReturnsSameInstance() { final ThingId thingIdOne = ThingId.of("namespace", "name"); final ThingId thingIdTwo = ThingId.of(thingIdOne); assertThat((CharSequence) thingIdOne).isSameAs(thingIdTwo); }