PrincipalImpl implements JackrabbitPrincipal { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof JackrabbitPrincipal) { return name.equals(((JackrabbitPrincipal) obj).getName()); } return false; } PrincipalImpl(String name); @Override String getName(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testEqualsSame() { assertTrue(principal.equals(principal)); }
@Test public void testEquals() { List<Principal> principals = new ArrayList<>(); principals.add(new PrincipalImpl("name")); principals.add(new TestPrincipal("name")); principals.add(new JackrabbitPrincipal() { @Override public String getName() { return "name"; } }); for (Principal p : principals) { assertEquals(principal, p); } }
@Test public void testNotEquals() { List<Principal> principals = new ArrayList<>(); principals.add(new PrincipalImpl("otherName")); principals.add(new Principal() { @Override public String getName() { return "name"; } }); for (Principal p : principals) { assertFalse(principal.equals(p)); } }