@Test public void equalsReturnsTrueForSameInstance() { var accessIntervalId = 1L; var startTime = LocalDateTime.now(clock); var endTime = LocalDateTime.now(clock).plus(1L, ChronoUnit.DAYS); var accessInterval = new AccessInterval(userMock, startTime, endTime); accessInterval.id = accessIntervalId; boolean actualEquals = accessInterval.equals(accessInterval); assertThat(actualEquals).isTrue(); }
@Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof AccessInterval) { AccessInterval other = (AccessInterval) obj; boolean userEquals; if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) { userEquals = Objects.equals(this.user.getId(), other.user.getId()); } else { userEquals = Objects.isNull(this.user) && Objects.isNull(other.user); } return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.endTime, other.endTime); } return false; }
AccessInterval { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof AccessInterval) { AccessInterval other = (AccessInterval) obj; boolean userEquals; if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) { userEquals = Objects.equals(this.user.getId(), other.user.getId()); } else { userEquals = Objects.isNull(this.user) && Objects.isNull(other.user); } return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.endTime, other.endTime); } return false; } }
AccessInterval { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof AccessInterval) { AccessInterval other = (AccessInterval) obj; boolean userEquals; if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) { userEquals = Objects.equals(this.user.getId(), other.user.getId()); } else { userEquals = Objects.isNull(this.user) && Objects.isNull(other.user); } return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.endTime, other.endTime); } return false; } AccessInterval(User user, LocalDateTime startTime, LocalDateTime endTime); }
AccessInterval { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof AccessInterval) { AccessInterval other = (AccessInterval) obj; boolean userEquals; if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) { userEquals = Objects.equals(this.user.getId(), other.user.getId()); } else { userEquals = Objects.isNull(this.user) && Objects.isNull(other.user); } return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.endTime, other.endTime); } return false; } AccessInterval(User user, LocalDateTime startTime, LocalDateTime endTime); @Override boolean equals(Object obj); @Override int hashCode(); }
AccessInterval { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof AccessInterval) { AccessInterval other = (AccessInterval) obj; boolean userEquals; if(Objects.nonNull(this.user) && Objects.nonNull(other.user)) { userEquals = Objects.equals(this.user.getId(), other.user.getId()); } else { userEquals = Objects.isNull(this.user) && Objects.isNull(other.user); } return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.startTime, other.startTime) && Objects.equals(this.endTime, other.endTime); } return false; } AccessInterval(User user, LocalDateTime startTime, LocalDateTime endTime); @Override boolean equals(Object obj); @Override int hashCode();  }