GenericAuditEntity extends TaggedLogAPIEntity { public boolean equals (Object obj) { if(obj == this) return true; if(!(obj instanceof GenericAuditEntity)) return false; GenericAuditEntity that = (GenericAuditEntity) obj; if(compare(that.getTags().get(AUDIT_COLUMN_SERVICE_NAME), this.getTags().get(AUDIT_COLUMN_SERVICE_NAME)) && compare(that.getTags().get(AUDIT_COLUMN_USER_ID), this.getTags().get(AUDIT_COLUMN_USER_ID)) && compare(that.getTags().get(AUDIT_COLUMN_OPERATION), this.getTags().get(AUDIT_COLUMN_OPERATION)) && compare(that.getTags().get(AUDIT_COLUMN_TIMESTAMP), this.getTags().get(AUDIT_COLUMN_TIMESTAMP))) return true; return false; }  boolean equals(Object obj); int hashCode();  }
@Test public void testEqualsObj() { GenericAuditEntity genericAuditEntity = new GenericAuditEntity(); Assert.assertTrue(genericAuditEntity.equals(genericAuditEntity)); }
@Test public void testEqualsInstanceOf() { GenericAuditEntity genericAuditEntity = new GenericAuditEntity(); Object obj = new Object(); Assert.assertFalse(genericAuditEntity.equals(obj)); }
@Test public void testEqualsTrue() { GenericAuditEntity genericAuditEntity1 = new GenericAuditEntity(); GenericAuditEntity genericAuditEntity2 = new GenericAuditEntity(); Map<String, String> tags1 = new HashMap<>(); tags1.put(AuditConstants.AUDIT_COLUMN_SERVICE_NAME, "testService"); tags1.put(AuditConstants.AUDIT_COLUMN_USER_ID, "eagle1"); tags1.put(AuditConstants.AUDIT_COLUMN_OPERATION, "UPDATE"); tags1.put(AuditConstants.AUDIT_COLUMN_TIMESTAMP, "1479107183"); Map<String, String> tags2 = new HashMap<>(); tags2.put(AuditConstants.AUDIT_COLUMN_SERVICE_NAME, "testService"); tags2.put(AuditConstants.AUDIT_COLUMN_USER_ID, "eagle1"); tags2.put(AuditConstants.AUDIT_COLUMN_OPERATION, "UPDATE"); tags2.put(AuditConstants.AUDIT_COLUMN_TIMESTAMP, "1479107183"); genericAuditEntity1.setTags(tags1); genericAuditEntity2.setTags(tags2); Assert.assertTrue(genericAuditEntity1.equals(genericAuditEntity2)); }
@Test public void testEqualsFalse() { GenericAuditEntity genericAuditEntity1 = new GenericAuditEntity(); GenericAuditEntity genericAuditEntity2 = new GenericAuditEntity(); Map<String, String> tags1 = new HashMap<>(); tags1.put(AuditConstants.AUDIT_COLUMN_SERVICE_NAME, "testService"); tags1.put(AuditConstants.AUDIT_COLUMN_USER_ID, "eagle1"); tags1.put(AuditConstants.AUDIT_COLUMN_OPERATION, "UPDATE"); tags1.put(AuditConstants.AUDIT_COLUMN_TIMESTAMP, null); Map<String, String> tags2 = new HashMap<>(); tags2.put(AuditConstants.AUDIT_COLUMN_SERVICE_NAME, "testService"); tags2.put(AuditConstants.AUDIT_COLUMN_USER_ID, "eagle1"); tags2.put(AuditConstants.AUDIT_COLUMN_OPERATION, "UPDATE"); tags2.put(AuditConstants.AUDIT_COLUMN_TIMESTAMP, "1479107183"); genericAuditEntity1.setTags(tags1); genericAuditEntity2.setTags(tags2); Assert.assertFalse(genericAuditEntity1.equals(genericAuditEntity2)); }