Search in sources :

Example 26 with BarCode

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();
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Test(org.junit.Test)

Example 27 with BarCode

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);
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Test(org.junit.Test)

Example 28 with BarCode

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();
}
Also used : Date(java.util.Date) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Maybe(io.reactivex.Maybe) StoreBuilder(com.nytimes.android.external.store3.base.impl.StoreBuilder) Fetcher(com.nytimes.android.external.store3.base.Fetcher) Persister(com.nytimes.android.external.store3.base.Persister) Test(org.junit.Test) Store(com.nytimes.android.external.store3.base.impl.Store) Nonnull(javax.annotation.Nonnull) Single(io.reactivex.Single) Maybe(io.reactivex.Maybe) Nonnull(javax.annotation.Nonnull) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Date(java.util.Date) Single(io.reactivex.Single) Fetcher(com.nytimes.android.external.store3.base.Fetcher) Test(org.junit.Test)

Example 29 with BarCode

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));
}
Also used : RedditData(com.nytimes.android.sample.data.model.RedditData) BarCode(com.nytimes.android.external.store3.base.impl.BarCode)

Example 30 with BarCode

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);
    });
}
Also used : RedditData(com.nytimes.android.sample.data.model.RedditData) ObservableSource(io.reactivex.ObservableSource) BarCode(com.nytimes.android.external.store3.base.impl.BarCode)

Aggregations

BarCode (com.nytimes.android.external.store3.base.impl.BarCode)30 Test (org.junit.Test)28 BufferedSource (okio.BufferedSource)7 Foo (com.nytimes.android.external.store3.middleware.jackson.data.Foo)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Gson (com.google.gson.Gson)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 Store (com.nytimes.android.external.store3.base.impl.Store)3 StoreBuilder (com.nytimes.android.external.store3.base.impl.StoreBuilder)3 Maybe (io.reactivex.Maybe)3 Single (io.reactivex.Single)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Persister (com.nytimes.android.external.store3.base.Persister)2 GsonSourceParser (com.nytimes.android.external.store3.middleware.GsonSourceParser)2 Foo (com.nytimes.android.external.store3.middleware.moshi.data.Foo)2 RedditData (com.nytimes.android.sample.data.model.RedditData)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Nonnull (javax.annotation.Nonnull)2 Before (org.junit.Before)2