@Test void searchTest() { SearchNewsDto searchNewsDto = new SearchNewsDto(1L, "title", null, null, Collections.singletonList("tag")); PageableDto<SearchNewsDto> ecoNews = new PageableDto<>(Collections.singletonList(searchNewsDto), 4, 1,1); SearchTipsAndTricksDto searchTipsAndTricksDto = new SearchTipsAndTricksDto(1L, "title", null, null, Collections.singletonList("tips_tag")); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = new PageableDto<>(Collections.singletonList(searchTipsAndTricksDto), 4, 1,1); when(ecoNewsService.search(anyString())).thenReturn(ecoNews); when(tipsAndTricksService.search(anyString())).thenReturn(tipsAndTricks); assertEquals(ecoNews.getPage(), searchService.search("tag").getEcoNews()); assertEquals(tipsAndTricks.getPage(), searchService.search("tag").getTipsAndTricks()); assertEquals(Long.valueOf(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()), searchService.search("tag").getCountOfResults()); }
@Override public SearchResponseDto search(String searchQuery) { PageableDto<SearchNewsDto> ecoNews = ecoNewsService.search(searchQuery); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = tipsAndTricksService.search(searchQuery); return SearchResponseDto.builder() .ecoNews(ecoNews.getPage()) .tipsAndTricks(tipsAndTricks.getPage()) .countOfResults(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()) .build(); }
SearchServiceImpl implements SearchService { @Override public SearchResponseDto search(String searchQuery) { PageableDto<SearchNewsDto> ecoNews = ecoNewsService.search(searchQuery); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = tipsAndTricksService.search(searchQuery); return SearchResponseDto.builder() .ecoNews(ecoNews.getPage()) .tipsAndTricks(tipsAndTricks.getPage()) .countOfResults(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()) .build(); } }
SearchServiceImpl implements SearchService { @Override public SearchResponseDto search(String searchQuery) { PageableDto<SearchNewsDto> ecoNews = ecoNewsService.search(searchQuery); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = tipsAndTricksService.search(searchQuery); return SearchResponseDto.builder() .ecoNews(ecoNews.getPage()) .tipsAndTricks(tipsAndTricks.getPage()) .countOfResults(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()) .build(); }  }
SearchServiceImpl implements SearchService { @Override public SearchResponseDto search(String searchQuery) { PageableDto<SearchNewsDto> ecoNews = ecoNewsService.search(searchQuery); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = tipsAndTricksService.search(searchQuery); return SearchResponseDto.builder() .ecoNews(ecoNews.getPage()) .tipsAndTricks(tipsAndTricks.getPage()) .countOfResults(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()) .build(); }  @Override SearchResponseDto search(String searchQuery); }
SearchServiceImpl implements SearchService { @Override public SearchResponseDto search(String searchQuery) { PageableDto<SearchNewsDto> ecoNews = ecoNewsService.search(searchQuery); PageableDto<SearchTipsAndTricksDto> tipsAndTricks = tipsAndTricksService.search(searchQuery); return SearchResponseDto.builder() .ecoNews(ecoNews.getPage()) .tipsAndTricks(tipsAndTricks.getPage()) .countOfResults(ecoNews.getTotalElements() + tipsAndTricks.getTotalElements()) .build(); }  @Override SearchResponseDto search(String searchQuery);  }