use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class ClearStoreMemoryTest method testClearAllBarCodes.
@Test
public void testClearAllBarCodes() {
BarCode b1 = new BarCode("type1", "key1");
BarCode b2 = new BarCode("type2", "key2");
//each request should produce one call
store.get(b1).test().awaitTerminalEvent();
store.get(b2).test().awaitTerminalEvent();
assertThat(networkCalls).isEqualTo(2);
store.clearMemory();
//after everything is cleared each request should produce another 2 calls
store.get(b1).test().awaitTerminalEvent();
store.get(b2).test().awaitTerminalEvent();
assertThat(networkCalls).isEqualTo(4);
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class ClearStoreTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(new Fetcher<Integer, BarCode>() {
@Nonnull
@Override
public Observable<Integer> fetch(@Nonnull BarCode barCode) {
return Observable.fromCallable(new Callable<Integer>() {
@Override
public Integer call() {
return networkCalls.incrementAndGet();
}
});
}
}).persister(persister).open();
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class ClearStoreTest method testClearAllBarCodes.
@Test
public void testClearAllBarCodes() {
BarCode barcode1 = new BarCode("type1", "key1");
BarCode barcode2 = new BarCode("type2", "key2");
when(persister.read(barcode1)).thenReturn(//read from disk
Observable.<Integer>empty()).thenReturn(//read from disk after fetching from network
Observable.just(1)).thenReturn(//read from disk after clearing disk cache
Observable.<Integer>empty()).thenReturn(//read from disk after making additional network call
Observable.just(1));
when(persister.write(barcode1, 1)).thenReturn(Observable.just(true));
when(persister.write(barcode1, 2)).thenReturn(Observable.just(true));
when(persister.read(barcode2)).thenReturn(//read from disk
Observable.<Integer>empty()).thenReturn(//read from disk after fetching from network
Observable.just(1)).thenReturn(//read from disk after clearing disk cache
Observable.<Integer>empty()).thenReturn(//read from disk after making additional network call
Observable.just(1));
when(persister.write(barcode2, 1)).thenReturn(Observable.just(true));
when(persister.write(barcode2, 2)).thenReturn(Observable.just(true));
// each request should produce one call
store.get(barcode1).test().awaitTerminalEvent();
store.get(barcode2).test().awaitTerminalEvent();
assertThat(networkCalls.intValue()).isEqualTo(2);
store.clear();
// after everything is cleared each request should produce another 2 calls
store.get(barcode1).test().awaitTerminalEvent();
store.get(barcode2).test().awaitTerminalEvent();
assertThat(networkCalls.intValue()).isEqualTo(4);
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class JacksonReaderParserStoreTest method testDefaultJacksonReaderParser.
@Test
public void testDefaultJacksonReaderParser() {
Parser<Reader, Foo> parser = JacksonParserFactory.createReaderParser(Foo.class);
Store<Foo, BarCode> store = StoreBuilder.<BarCode, Reader, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
Foo result = store.get(barCode).toBlocking().first();
validateFoo(result);
verify(fetcher, times(1)).fetch(barCode);
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class JacksonReaderParserStoreTest method testCustomJsonFactoryReaderParser.
@Test
public void testCustomJsonFactoryReaderParser() {
JsonFactory jsonFactory = new JsonFactory();
Parser<Reader, Foo> parser = JacksonParserFactory.createReaderParser(jsonFactory, Foo.class);
Store<Foo, BarCode> store = StoreBuilder.<BarCode, Reader, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
Foo result = store.get(barCode).toBlocking().first();
validateFoo(result);
verify(fetcher, times(1)).fetch(barCode);
}
Aggregations