use of com.nytimes.android.external.store3.base.Persister in project Store by NYTimes.
the class StoreUtil method persisterIsStale.
static <Raw, Key> boolean persisterIsStale(@Nonnull Key key, Persister<Raw, Key> persister) {
if (persister instanceof RecordProvider) {
RecordProvider<Key> provider = (RecordProvider<Key>) persister;
RecordState recordState = provider.getRecordState(key);
return recordState == STALE;
}
return false;
}
use of com.nytimes.android.external.store3.base.Persister 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.Persister 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.Persister 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");
}
use of com.nytimes.android.external.store3.base.Persister in project Store by NYTimes.
the class SourceFilerReaderWriterStoreTest method testSimple.
@Test
public void testSimple() {
MockitoAnnotations.initMocks(this);
GsonSourceParser<Foo> parser = new GsonSourceParser<>(new Gson(), Foo.class);
Store<Foo, BarCode> simpleStore = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(fileReader, fileWriter).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(fileReader.read(barCode)).thenReturn(Maybe.<BufferedSource>empty()).thenReturn(value.toMaybe());
when(fileWriter.write(barCode, source)).thenReturn(Single.just(true));
Foo result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
result = simpleStore.get(barCode).blockingGet();
assertThat(result.bar).isEqualTo(KEY);
verify(fetcher, times(1)).fetch(barCode);
}
Aggregations