@Test public void findBySearchTerm_NoTodoEntriesFound_ShouldReturnEmptyList() { Page<Todo> page = new PageBuilder<Todo>() .pageNumber(PAGE_NUMBER) .pageSize(PAGE_SIZE) .sort(SORT) .build(); when(repositoryMock.findBySearchTerm(SEARCH_TERM, pageRequest)).thenReturn(page); Page<TodoDTO> searchResults = service.findBySearchTerm(SEARCH_TERM, pageRequest); verify(repositoryMock, times(1)).findBySearchTerm(SEARCH_TERM, pageRequest); verifyNoMoreInteractions(repositoryMock); assertThatPage(searchResults) .isFirstPage() .isLastPage() .hasPageNumber(PAGE_NUMBER) .hasPageSize(PAGE_SIZE) .hasSort(SORT) .hasTotalNumberOfElements(ZERO_ELEMENTS) .hasTotalNumberOfPages(ZERO_PAGES) .isEmpty(); }
@Transactional(readOnly = true) @Override public Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable) { LOGGER.info("Finding {} todo entries for page {} by using search term: {}", pageable.getPageSize(), pageable.getPageNumber(), searchTerm ); Page<Todo> searchResults = repository.findBySearchTerm(searchTerm, pageable); LOGGER.info("Found {} todo entries for page: {}", searchResults.getNumberOfElements(), searchResults.getNumber() ); List<TodoDTO> dtos = transformer.convertList(searchResults.getContent(), TodoDTO.class); return new PageImpl<>(dtos, new PageRequest(searchResults.getNumber(), searchResults.getSize(), searchResults.getSort()), searchResults.getTotalElements() ); }
RepositoryTodoSearchService implements TodoSearchService { @Transactional(readOnly = true) @Override public Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable) { LOGGER.info("Finding {} todo entries for page {} by using search term: {}", pageable.getPageSize(), pageable.getPageNumber(), searchTerm ); Page<Todo> searchResults = repository.findBySearchTerm(searchTerm, pageable); LOGGER.info("Found {} todo entries for page: {}", searchResults.getNumberOfElements(), searchResults.getNumber() ); List<TodoDTO> dtos = transformer.convertList(searchResults.getContent(), TodoDTO.class); return new PageImpl<>(dtos, new PageRequest(searchResults.getNumber(), searchResults.getSize(), searchResults.getSort()), searchResults.getTotalElements() ); } }
RepositoryTodoSearchService implements TodoSearchService { @Transactional(readOnly = true) @Override public Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable) { LOGGER.info("Finding {} todo entries for page {} by using search term: {}", pageable.getPageSize(), pageable.getPageNumber(), searchTerm ); Page<Todo> searchResults = repository.findBySearchTerm(searchTerm, pageable); LOGGER.info("Found {} todo entries for page: {}", searchResults.getNumberOfElements(), searchResults.getNumber() ); List<TodoDTO> dtos = transformer.convertList(searchResults.getContent(), TodoDTO.class); return new PageImpl<>(dtos, new PageRequest(searchResults.getNumber(), searchResults.getSize(), searchResults.getSort()), searchResults.getTotalElements() ); } @Autowired  RepositoryTodoSearchService(TodoRepository repository, JTransfo transformer); }
RepositoryTodoSearchService implements TodoSearchService { @Transactional(readOnly = true) @Override public Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable) { LOGGER.info("Finding {} todo entries for page {} by using search term: {}", pageable.getPageSize(), pageable.getPageNumber(), searchTerm ); Page<Todo> searchResults = repository.findBySearchTerm(searchTerm, pageable); LOGGER.info("Found {} todo entries for page: {}", searchResults.getNumberOfElements(), searchResults.getNumber() ); List<TodoDTO> dtos = transformer.convertList(searchResults.getContent(), TodoDTO.class); return new PageImpl<>(dtos, new PageRequest(searchResults.getNumber(), searchResults.getSize(), searchResults.getSort()), searchResults.getTotalElements() ); } @Autowired  RepositoryTodoSearchService(TodoRepository repository, JTransfo transformer); @Transactional(readOnly = true) @Override Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable); }
RepositoryTodoSearchService implements TodoSearchService { @Transactional(readOnly = true) @Override public Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable) { LOGGER.info("Finding {} todo entries for page {} by using search term: {}", pageable.getPageSize(), pageable.getPageNumber(), searchTerm ); Page<Todo> searchResults = repository.findBySearchTerm(searchTerm, pageable); LOGGER.info("Found {} todo entries for page: {}", searchResults.getNumberOfElements(), searchResults.getNumber() ); List<TodoDTO> dtos = transformer.convertList(searchResults.getContent(), TodoDTO.class); return new PageImpl<>(dtos, new PageRequest(searchResults.getNumber(), searchResults.getSize(), searchResults.getSort()), searchResults.getTotalElements() ); } @Autowired  RepositoryTodoSearchService(TodoRepository repository, JTransfo transformer); @Transactional(readOnly = true) @Override Page<TodoDTO> findBySearchTerm(String searchTerm, Pageable pageable);  }