Search in sources :

Example 11 with BarCode

use of com.nytimes.android.external.store3.base.impl.BarCode 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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Clearable(com.nytimes.android.external.store3.base.Clearable) Mock(org.mockito.Mock) BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Maybe(io.reactivex.Maybe) Test(org.junit.Test) TestObserver(io.reactivex.observers.TestObserver) Mockito.when(org.mockito.Mockito.when) Single(io.reactivex.Single) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StoreBuilder(com.nytimes.android.external.store3.base.impl.StoreBuilder) Persister(com.nytimes.android.external.store3.base.Persister) Store(com.nytimes.android.external.store3.base.impl.Store) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Before(org.junit.Before)

Example 12 with BarCode

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

the class SequentialTest method sequentially.

@Test
public void sequentially() {
    BarCode b = new BarCode("one", "two");
    store.get(b).test().awaitTerminalEvent();
    store.get(b).test().awaitTerminalEvent();
    assertThat(networkCalls).isEqualTo(1);
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Test(org.junit.Test)

Example 13 with BarCode

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

the class SequentialTest method parallelWithResult.

@Test
public void parallelWithResult() {
    BarCode b = new BarCode("one", "two");
    Single<Result<Integer>> first = store.getWithResult(b);
    Single<Result<Integer>> second = store.getWithResult(b);
    first.test().awaitTerminalEvent();
    second.test().awaitTerminalEvent();
    assertThat(networkCalls).isEqualTo(1);
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Result(com.nytimes.android.external.store.util.Result) Test(org.junit.Test)

Example 14 with BarCode

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

the class SequentialTest method sequentiallyWithResult.

@Test
public void sequentiallyWithResult() {
    BarCode b = new BarCode("one", "two");
    store.getWithResult(b).test().awaitTerminalEvent();
    store.getWithResult(b).test().awaitTerminalEvent();
    assertThat(networkCalls).isEqualTo(1);
}
Also used : BarCode(com.nytimes.android.external.store3.base.impl.BarCode) Test(org.junit.Test)

Example 15 with BarCode

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

Aggregations

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