ImmutableLabel implements Label { public static Label of(final CharSequence labelValue) { argumentNotEmpty(labelValue, "label value"); final Validator validator = NoControlCharactersNoSlashesValidator.getInstance(labelValue); if (!validator.isValid()) { throw PolicyEntryInvalidException.newBuilder() .message("The Policy Label " + labelValue + " is invalid") .description(validator.getReason().orElse(null)) .build(); } return new ImmutableLabel(labelValue.toString()); } private  ImmutableLabel(final String theLabelValue); static Label of(final CharSequence labelValue); @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(expected = PolicyEntryInvalidException.class) public void createInvalidAttribute() { final String invalidLabel = "invalidLabel/"; ImmutableLabel.of(invalidLabel); }
@Test public void createValidLabelAttribute() { ImmutableLabel.of(generateStringWithMaxLength()); }
@Test(expected = PolicyEntryInvalidException.class) public void createTooLargeLabel() { ImmutableLabel.of(generateStringExceedingMaxLength()); }