Search in sources :

Example 6 with AnyRepositoryValue

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

the class RosieRepositoryTest method shouldReturnValueByKeyFromCacheDataSource.

@Test
public void shouldReturnValueByKeyFromCacheDataSource() throws Exception {
    givenReadableDataSourceReturnsNull();
    AnyRepositoryValue cacheValue = givenCacheDataSourceReturnsValidValueWithKey(ANY_KEY);
    RosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAReadableAndCacheRepository();
    AnyRepositoryValue value = repository.getByKey(ANY_KEY);
    Assert.assertEquals(cacheValue, value);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 7 with AnyRepositoryValue

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

the class RosieRepositoryTest method givenReadableDataSourceReturnsValidValueWithKey.

@NonNull
private AnyRepositoryValue givenReadableDataSourceReturnsValidValueWithKey(AnyRepositoryKey key) throws Exception {
    AnyRepositoryValue value = new AnyRepositoryValue(key);
    when(readableDataSource.getByKey(key)).thenReturn(value);
    return value;
}
Also used : AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) NonNull(android.support.annotation.NonNull)

Example 8 with AnyRepositoryValue

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

the class RosieRepositoryTest method shouldReturnValueFromReadableDataSourceIfCacheDataSourceValueIsNull.

@Test
public void shouldReturnValueFromReadableDataSourceIfCacheDataSourceValueIsNull() throws Exception {
    givenCacheDataSourceReturnsNull();
    AnyRepositoryValue readableValue = givenReadableDataSourceReturnsValidValueWithKey(ANY_KEY);
    RosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAReadableAndCacheRepository();
    AnyRepositoryValue value = repository.getByKey(ANY_KEY);
    Assert.assertEquals(readableValue, value);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 9 with AnyRepositoryValue

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

the class RosieRepositoryTest method shouldPopulateCacheDataSourceWithValueIfCacheDataSourceIsNotValid.

@Test
public void shouldPopulateCacheDataSourceWithValueIfCacheDataSourceIsNotValid() throws Exception {
    givenCacheDataSourceReturnsNonValidValueWithKey(ANY_KEY);
    AnyRepositoryValue readableValue = givenReadableDataSourceReturnsValidValueWithKey(ANY_KEY);
    RosieRepository<AnyRepositoryKey, AnyRepositoryValue> repository = givenAReadableAndCacheRepository();
    repository.getByKey(ANY_KEY);
    verify(cacheDataSource).addOrUpdate(readableValue);
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) AnyRepositoryValue(com.karumi.rosie.doubles.AnyRepositoryValue) Test(org.junit.Test)

Example 10 with AnyRepositoryValue

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

the class InMemoryCacheDataSourceTest method shouldReturnInvalidValuesIfTheTTLHasExpired.

@Test
public void shouldReturnInvalidValuesIfTheTTLHasExpired() 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);
    assertFalse(cache.isValid(value));
}
Also used : AnyRepositoryKey(com.karumi.rosie.doubles.AnyRepositoryKey) 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