Search in sources :

Example 21 with AnyRepositoryValue

use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.

the class InMemoryCacheDataSourceTest method shouldReturnInvalidValuesIfTheTTLNoHasExpired.

@Test
public void shouldReturnInvalidValuesIfTheTTLNoHasExpired() throws Exception {
    CacheDataSource<AnyRepositoryKey, AnyRepositoryValue> cache = givenAnInMemoryCacheDataSource();
    List<AnyRepositoryValue> values = givenSomeValues(ANY_ITEMS_COUNT);
    cache.addOrUpdateAll(values);
    advanceTime(ANY_TTL - 1);
    AnyRepositoryValue value = cache.getByKey(ANY_KEY);
    assertTrue(cache.isValid(value));
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 22 with AnyRepositoryValue

use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.

the class InMemoryPaginatedCacheDataSourceTest method givenSomeItems.

private Collection<AnyRepositoryValue> givenSomeItems(int numberOfItems) {
    List<AnyRepositoryValue> values = new LinkedList<>();
    for (int i = 0; i < numberOfItems; 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 23 with AnyRepositoryValue

use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.

the class InMemoryPaginatedCacheDataSourceTest method shouldAddValuesBasedOnTheOffsetAndLimit.

@Test
public void shouldAddValuesBasedOnTheOffsetAndLimit() 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(values, paginatedCollection.getItems());
}
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 24 with AnyRepositoryValue

use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.

the class InMemoryPaginatedCacheDataSourceTest method shouldReturnRequestedLimit.

@Test
public void shouldReturnRequestedLimit() 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_LIMIT, paginatedCollection.getPage().getLimit());
}
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 25 with AnyRepositoryValue

use of com.karumi.rosie.doubles.AnyRepositoryValue in project Rosie by Karumi.

the class InMemoryPaginatedCacheDataSourceTest method shouldReturnTheRequestedOffset.

@Test
public void shouldReturnTheRequestedOffset() 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_OFFSET, paginatedCollection.getPage().getOffset());
}
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)

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