use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.
the class InMemoryCacheDataSourceTest method givenSomeValues.
private List<AnyRepositoryValue> givenSomeValues(int itemsCount) {
List<AnyRepositoryValue> values = new LinkedList<>();
for (int i = 0; i < itemsCount; i++) {
AnyRepositoryValue value = new AnyRepositoryValue(new AnyRepositoryKey(i));
values.add(value);
}
return values;
}
use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.
the class InMemoryPaginatedCacheDataSourceTest method shouldReturnHasMoreIfThereAreMoreItemsToLoad.
@Test
public void shouldReturnHasMoreIfThereAreMoreItemsToLoad() throws Exception {
Page page = Page.withOffsetAndLimit(ANY_OFFSET, ANY_LIMIT);
Collection<AnyRepositoryValue> values = givenSomeItems(ANY_OFFSET + ANY_LIMIT);
PaginatedCacheDataSource<AnyRepositoryKey, AnyRepositoryValue> cache = givenAnInMemoryPaginatedCacheDataSource();
cache.addOrUpdatePage(page, values, ANY_HAS_MORE);
PaginatedCollection<AnyRepositoryValue> paginatedCollection = cache.getPage(page);
assertEquals(ANY_HAS_MORE, paginatedCollection.hasMore());
}
use of com.karumi.rosie.doubles.AnyRepositoryValue 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.AnyRepositoryValue 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.AnyRepositoryValue 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;
}
Aggregations