TableEvent extends Event { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TableEvent other = (TableEvent) obj; if (other.getCommand() == null && this.getCommand() != null) { return false; } else if (other.getCommand() != null && this.getCommand() == null) { return false; } return other.getCommand().equals(this.getCommand()) && other.actionId.equals(actionId) && other.rowId == rowId; } TableEvent(final String command, final int rowId, final String actionId); String getActionId(); int getRowId(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testEqualsCodeContract() { assertFalse("Wrong equals implementation, different types are recognized as equals ", one.equals(new Integer(1))); assertFalse("Wrong equals implementation, different objects are recognized as equals ", one.equals(two)); assertFalse("Wrong equals implementation, null value is recognized as equals ", one.equals(null)); assertTrue("Wrong equals implementation, same objects are NOT recognized as equals ", one.equals(sameRefAsOne)); assertTrue("Wrong equals implementation, same objecst are NOT recognized as equals ", one.equals(sameAsOne)); }