use of com.nytimes.android.external.store3.base.impl.Store in project Store by NYTimes.
the class ClearStoreTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(barCode -> Single.fromCallable(() -> networkCalls.incrementAndGet())).persister(persister).open();
}
use of com.nytimes.android.external.store3.base.impl.Store in project Store by NYTimes.
the class GetRefreshingTest method testRefreshOnClear.
@Test
public void testRefreshOnClear() {
BarCode barcode = new BarCode("type", "key");
when(persister.read(barcode)).thenReturn(// read from disk
Maybe.<Integer>empty()).thenReturn(// read from disk after fetching from network
Maybe.just(1)).thenReturn(// read from disk after clearing disk cache
Maybe.<Integer>empty()).thenReturn(// read from disk after making additional network call
Maybe.just(1));
when(persister.write(barcode, 1)).thenReturn(Single.just(true));
when(persister.write(barcode, 2)).thenReturn(Single.just(true));
TestObserver<Integer> refreshingObservable = store.getRefreshing(barcode).test();
refreshingObservable.assertValueCount(1);
assertThat(networkCalls.intValue()).isEqualTo(1);
// clearing the store should produce another network call
store.clear(barcode);
refreshingObservable.assertValueCount(2);
assertThat(networkCalls.intValue()).isEqualTo(2);
store.get(barcode).test().awaitTerminalEvent();
refreshingObservable.assertValueCount(2);
assertThat(networkCalls.intValue()).isEqualTo(2);
}
use of com.nytimes.android.external.store3.base.impl.Store in project Store by NYTimes.
the class GetRefreshingTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(barCode -> Single.fromCallable(() -> networkCalls.incrementAndGet())).persister(persister).open();
}
use of com.nytimes.android.external.store3.base.impl.Store in project Store by NYTimes.
the class NoopPersisterTest method testReadingOfMemoryPolicies.
// https://github.com/NYTimes/Store/issues/312
@Test
public void testReadingOfMemoryPolicies() {
MemoryPolicy expireAfterWritePolicy = MemoryPolicy.builder().setExpireAfterWrite(1).setExpireAfterTimeUnit(TimeUnit.HOURS).build();
NoopPersister.create(expireAfterWritePolicy);
MemoryPolicy expireAfterAccessPolicy = MemoryPolicy.builder().setExpireAfterAccess(1).setExpireAfterTimeUnit(TimeUnit.HOURS).build();
NoopPersister.create(expireAfterAccessPolicy);
exception.expect(IllegalArgumentException.class);
exception.expectMessage("No expiry policy set");
MemoryPolicy incompletePolicy = MemoryPolicy.builder().setExpireAfterTimeUnit(TimeUnit.HOURS).build();
NoopPersister.create(incompletePolicy);
}
use of com.nytimes.android.external.store3.base.impl.Store in project Store by NYTimes.
the class SourceFilerReaderWriterStoreTest method testSimple.
@Test
public void testSimple() {
MockitoAnnotations.initMocks(this);
GsonSourceParser<Foo> parser = new GsonSourceParser<>(new Gson(), Foo.class);
Store<Foo, BarCode> simpleStore = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(fileReader, fileWriter).fetcher(fetcher).parser(parser).open();
Foo foo = new Foo();
foo.bar = barCode.getKey();
String sourceData = new Gson().toJson(foo);
BufferedSource source = source(sourceData);
Single<BufferedSource> value = Single.just(source);
when(fetcher.fetch(barCode)).thenReturn(value);
when(fileReader.read(barCode)).thenReturn(Maybe.<BufferedSource>empty()).thenReturn(value.toMaybe());
when(fileWriter.write(barCode, source)).thenReturn(Single.just(true));
Foo result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
verify(fetcher, times(1)).fetch(barCode);
}
Aggregations