Search in sources :

Example 11 with Store

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

the class JacksonReaderParserStoreTest method testCustomJsonFactoryReaderParser.

@Test
public void testCustomJsonFactoryReaderParser() {
    JsonFactory jsonFactory = new JsonFactory();
    Parser<Reader, Foo> parser = JacksonParserFactory.createReaderParser(jsonFactory, Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, Reader, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).blockingGet();
    validateFoo(result);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store3.middleware.jackson.data.Foo) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 12 with Store

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

the class JacksonSourceParserStoreTest method testCustomJsonFactorySourceParser.

@Test
public void testCustomJsonFactorySourceParser() {
    JsonFactory jsonFactory = new JsonFactory();
    Parser<BufferedSource, Foo> parser = JacksonParserFactory.createSourceParser(jsonFactory, Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).blockingGet();
    validateFoo(result);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store3.middleware.jackson.data.Foo) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 13 with Store

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

the class JacksonSourceParserStoreTest method testDefaultJacksonSourceParser.

@Test
public void testDefaultJacksonSourceParser() {
    Parser<BufferedSource, Foo> parser = JacksonParserFactory.createSourceParser(Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).blockingGet();
    validateFoo(result);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store3.middleware.jackson.data.Foo) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 14 with Store

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

the class JacksonStringParserStoreTest method testCustomJsonFactoryStringParser.

@Test
public void testCustomJsonFactoryStringParser() {
    JsonFactory jsonFactory = new JsonFactory();
    Parser<String, Foo> parser = JacksonParserFactory.createStringParser(jsonFactory, Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, String, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).blockingGet();
    validateFoo(result);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store3.middleware.jackson.data.Foo) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Test(org.junit.Test)

Example 15 with Store

use of com.nytimes.android.external.store3.base.impl.Store 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

Test (org.junit.Test)17 BarCode (com.nytimes.android.external.store3.base.impl.BarCode)16 BufferedSource (okio.BufferedSource)7 Foo (com.nytimes.android.external.store3.middleware.jackson.data.Foo)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 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)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 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Nonnull (javax.annotation.Nonnull)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2