Search in sources :

Example 1 with Parser

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