Transaction implements Comparable<Transaction> { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (!(obj instanceof Transaction)) { return false; } Transaction other = (Transaction) obj; return amount == other.getAmount() && Objects.equals(getDate(), other.getDate()) && getDescription().equalsIgnoreCase(other.getDescription()) && Objects.equals(accountNumber, other.getAccountNumber()); } Transaction(Date date, String description, long amount, Category category, String accountNumber); private  Transaction(String id, Date date, String description, long amount, String categoryName, Category category,
			String accountNumber); String getId(); Date getDate(); String getDescription(); long getAmount(); String getAccountNumber(); Category getCategory(); String getCategoryName(); Transaction withCategory(Category category); Transaction withCategoryName(String categoryName); Transaction withId(String id); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Transaction o); @Override String toString();  }
@Test public void equals() { Date date1 = new Date(1441842160000L); Date date2 = new Date(1441850000000L); Transaction transaction1 = new Transaction(date1, "a desc", 1003, null, null); Transaction transaction2 = new Transaction(date1, "a desc", 1003, null, "123"); Transaction transaction3 = transaction1.withCategoryName("some category"); assertTransactionEqualsCaseInsensitive(transaction1); assertTransactionEqualsCaseInsensitive(transaction2); assertTransactionEqualsCaseInsensitive(transaction3); assertTransactionEquals(transaction1, transaction1); assertTransactionEquals(transaction1, transaction3); assertTransactionEquals(transaction1, new Transaction(date1, "a desc", 1003, null, null)); assertTransactionEquals(transaction2, new Transaction(date1, "a desc", 1003, null, "123")); assertTransactionNotEquals(transaction1, new Object()); assertTransactionNotEquals(transaction1, null); assertTransactionNotEquals(transaction1, transaction2); assertTransactionNotEquals(transaction1, new Transaction(date1, "a desc", 1004, null, null)); assertTransactionNotEquals(transaction1, new Transaction(date1, "a desc2", 1003, null, null)); assertTransactionNotEquals(transaction1, new Transaction(date2, "a desc", 1003, null, null)); }