NamespacedEntityIdWithType extends EntityIdWithType implements NamespacedEntityId { @Override public boolean isCompatibleOrThrow(@Nullable final EntityIdWithType otherEntityId) { final boolean result; if (null == otherEntityId) { result = false; } else if (equals(otherEntityId)) { result = true; } else if (!Objects.equals(getEntityType(), otherEntityId.getEntityType())) { result = false; } else if (otherEntityId instanceof NamespacedEntityIdWithType) { result = isNamespaceAndNameCompatible((NamespacedEntityId) otherEntityId); } else { result = false; } if (!result) { throw getIllegalArgumentExceptionForDifferentEntityIds(otherEntityId); } return result; } protected  NamespacedEntityIdWithType(final NamespacedEntityId namespacedEntityId); @Override String getNamespace(); @Override String getName(); @Override boolean isCompatibleOrThrow(@Nullable final EntityIdWithType otherEntityId); @Override boolean equals(@Nullable final Object o); @Override int hashCode();  }
@Test public void isCompatibleOrThrowBehavesCorrectly() { if (parameter.shouldBeCompatible) { assertThat(parameter.blue.isCompatibleOrThrow(parameter.green)).isTrue(); } else { assertThatIllegalArgumentException() .isThrownBy(() -> parameter.blue.isCompatibleOrThrow(parameter.green)) .withMessage("The entity ID <%s> is not compatible with <%s>!", parameter.green, parameter.blue) .withNoCause(); } }