use of com.nytimes.android.external.store.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
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(barcode, 1)).thenReturn(Observable.just(true));
when(persister.write(barcode, 2)).thenReturn(Observable.just(true));
AssertableSubscriber<Integer> refreshingObservable = store.getRefreshing(barcode).test();
assertThat(refreshingObservable.getValueCount()).isEqualTo(1);
assertThat(networkCalls.intValue()).isEqualTo(1);
//clearing the store should produce another network call
store.clear(barcode);
assertThat(refreshingObservable.getValueCount()).isEqualTo(2);
assertThat(networkCalls.intValue()).isEqualTo(2);
store.get(barcode).test().awaitTerminalEvent();
assertThat(refreshingObservable.getValueCount()).isEqualTo(2);
assertThat(networkCalls.intValue()).isEqualTo(2);
}
use of com.nytimes.android.external.store.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
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));
AssertableSubscriber<Integer> testObservable1 = store.getRefreshing(barcode1).test();
AssertableSubscriber<Integer> testObservable2 = store.getRefreshing(barcode2).test();
assertThat(testObservable1.getValueCount()).isEqualTo(1);
assertThat(testObservable2.getValueCount()).isEqualTo(1);
assertThat(networkCalls.intValue()).isEqualTo(2);
store.clear();
assertThat(networkCalls.intValue()).isEqualTo(4);
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class SequentialTest method sequentially.
@Test
public void sequentially() {
BarCode b = new BarCode("one", "two");
store.get(b).test().awaitTerminalEvent();
store.get(b).test().awaitTerminalEvent();
assertThat(networkCalls).isEqualTo(1);
}
use of com.nytimes.android.external.store.base.impl.BarCode in project Store by NYTimes.
the class StoreBuilderTest method testBuildersBuildWithCorrectTypes.
@Test
public void testBuildersBuildWithCorrectTypes() {
//test is checking whether types are correct in builders
Store<Date, Integer> store = StoreBuilder.<Integer, String, Date>parsedWithKey().fetcher(new Fetcher<String, Integer>() {
@Nonnull
@Override
public Observable<String> fetch(@Nonnull Integer key) {
return Observable.just(String.valueOf(key));
}
}).persister(new Persister<String, Integer>() {
@Nonnull
@Override
public Observable<String> read(@Nonnull Integer key) {
return Observable.just(String.valueOf(key));
}
@Nonnull
@Override
public Observable<Boolean> write(@Nonnull Integer key, @Nonnull String s) {
return Observable.empty();
}
}).parser(new Parser<String, Date>() {
@Override
public Date call(String s) {
return DATE;
}
}).open();
Store<Date, BarCode> barCodeStore = StoreBuilder.<Date>barcode().fetcher(new Fetcher<Date, BarCode>() {
@Nonnull
@Override
public Observable<Date> fetch(@Nonnull BarCode barCode) {
return Observable.just(DATE);
}
}).open();
Store<Date, Integer> keyStore = StoreBuilder.<Integer, Date>key().fetcher(new Fetcher<Date, Integer>() {
@Nonnull
@Override
public Observable<Date> fetch(@Nonnull Integer key) {
return Observable.just(DATE);
}
}).open();
Date result = store.get(5).toBlocking().first();
result = barCodeStore.get(new BarCode("test", "5")).toBlocking().first();
result = keyStore.get(5).toBlocking().first();
assertThat(result).isNotNull();
}
Aggregations