Search in sources :

Example 1 with Fetcher

use of com.nytimes.android.external.store.base.Fetcher in project Store by NYTimes.

the class GetRefreshingTest 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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Nonnull(javax.annotation.Nonnull) BarCode(com.nytimes.android.external.store.base.impl.BarCode) Fetcher(com.nytimes.android.external.store.base.Fetcher) Before(org.junit.Before)

Example 2 with Fetcher

use of com.nytimes.android.external.store.base.Fetcher 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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Nonnull(javax.annotation.Nonnull) BarCode(com.nytimes.android.external.store.base.impl.BarCode) Fetcher(com.nytimes.android.external.store.base.Fetcher) Before(org.junit.Before)

Example 3 with Fetcher

use of com.nytimes.android.external.store.base.Fetcher 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();
}
Also used : Nonnull(javax.annotation.Nonnull) BarCode(com.nytimes.android.external.store.base.impl.BarCode) Fetcher(com.nytimes.android.external.store.base.Fetcher) Date(java.util.Date) Observable(rx.Observable) Parser(com.nytimes.android.external.store.base.Parser) Test(org.junit.Test)

Aggregations

Fetcher (com.nytimes.android.external.store.base.Fetcher)3 BarCode (com.nytimes.android.external.store.base.impl.BarCode)3 Nonnull (javax.annotation.Nonnull)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 Parser (com.nytimes.android.external.store.base.Parser)1 Date (java.util.Date)1 Test (org.junit.Test)1 Observable (rx.Observable)1