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