Source:
public void getCandidatesByFilterRequestShouldFindDummyCandidateDTOInAscendingOrderByNameWhenThereIsARightCandidateFilterRequest() { CandidateFilterRequest candidateFilterRequest = CandidateFilterRequest.builder().pageNumber(DEFAULT_PAGE_NUMBER).pageSize(DEFAULT_PAGE_SIZE) .sortName(SORT_NAME_NAME).sortOrder(SORT_ORDER_ASC).candidateName(NAME).build(); PageRequest pageRequest = new PageRequest(candidateFilterRequest.getPageNumber(), candidateFilterRequest.getPageSize(), Sort.Direction.fromString(candidateFilterRequest.getSortOrder()), candidateFilterRequest.getSortName()); String name = candidateFilterRequest.getCandidateName(); String email = candidateFilterRequest.getCandidateEmail(); String phone = candidateFilterRequest.getCandidatePhone(); String positions = candidateFilterRequest.getCandiadtePositions(); Page<CandidateEntity> dummyCandidateEntityPage = new PageImpl<>(Arrays.asList(dummyCandidateEntity)); List<CandidateDTO> dummyCandidateDTOs = Arrays.asList(dummyCandidateDto); given(candidateRepository .findByCandidateFilterRequest(name, email, phone, positions, pageRequest)) .willReturn(dummyCandidateEntityPage); given(converterService.convert(dummyCandidateEntityPage.getContent(), CandidateDTO.class)) .willReturn(dummyCandidateDTOs); PagingResponse<CandidateDTO> expectedPagingResponse = new PagingResponse<>(dummyCandidateEntityPage.getTotalElements(), dummyCandidateDTOs); PagingResponse<CandidateDTO> actualPagingResponse = candidateService.getCandidatesByFilterRequest(candidateFilterRequest); assertEquals(actualPagingResponse, expectedPagingResponse); then(converterService).should(times(1)) .convert(dummyCandidateEntityPage.getContent(), CandidateDTO.class); then(candidateRepository).should(times(1)) .findByCandidateFilterRequest(name, email, phone, positions, pageRequest); }

Target:
public void getCandidatesByFilterRequestShouldFindDummyCandidateDTOInAscendingOrderByNameWhenThereIsARightCandidateFilterRequest() { final CandidateFilterRequest candidateFilterRequest = CandidateFilterRequest.builder().pageNumber(DEFAULT_PAGE_NUMBER).pageSize(DEFAULT_PAGE_SIZE) .sortName(SORT_NAME_NAME).sortOrder(SORT_ORDER_ASC).candidateName(NAME).build(); final PageRequest pageRequest = new PageRequest(candidateFilterRequest.getPageNumber(), candidateFilterRequest.getPageSize(), Sort.Direction.fromString(candidateFilterRequest.getSortOrder()), candidateFilterRequest.getSortName()); final String name = candidateFilterRequest.getCandidateName(); final String email = StringUtils.EMPTY; final String phone = StringUtils.EMPTY; final String positions = StringUtils.EMPTY; final Page<CandidateEntity> dummyCandidateEntityPage = new PageImpl<>(Arrays.asList(dummyCandidateEntity)); final List<CandidateDTO> dummyCandidateDTOs = Arrays.asList(dummyCandidateDto); given(candidateRepository .findByCandidateFilterRequest(name, email, phone, positions, pageRequest)) .willReturn(dummyCandidateEntityPage); given(converterService.convert(dummyCandidateEntityPage.getContent(), CandidateDTO.class)) .willReturn(dummyCandidateDTOs); final PagingResponse<CandidateDTO> expectedPagingResponse = new PagingResponse<>(dummyCandidateEntityPage.getTotalElements(), dummyCandidateDTOs); final PagingResponse<CandidateDTO> actualPagingResponse = candidateService.getCandidatesByFilterRequest(candidateFilterRequest); assertEquals(actualPagingResponse, expectedPagingResponse); then(converterService).should(times(1)) .convert(dummyCandidateEntityPage.getContent(), CandidateDTO.class); then(candidateRepository).should(times(1)) .findByCandidateFilterRequest(name, email, phone, positions, pageRequest); }