ImmutableSubjectId implements SubjectId { public static SubjectId of(final SubjectIssuer issuer, final CharSequence subject) { checkNotNull(issuer, "issuer"); argumentNotEmpty(subject, "subject"); final String subjectIdAsString = issuer.toString() + ":" + subject.toString(); final Validator validator = NoControlCharactersValidator.getInstance(subjectIdAsString); if (!validator.isValid()) { throw SubjectIdInvalidException.newBuilder(subjectIdAsString) .description(validator.getReason().orElse(null)) .build(); } return new ImmutableSubjectId(issuer, subject.toString()); } private  ImmutableSubjectId(final SubjectIssuer issuer, final String subject); static SubjectId of(final SubjectIssuer issuer, final CharSequence subject); static SubjectId of(final CharSequence subjectIssuerWithId); @Override SubjectIssuer getIssuer(); @Override String getSubject(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); @Override boolean equals(final Object o); @Override int hashCode(); @Override @Nonnull String toString();  }
@Test public void subjectIdCannotHaveMoreThan256Characters() { final String invalidSubjectId = generateStringExceedingMaxLength(ISSUER_WITH_SEPARATOR); assertThatExceptionOfType(SubjectIdInvalidException.class) .isThrownBy(() -> ImmutableSubjectId.of(invalidSubjectId)); }
@Test public void createInvalidAttribute() { final String invalidSubjectId = "invalidSubjectID\u0001"; assertThatExceptionOfType(SubjectIdInvalidException.class) .isThrownBy(() -> ImmutableSubjectId.of(invalidSubjectId)); }