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);
}
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;
}
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);
}
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);
}
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));
}
Aggregations