ExternalIdentityRef { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ExternalIdentityRef) { return string.equals(((ExternalIdentityRef) o).string); } return false; } ExternalIdentityRef(@NotNull String id, @Nullable String providerName); @Nullable String getProviderName(); @NotNull String getId(); @NotNull String getString(); @NotNull static ExternalIdentityRef fromString(@NotNull String str); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testEquals() { assertEquals(refNullProvider, refNullProvider); assertEquals(refNullProvider, new ExternalIdentityRef(USERID, refNullProvider.getProviderName())); assertEquals(refNullProvider, new ExternalIdentityRef(USERID, refEmptyProvider.getProviderName())); assertEquals(refNullProvider, refEmptyProvider); assertEquals(refEmptyProvider, refNullProvider); assertEquals(ref, ref); assertEquals(ref, new ExternalIdentityRef(ref.getId(), ref.getProviderName())); assertEquals(ref, new ExternalIdentityRef(USERID, PROVIDER_NAME)); }
@Test public void testNotEquals() { Map<ExternalIdentityRef, ExternalIdentityRef> notEqual = new HashMap<>(); notEqual.put(refNullProvider, ref); notEqual.put(refEmptyProvider, ref); notEqual.put(refNullProvider, null); notEqual.put(refNullProvider, new ExternalIdentityRef("anotherId", null)); notEqual.put(ref, new ExternalIdentityRef("anotherId", PROVIDER_NAME)); notEqual.put(ref, new ExternalIdentityRef(USERID, "anotherProvider")); for (Map.Entry<ExternalIdentityRef, ExternalIdentityRef> entry : notEqual.entrySet()) { ExternalIdentityRef r1 = entry.getKey(); ExternalIdentityRef r2 = entry.getValue(); assertFalse(r1.equals(r2)); if (r2 != null) { assertFalse(r2.equals(r1)); } } }