use of com.nytimes.android.external.store3.base.impl.BarCode in project Store by NYTimes.
the class DontCacheErrorsTest method testStoreDoesntCacheErrorsWithResult.
@Test
public void testStoreDoesntCacheErrorsWithResult() throws InterruptedException {
BarCode barcode = new BarCode("bar", "code");
shouldThrow = true;
store.getWithResult(barcode).test().assertTerminated().assertError(Exception.class).awaitTerminalEvent();
shouldThrow = false;
store.get(barcode).test().assertNoErrors().awaitTerminalEvent();
}
use of com.nytimes.android.external.store3.base.impl.BarCode in project Store by NYTimes.
the class SequentialTest method parallel.
@Test
public void parallel() {
BarCode b = new BarCode("one", "two");
Single<Integer> first = store.get(b);
Single<Integer> second = store.get(b);
first.test().awaitTerminalEvent();
second.test().awaitTerminalEvent();
assertThat(networkCalls).isEqualTo(1);
}
use of com.nytimes.android.external.store3.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(key -> Single.just(String.valueOf(key))).persister(new Persister<String, Integer>() {
@Nonnull
@Override
public Maybe<String> read(@Nonnull Integer key) {
return Maybe.just(String.valueOf(key));
}
@Nonnull
@Override
public Single<Boolean> write(@Nonnull Integer key, @Nonnull String s) {
return Single.just(true);
}
}).parser(s -> DATE).open();
Store<Date, BarCode> barCodeStore = StoreBuilder.<Date>barcode().fetcher(new Fetcher<Date, BarCode>() {
@Nonnull
@Override
public Single<Date> fetch(@Nonnull BarCode barCode) {
return Single.just(DATE);
}
}).open();
Store<Date, Integer> keyStore = StoreBuilder.<Integer, Date>key().fetcher(new Fetcher<Date, Integer>() {
@Nonnull
@Override
public Single<Date> fetch(@Nonnull Integer key) {
return Single.just(DATE);
}
}).open();
Date result = store.get(5).blockingGet();
result = barCodeStore.get(new BarCode("test", "5")).blockingGet();
result = keyStore.get(5).blockingGet();
assertThat(result).isNotNull();
}
use of com.nytimes.android.external.store3.base.impl.BarCode in project Store by NYTimes.
the class PersistingStoreActivity method loadPosts.
@SuppressWarnings("CheckReturnValue")
public void loadPosts() {
BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww");
this.persistedStore.get(awwRequest).flatMapObservable(this::sanitizeData).toList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showPosts, throwable -> Log.e(StoreActivity.class.getSimpleName(), throwable.getMessage(), throwable));
}
use of com.nytimes.android.external.store3.base.impl.BarCode in project Store by NYTimes.
the class StoreActivity method loadPosts.
@SuppressWarnings("CheckReturnValue")
public void loadPosts() {
BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww");
this.nonPersistedStore.get(awwRequest).flatMapObservable(new Function<RedditData, ObservableSource<Post>>() {
@Override
public ObservableSource<Post> apply(@NonNull RedditData redditData) throws Exception {
return sanitizeData(redditData);
}
}).toList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showPosts, throwable -> {
Log.e(StoreActivity.class.getSimpleName(), throwable.getMessage(), throwable);
});
}
Aggregations