Search in sources :

Example 11 with AnyRepositoryValue

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;
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) LinkedList(java.util.LinkedList)

Example 12 with AnyRepositoryValue

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());
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 13 with AnyRepositoryValue

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);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 14 with AnyRepositoryValue

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);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) Page(com.karumi.rosie.repository.datasource.paginated.Page) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 15 with AnyRepositoryValue

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;
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) LinkedList(java.util.LinkedList)

Aggregations

AnyRepositoryValue (com.karumi.rosie.doubles.AnyRepositoryValue)25 AnyRepositoryKey (com.karumi.rosie.doubles.AnyRepositoryKey)21 Test (org.junit.Test)19 Page (com.karumi.rosie.repository.datasource.paginated.Page)12 LinkedList (java.util.LinkedList)3 NonNull (android.support.annotation.NonNull)2