Search in sources :

Example 1 with Foo

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

the class NoopPersisterTest method writeReadTest.

@Test
public void writeReadTest() {
    BarCode barCode = new BarCode("key", "value");
    NoopPersister<String, BarCode> persister = NoopPersister.create();
    boolean success = persister.write(barCode, "foo").blockingGet();
    assertThat(success).isTrue();
    String rawValue = persister.read(barCode).blockingGet();
    assertThat(rawValue).isEqualTo("foo");
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Test(org.junit.Test)

Example 2 with Foo

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

the class SourceDiskDaoStoreTest method testSimple.

@Test
public void testSimple() {
    MockitoAnnotations.initMocks(this);
    GsonSourceParser<Foo> parser = new GsonSourceParser<>(new Gson(), Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(diskDAO).fetcher(fetcher).parser(parser).open();
    Foo foo = new Foo();
    foo.bar = barCode.getKey();
    String sourceData = new Gson().toJson(foo);
    BufferedSource source = source(sourceData);
    Single<BufferedSource> value = Single.just(source);
    when(fetcher.fetch(barCode)).thenReturn(value);
    when(diskDAO.read(barCode)).thenReturn(Maybe.<BufferedSource>empty()).thenReturn(value.toMaybe());
    when(diskDAO.write(barCode, source)).thenReturn(Single.just(true));
    Foo result = store.get(barCode).blockingGet();
    assertThat(result.bar).isEqualTo(KEY);
    result = store.get(barCode).blockingGet();
    assertThat(result.bar).isEqualTo(KEY);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : GsonSourceParser(com.nytimes.android.external.store3.middleware.GsonSourceParser) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Gson(com.google.gson.Gson) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 3 with Foo

use of com.nytimes.android.external.store3.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).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) Test(org.junit.Test)

Example 4 with Foo

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

the class JacksonReaderParserStoreTest method testDefaultJacksonReaderParser.

@Test
public void testDefaultJacksonReaderParser() {
    Parser<Reader, Foo> parser = JacksonParserFactory.createReaderParser(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) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 5 with Foo

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

the class JacksonStringParserStoreTest method testDefaultJacksonStringParser.

@Test
public void testDefaultJacksonStringParser() {
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, String, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(JacksonParserFactory.createStringParser(Foo.class)).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) Test(org.junit.Test)

Aggregations

BarCode (com.nytimes.android.external.store3.base.impl.BarCode)13 Test (org.junit.Test)13 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 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 TypeToken (com.google.gson.reflect.TypeToken)1 List (java.util.List)1