Search in sources :

Example 1 with Foo

use of com.nytimes.android.external.store.middleware.moshi.data.Foo 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).toBlocking().first();
    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.store.middleware.moshi.data.Foo) BarCode(com.nytimes.android.external.store.base.impl.BarCode) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 2 with Foo

use of com.nytimes.android.external.store.middleware.moshi.data.Foo in project Store by NYTimes.

the class MoshiStringParserStoreTest method testMoshiString.

@Test
public void testMoshiString() {
    Store<Foo, BarCode> store = ParsingStoreBuilder.<String, Foo>builder().persister(persister).fetcher(fetcher).parser(MoshiParserFactory.createStringParser(Foo.class)).open();
    Foo result = store.get(barCode).toBlocking().first();
    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.store.middleware.moshi.data.Foo) BarCode(com.nytimes.android.external.store.base.impl.BarCode) Test(org.junit.Test)

Aggregations

BarCode (com.nytimes.android.external.store.base.impl.BarCode)2 Foo (com.nytimes.android.external.store.middleware.moshi.data.Foo)2 Test (org.junit.Test)2 BufferedSource (okio.BufferedSource)1