UserPrincipal extends AbstractPrincipal { @Override public boolean equals(Object obj) { if (!(obj instanceof UserPrincipal)) { return false; } if (this == obj) { return true; } UserPrincipal rhs = (UserPrincipal) obj; return new EqualsBuilder().appendSuper(super.equals(obj)).append(user.getId(), rhs.user.getId()).isEquals(); } UserPrincipal(PLCUser user); PLCUser getUser(); @Override String getName(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void equalityForSameObject() { UserPrincipal testUserPrincipal = createTestUserPrincipal(TEST_ID, TEST_USERNAME); assertTrue(testUserPrincipal.equals(testUserPrincipal)); }
@Test public void equalsWhenIDsAndNamesAreEqual() { UserPrincipal testUserPrincipal1 = createTestUserPrincipal(TEST_ID, TEST_USERNAME); UserPrincipal testUserPrincipal2 = createTestUserPrincipal(TEST_ID, TEST_USERNAME); assertTrue(testUserPrincipal1.equals(testUserPrincipal2)); }
@Test public void equalsWithSameIDsAndDifferentNames() { UserPrincipal testUserPrincipal1 = createTestUserPrincipal(TEST_ID, TEST_USERNAME); UserPrincipal testUserPrincipal2 = createTestUserPrincipal(TEST_ID, "test1"); assertFalse(testUserPrincipal1.equals(testUserPrincipal2)); }
@Test public void inequalityWithNull() { UserPrincipal testUserPrincipal = createTestUserPrincipal(TEST_ID, TEST_USERNAME); assertFalse(testUserPrincipal.equals(null)); }
@Test public void inequalityWhenNotSameClass() { UserPrincipal testUserPrincipal = createTestUserPrincipal(TEST_ID, TEST_USERNAME); assertFalse(testUserPrincipal.equals(new Object())); }