use of com.nytimes.android.external.store3.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
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(barcode1, 1)).thenReturn(Single.just(true));
when(persister.write(barcode1, 2)).thenReturn(Single.just(true));
when(persister.read(barcode2)).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(barcode2, 1)).thenReturn(Single.just(true));
when(persister.write(barcode2, 2)).thenReturn(Single.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.store3.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(barCode -> Single.fromCallable(() -> networkCalls.incrementAndGet())).persister(persister).open();
}
use of com.nytimes.android.external.store3.base.impl.BarCode 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.BarCode 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.BarCode in project Store by NYTimes.
the class GetRefreshingTest method testRefreshOnClearAll.
@Test
public void testRefreshOnClearAll() {
BarCode barcode1 = new BarCode("type", "key");
BarCode barcode2 = new BarCode("type", "key2");
when(persister.read(barcode1)).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(barcode1, 1)).thenReturn(Single.just(true));
when(persister.write(barcode1, 2)).thenReturn(Single.just(true));
when(persister.read(barcode2)).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(barcode2, 1)).thenReturn(Single.just(true));
when(persister.write(barcode2, 2)).thenReturn(Single.just(true));
TestObserver<Integer> testObservable1 = store.getRefreshing(barcode1).test();
TestObserver<Integer> testObservable2 = store.getRefreshing(barcode2).test();
testObservable1.assertValueCount(1);
testObservable2.assertValueCount(1);
assertThat(networkCalls.intValue()).isEqualTo(2);
store.clear();
assertThat(networkCalls.intValue()).isEqualTo(4);
}
Aggregations