use of com.karumi.rosie.doubles.AnyRepositoryKey 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.AnyRepositoryKey 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.AnyRepositoryKey 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));
}
use of com.karumi.rosie.doubles.AnyRepositoryKey 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.AnyRepositoryKey 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());
}
Aggregations