ImmutableDefinitionIdentifier implements DefinitionIdentifier { static DefinitionIdentifier ofParsed(final CharSequence definitionIdentifier) { checkNotNull(definitionIdentifier, "CharSequence-representation of the identifier"); if (definitionIdentifier instanceof DefinitionIdentifier) { return (DefinitionIdentifier) definitionIdentifier; } final Matcher matcher = IDENTIFIER_PATTERN.matcher(definitionIdentifier); if (!matcher.matches()) { throw new DefinitionIdentifierInvalidException(definitionIdentifier); } final String parsedNamespace = matcher.group(CapturingGroup.NAMESPACE); final String parsedName = matcher.group(CapturingGroup.NAME); final String parsedVersion = matcher.group(CapturingGroup.VERSION); return getInstance(parsedNamespace, parsedName, parsedVersion); } private  ImmutableDefinitionIdentifier(final CharSequence theNamespace, final CharSequence theName,
            final CharSequence theVersion); @Override String getNamespace(); @Override String getName(); @Override String getVersion(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); @Override String toString();  }
@Test public void tryToParseNullIdentifierString() { assertThatNullPointerException() .isThrownBy(() -> ImmutableDefinitionIdentifier.ofParsed(null)) .withMessage("The %s must not be null!", "CharSequence-representation of the identifier") .withNoCause(); }
@Test public void tryToParseEmptyIdentifierString() { assertThatExceptionOfType(DefinitionIdentifierInvalidException.class) .isThrownBy(() -> ImmutableDefinitionIdentifier.ofParsed("")) .withMessage("Definition identifier <> is invalid!") .withNoCause(); }
@Test public void tryToParseIdentifierStringWithEmptyNameSegment() { final String invalidString = NAMESPACE + "::" + VERSION; assertThatExceptionOfType(DefinitionIdentifierInvalidException.class) .isThrownBy(() -> ImmutableDefinitionIdentifier.ofParsed(invalidString)) .withMessage("Definition identifier <%s> is invalid!", invalidString) .withNoCause(); }
@Test public void tryToParseIdentifierStringWithIllegalChar() { final String invalidString = "org/eclipse/ditto" + ":" + NAME + ":" + VERSION; assertThatExceptionOfType(DefinitionIdentifierInvalidException.class) .isThrownBy(() -> ImmutableDefinitionIdentifier.ofParsed(invalidString)) .withMessage("Definition identifier <%s> is invalid!", invalidString) .withNoCause(); }