use of com.nytimes.android.external.store3.base.impl.StoreBuilder in project Store by NYTimes.
the class ClearStoreTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(barCode -> Single.fromCallable(() -> networkCalls.incrementAndGet())).persister(persister).open();
}
use of com.nytimes.android.external.store3.base.impl.StoreBuilder in project Store by NYTimes.
the class GetRefreshingTest method setUp.
@Before
public void setUp() {
networkCalls = new AtomicInteger(0);
store = StoreBuilder.<Integer>barcode().fetcher(barCode -> Single.fromCallable(() -> networkCalls.incrementAndGet())).persister(persister).open();
}
use of com.nytimes.android.external.store3.base.impl.StoreBuilder 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);
}
use of com.nytimes.android.external.store3.base.impl.StoreBuilder 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);
}
use of com.nytimes.android.external.store3.base.impl.StoreBuilder 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);
}
Aggregations