protected PaginatedCollection<V> getPaginatedValuesFromReadables(Page page) throws Exception { PaginatedCollection<V> values = null; for (PaginatedReadableDataSource<K, V> readable : paginatedReadableDataSources) { values = readable.getPage(page); if (values != null && values.getItems() != null && !values.getItems().isEmpty()) { break; } } return values; }
private PaginatedCollection<AnyRepositoryValue> givenReadableDataSourceReturnsValues(Page page) throws Exception { PaginatedCollection<AnyRepositoryValue> values = getSomeValues(page); when(readableDataSource.getPage(page)).thenReturn(values); return values; }
@Test public void shouldReturnValuesFromReadableDataSourceIfCacheDoNotHaveThisPage() throws Exception { Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT); givenCacheDataSourceReturnsNonValidValues(page); givenReadableDataSourceReturnsValues(page); PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository(); repository.getPage(page); Page nextPage = Page.withOffsetAndLimit(ANY_OFFSET + ANY_LIMIT, ANY_LIMIT); repository.getPage(nextPage); verify(cacheDataSource).getPage(page); verify(readableDataSource).getPage(page); verify(cacheDataSource).getPage(nextPage); verify(readableDataSource).getPage(nextPage); }