CandidateValidatorHelper { public boolean isValidNonExistingCandidate(CandidateDTO candidateDTO) { this.preValidateNonExistingCandidate(candidateDTO); CandidateDTO candidateDTOByEmail = this.candidateService.getCandidateDtoByEmail(candidateDTO.getEmail()); CandidateDTO candidateDTOByPhone = this.candidateService.getCandidateDtoByPhone(candidateDTO.getPhone()); if (candidateDTOByEmail == null && candidateDTOByPhone == null) { return true; } return false; }  boolean isValidNonExistingCandidate(CandidateDTO candidateDTO); boolean isValidExistingCandidate(CandidateDTO candidateDTO);  }
@Test(expected = IllegalArgumentException.class) public void isValidNonExistingCandidateShouldThrowIllegalArgumentExceptionWhenCandidateIsNull() { this.candidateValidatorHelper.isValidNonExistingCandidate(null); }
@Test(expected = IllegalArgumentException.class) public void isValidNonExistingCandidateShouldThrowIllegalArgumentExceptionWhenCandidateEmailIsNull() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().email(null).phone(CANDIDATE_NEW_PHONE).build(); this.candidateValidatorHelper.isValidNonExistingCandidate(actualCandidateDto); }
@Test(expected = IllegalArgumentException.class) public void isValidNonExistingCandidateShouldThrowIllegalArgumentExceptionWhenCandidatePhoneIsNull() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().email(CANDIDATE_NEW_EMAIL).phone(null).build(); this.candidateValidatorHelper.isValidNonExistingCandidate(actualCandidateDto); }
@Test public void isValidNonExistingCandidateShouldReturnFalseWhenEmailAlreadyExists() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().email(CANDIDATE_A_EMAIL).phone(CANDIDATE_NEW_PHONE).build(); final CandidateDTO candidateDtoWithEmail = CandidateDTO.builder().email(CANDIDATE_A_EMAIL).phone(CANDIDATE_A_PHONE).build(); given(this.candidateService.getCandidateDtoByEmail(CANDIDATE_A_EMAIL)) .willReturn(candidateDtoWithEmail); given(this.candidateService.getCandidateDtoByPhone(CANDIDATE_NEW_PHONE)).willReturn(null); boolean result = this.candidateValidatorHelper.isValidNonExistingCandidate(actualCandidateDto); assertThat(result, is(false)); then(this.candidateService.getCandidateDtoByEmail(CANDIDATE_A_EMAIL)); then(this.candidateService.getCandidateDtoByPhone(CANDIDATE_NEW_PHONE)); }
@Test public void isValidNonExistingCandidateShouldReturnFalseWhenPhoneAlreadyExists() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().email(CANDIDATE_NEW_EMAIL).phone(CANDIDATE_A_PHONE).build(); final CandidateDTO candidateDtoWithPhone = CandidateDTO.builder().email(CANDIDATE_A_EMAIL).phone(CANDIDATE_A_PHONE).build(); given(this.candidateService.getCandidateDtoByEmail(CANDIDATE_NEW_EMAIL)).willReturn(null); given(this.candidateService.getCandidateDtoByPhone(CANDIDATE_A_PHONE)) .willReturn(candidateDtoWithPhone); boolean result = this.candidateValidatorHelper.isValidNonExistingCandidate(actualCandidateDto); assertThat(result, is(false)); then(this.candidateService.getCandidateDtoByEmail(CANDIDATE_NEW_EMAIL)); then(this.candidateService.getCandidateDtoByPhone(CANDIDATE_A_PHONE)); }
@Test public void isValidNonExistingCandidateShouldReturnTrueWhenEmailAndPhoneNotExist() { final CandidateDTO actualCandidateDto = CandidateDTO.builder().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(null); boolean result = this.candidateValidatorHelper.isValidNonExistingCandidate(actualCandidateDto); assertThat(result, is(true)); then(this.candidateService.getCandidateDtoByEmail(CANDIDATE_NEW_EMAIL)); then(this.candidateService.getCandidateDtoByPhone(CANDIDATE_NEW_PHONE)); }