use of org.mockito.internal.stubbing.answers.ReturnsElementsOf in project nem2-sdk-java by nemtech.
the class PaginationStreamerTester method runSearch.
private void runSearch(int pageSize, int totalEntries, Integer limit) {
try {
criteria.setPageSize(pageSize);
List<E> infos = IntStream.range(0, totalEntries).mapToObj((i) -> Mockito.mock(entityClass)).collect(Collectors.toList());
Assertions.assertEquals(totalEntries, infos.size());
List<Observable<Page<E>>> pages = toPages(infos, criteria.getPageSize());
Mockito.when(repository.search(Mockito.eq(criteria))).thenAnswer(new ReturnsElementsOf(pages));
Observable<E> search = streamer.search(criteria);
if (limit != null) {
search = search.take(limit);
}
List<E> returnedInfos = search.toList().toFuture().get();
Assertions.assertEquals(infos.subList(0, limit == null ? infos.size() : limit), returnedInfos);
int totalPagesRead = limit == null ? pages.size() : (int) Math.ceil(limit.doubleValue() / pageSize);
Mockito.verify(repository, Mockito.times(totalPagesRead)).search(Mockito.eq(criteria));
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
Aggregations