use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.
the class PaginatedRosieRepositoryTest method shouldPopulateCacheDataSourceAfterGetPageFromReadableDataSource.
@Test
public void shouldPopulateCacheDataSourceAfterGetPageFromReadableDataSource() throws Exception {
Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
givenCacheDataSourceReturnsNull(page);
PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
repository.getPage(page);
verify(cacheDataSource).addOrUpdatePage(page, readableValues.getItems(), true);
}
use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.
the class PaginatedRosieRepositoryTest method shouldReturnValuesFromReadableDataSourceIfPolicyForcesOnlyReadable.
@Test
public void shouldReturnValuesFromReadableDataSourceIfPolicyForcesOnlyReadable() throws Exception {
Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
givenCacheDataSourceReturnsValidValues(page);
PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
PaginatedCollection<AnyRepositoryValue> values = repository.getPage(page, ReadPolicy.READABLE_ONLY);
assertEquals(readableValues, values);
}
use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.
the class PaginatedRosieRepositoryTest method getSomeValues.
private PaginatedCollection<AnyRepositoryValue> getSomeValues(Page page) {
LinkedList<AnyRepositoryValue> values = new LinkedList<>();
for (int i = 0; i < 10; i++) {
values.add(new AnyRepositoryValue(new AnyRepositoryKey(i)));
}
PaginatedCollection<AnyRepositoryValue> paginatedValues = new PaginatedCollection<>(values);
paginatedValues.setHasMore(true);
paginatedValues.setPage(page);
return paginatedValues;
}
use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.
the class PaginatedRosieRepositoryTest method shouldReturnValuesFromReadableDataSourceIfCacheDataSourceIsNotValid.
@Test
public void shouldReturnValuesFromReadableDataSourceIfCacheDataSourceIsNotValid() throws Exception {
Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
givenCacheDataSourceReturnsNonValidValues(page);
PaginatedCollection<AnyRepositoryValue> readableValues = givenReadableDataSourceReturnsValues(page);
PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
PaginatedCollection<AnyRepositoryValue> values = repository.getPage(page);
assertEquals(readableValues, values);
}
use of com.karumi.rosie.doubles.AnyRepositoryKey in project Rosie by Karumi.
the class PaginatedRosieRepositoryTest method shouldDeleteCacheDataIfItemsAreNotValid.
@Test
public void shouldDeleteCacheDataIfItemsAreNotValid() throws Exception {
Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
givenCacheDataSourceReturnsNonValidValues(page);
PaginatedRosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAPaginatedRepository();
repository.getPage(page);
verify(cacheDataSource).deleteAll();
}
Aggregations