Authority implements GrantedAuthority { @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Authority)) { return false; } if (obj == this) { return true; } Authority other = (Authority) obj; return Objects.equals(authority, other.authority); } private  Authority();  Authority(String authority);  Authority(String authority, String description); @Id @GeneratedValue Long getId(); void setId(Long id); @Override @Column(unique = true) String getAuthority(); String getDescription(); void setDescription(String description); Long getVersion(); void setVersion(Long version); LocalDateTime getLastModified(); void setLastModified(LocalDateTime lastModified); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testEquals() { Authority userAuthority = new Authority("user"); Authority adminAuthority = new Authority("admin"); assertThat(userAuthority, not(equalTo(adminAuthority))); assertThat(userAuthority, equalTo(new Authority("user"))); assertThat(userAuthority, equalTo(userAuthority)); assertThat(userAuthority, not(equalTo(null))); }