PolicyId implements NamespacedEntityId { public static PolicyId of(final CharSequence policyId) { if (policyId instanceof PolicyId) { return (PolicyId) policyId; } return wrapInPolicyIdInvalidException(() -> new PolicyId(DefaultNamespacedEntityId.of(policyId))); } private  PolicyId(final NamespacedEntityId entityId); static PolicyId of(final CharSequence policyId); static PolicyId of(final PolicyId policyId); static PolicyId of(final String namespace, final String policyName); static PolicyId inNamespaceWithRandomName(final String namespace); static PolicyId dummy(); @Override String getName(); @Override String getNamespace(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); @Override boolean isDummy();  }
@Test public void invalidNameThrowsPolicyIdInvalidException() { assertThatExceptionOfType(PolicyIdInvalidException.class) .isThrownBy(() -> PolicyId.of("validNamespace", "§inValidName")); assertThatExceptionOfType(PolicyIdInvalidException.class) .isThrownBy(() -> PolicyId.of("validNamespace:§inValidName")); }
@Test public void policyIdOfPolicyIdReturnsSameInstance() { final PolicyId policyIdOne = PolicyId.of("namespace", "name"); final PolicyId policyIdTwo = PolicyId.of(policyIdOne); assertThat((CharSequence) policyIdOne).isSameAs(policyIdTwo); }