@Test public void isValidExistingCandidateShouldReturnTrueWhenEmailNotExistsAndPhoneNotBeenUpdated() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().id(CANDIDATE_NEW_ID).email(CANDIDATE_NEW_EMAIL) .phone(CANDIDATE_NEW_PHONE).build(); given(this.candidateService.getCandidateDtoByEmail(CANDIDATE_NEW_EMAIL)) .willReturn(null); given(this.candidateService.getCandidateDtoByPhone(CANDIDATE_NEW_PHONE)) .willReturn(actualCandidateDto); boolean result = this.candidateValidatorHelper.isValidExistingCandidate(actualCandidateDto); assertThat(result, is(true)); then(this.candidateService).should().getCandidateDtoByEmail(CANDIDATE_NEW_EMAIL); then(this.candidateService).should().getCandidateDtoByPhone(CANDIDATE_NEW_PHONE); }
public boolean isValidExistingCandidate(CandidateDTO candidateDTO) { this.preValidateExistingCandidate(candidateDTO); Long candidateId = candidateDTO.getId(); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if ((candidateDTOByEmail == null || candidateDTOByEmail.getId().equals(candidateId)) && (candidateDTOByPhone == null || candidateDTOByPhone.getId().equals(candidateId))) { return true; } return false; }
CandidateValidatorHelper { public boolean isValidExistingCandidate(CandidateDTO candidateDTO) { this.preValidateExistingCandidate(candidateDTO); Long candidateId = candidateDTO.getId(); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if ((candidateDTOByEmail == null || candidateDTOByEmail.getId().equals(candidateId)) && (candidateDTOByPhone == null || candidateDTOByPhone.getId().equals(candidateId))) { return true; } return false; } }
CandidateValidatorHelper { public boolean isValidExistingCandidate(CandidateDTO candidateDTO) { this.preValidateExistingCandidate(candidateDTO); Long candidateId = candidateDTO.getId(); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if ((candidateDTOByEmail == null || candidateDTOByEmail.getId().equals(candidateId)) && (candidateDTOByPhone == null || candidateDTOByPhone.getId().equals(candidateId))) { return true; } return false; }  }
CandidateValidatorHelper { public boolean isValidExistingCandidate(CandidateDTO candidateDTO) { this.preValidateExistingCandidate(candidateDTO); Long candidateId = candidateDTO.getId(); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if ((candidateDTOByEmail == null || candidateDTOByEmail.getId().equals(candidateId)) && (candidateDTOByPhone == null || candidateDTOByPhone.getId().equals(candidateId))) { return true; } return false; }  boolean isValidNonExistingCandidate(CandidateDTO candidateDTO); boolean isValidExistingCandidate(CandidateDTO candidateDTO); }
CandidateValidatorHelper { public boolean isValidExistingCandidate(CandidateDTO candidateDTO) { this.preValidateExistingCandidate(candidateDTO); Long candidateId = candidateDTO.getId(); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if ((candidateDTOByEmail == null || candidateDTOByEmail.getId().equals(candidateId)) && (candidateDTOByPhone == null || candidateDTOByPhone.getId().equals(candidateId))) { return true; } return false; }  boolean isValidNonExistingCandidate(CandidateDTO candidateDTO); boolean isValidExistingCandidate(CandidateDTO candidateDTO);  }