@Test public void testEquals() { PlayerDetails details1 = new PlayerDetails("bob@foo.bar", "1212-121212", "+34332322"); LotteryNumbers numbers1 = LotteryNumbers.create(new HashSet<Integer>(Arrays.asList(1, 2, 3, 4))); LotteryTicket ticket1 = new LotteryTicket(new LotteryTicketId(), details1, numbers1); PlayerDetails details2 = new PlayerDetails("bob@foo.bar", "1212-121212", "+34332322"); LotteryNumbers numbers2 = LotteryNumbers.create(new HashSet<Integer>(Arrays.asList(1, 2, 3, 4))); LotteryTicket ticket2 = new LotteryTicket(new LotteryTicketId(), details2, numbers2); assertEquals(ticket1, ticket2); PlayerDetails details3 = new PlayerDetails("elsa@foo.bar", "1223-121212", "+49332322"); LotteryNumbers numbers3 = LotteryNumbers.create(new HashSet<Integer>(Arrays.asList(1, 2, 3, 8))); LotteryTicket ticket3 = new LotteryTicket(new LotteryTicketId(), details3, numbers3); assertFalse(ticket1.equals(ticket3)); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } LotteryTicket other = (LotteryTicket) obj; if (lotteryNumbers == null) { if (other.lotteryNumbers != null) { return false; } } else if (!lotteryNumbers.equals(other.lotteryNumbers)) { return false; } if (playerDetails == null) { if (other.playerDetails != null) { return false; } } else if (!playerDetails.equals(other.playerDetails)) { return false; } return true; }
LotteryTicket { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } LotteryTicket other = (LotteryTicket) obj; if (lotteryNumbers == null) { if (other.lotteryNumbers != null) { return false; } } else if (!lotteryNumbers.equals(other.lotteryNumbers)) { return false; } if (playerDetails == null) { if (other.playerDetails != null) { return false; } } else if (!playerDetails.equals(other.playerDetails)) { return false; } return true; } }
LotteryTicket { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } LotteryTicket other = (LotteryTicket) obj; if (lotteryNumbers == null) { if (other.lotteryNumbers != null) { return false; } } else if (!lotteryNumbers.equals(other.lotteryNumbers)) { return false; } if (playerDetails == null) { if (other.playerDetails != null) { return false; } } else if (!playerDetails.equals(other.playerDetails)) { return false; } return true; } LotteryTicket(LotteryTicketId id, PlayerDetails details, LotteryNumbers numbers); }
LotteryTicket { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } LotteryTicket other = (LotteryTicket) obj; if (lotteryNumbers == null) { if (other.lotteryNumbers != null) { return false; } } else if (!lotteryNumbers.equals(other.lotteryNumbers)) { return false; } if (playerDetails == null) { if (other.playerDetails != null) { return false; } } else if (!playerDetails.equals(other.playerDetails)) { return false; } return true; } LotteryTicket(LotteryTicketId id, PlayerDetails details, LotteryNumbers numbers); PlayerDetails getPlayerDetails(); LotteryNumbers getNumbers(); LotteryTicketId getId(); void setId(LotteryTicketId id); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
LotteryTicket { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } LotteryTicket other = (LotteryTicket) obj; if (lotteryNumbers == null) { if (other.lotteryNumbers != null) { return false; } } else if (!lotteryNumbers.equals(other.lotteryNumbers)) { return false; } if (playerDetails == null) { if (other.playerDetails != null) { return false; } } else if (!playerDetails.equals(other.playerDetails)) { return false; } return true; } LotteryTicket(LotteryTicketId id, PlayerDetails details, LotteryNumbers numbers); PlayerDetails getPlayerDetails(); LotteryNumbers getNumbers(); LotteryTicketId getId(); void setId(LotteryTicketId id); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }