@Test public void equalsReturnsFalseForDifferentId() { long applicationId = 1; long otherApplicationId = 2; var userId = "user"; var comment = "This is a comment!"; var date = LocalDateTime.now(); given(userMock.getId()).willReturn(userId); var application = new ProjectApplication(projectMock, comment, userMock, date); application.id = applicationId; var otherApplication = new ProjectApplication(projectMock, comment, userMock, date); otherApplication.id = otherApplicationId; boolean actualEquals = application.equals(otherApplication); assertThat(actualEquals).isFalse(); }
@Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof ProjectApplication) { ProjectApplication other = (ProjectApplication) obj; boolean userEquals = Objects.nonNull(this.user) && Objects.nonNull(other.user) && Objects.equals(this.user.getId(), other.user.getId()); return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.comment, other.comment) && Objects.equals(this.project, other.project) && Objects.equals(this.applicationDate, other.applicationDate); } return false; }
ProjectApplication { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof ProjectApplication) { ProjectApplication other = (ProjectApplication) obj; boolean userEquals = Objects.nonNull(this.user) && Objects.nonNull(other.user) && Objects.equals(this.user.getId(), other.user.getId()); return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.comment, other.comment) && Objects.equals(this.project, other.project) && Objects.equals(this.applicationDate, other.applicationDate); } return false; } }
ProjectApplication { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof ProjectApplication) { ProjectApplication other = (ProjectApplication) obj; boolean userEquals = Objects.nonNull(this.user) && Objects.nonNull(other.user) && Objects.equals(this.user.getId(), other.user.getId()); return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.comment, other.comment) && Objects.equals(this.project, other.project) && Objects.equals(this.applicationDate, other.applicationDate); } return false; } ProjectApplication(Project project, String comment, User user, LocalDateTime applicationDate); }
ProjectApplication { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof ProjectApplication) { ProjectApplication other = (ProjectApplication) obj; boolean userEquals = Objects.nonNull(this.user) && Objects.nonNull(other.user) && Objects.equals(this.user.getId(), other.user.getId()); return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.comment, other.comment) && Objects.equals(this.project, other.project) && Objects.equals(this.applicationDate, other.applicationDate); } return false; } ProjectApplication(Project project, String comment, User user, LocalDateTime applicationDate); @Override boolean equals(Object obj); @Override int hashCode(); }
ProjectApplication { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(obj instanceof ProjectApplication) { ProjectApplication other = (ProjectApplication) obj; boolean userEquals = Objects.nonNull(this.user) && Objects.nonNull(other.user) && Objects.equals(this.user.getId(), other.user.getId()); return userEquals && Objects.equals(this.id, other.id) && Objects.equals(this.comment, other.comment) && Objects.equals(this.project, other.project) && Objects.equals(this.applicationDate, other.applicationDate); } return false; } ProjectApplication(Project project, String comment, User user, LocalDateTime applicationDate); @Override boolean equals(Object obj); @Override int hashCode();  }