Search in sources :

Example 21 with Persister

use of com.nytimes.android.external.store3.base.Persister in project Store by NYTimes.

the class MoshiSourceParserTest method testSourceParser.

@Test
public void testSourceParser() throws Exception {
    Parser<BufferedSource, Foo> parser = MoshiParserFactory.createSourceParser(Foo.class);
    Store<Foo, BarCode> store = ParsingStoreBuilder.<BufferedSource, Foo>builder().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).blockingGet();
    assertEquals(result.number, 123);
    assertEquals(result.string, "abc");
    assertEquals(result.bars.size(), 2);
    assertEquals(result.bars.get(0).string, "def");
    assertEquals(result.bars.get(1).string, "ghi");
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store3.middleware.moshi.data.Foo) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Aggregations

BarCode (com.nytimes.android.external.store3.base.impl.BarCode)19 Test (org.junit.Test)19 BufferedSource (okio.BufferedSource)7 Foo (com.nytimes.android.external.store3.middleware.jackson.data.Foo)6 Gson (com.google.gson.Gson)4 Single (io.reactivex.Single)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)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 Nonnull (javax.annotation.Nonnull)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 Mock (org.mockito.Mock)3 Mockito.when (org.mockito.Mockito.when)3 MockitoJUnitRunner (org.mockito.runners.MockitoJUnitRunner)3 Clearable (com.nytimes.android.external.store3.base.Clearable)2 Persister (com.nytimes.android.external.store3.base.Persister)2