MemberRole { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } MemberRole other = (MemberRole) obj; if (expiration != other.expiration) { return false; } if (role == null) { return other.role == null; } else { return role.equals(other.role); } } MemberRole(String role, long expiration); String getRole(); long getExpiration(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testMemberRoleEquals() { MemberRole mr1 = new MemberRole("role", 100); MemberRole mr2 = new MemberRole("role", 100); MemberRole mr3 = new MemberRole("role", 200); MemberRole mr4 = new MemberRole(null, 100); MemberRole mr5 = new MemberRole(null, 100); MemberRole mr6 = new MemberRole("role2", 100); assertTrue(mr1.equals(mr1)); assertFalse(mr1.equals(null)); assertFalse(mr1.equals("string")); assertTrue(mr1.equals(mr2)); assertFalse(mr1.equals(mr3)); assertFalse(mr4.equals(mr1)); assertTrue(mr4.equals(mr5)); assertFalse(mr1.equals(mr6)); }