From a9ed8718344678890d97ab9a3ec77561766becbd Mon Sep 17 00:00:00 2001 From: Maksim Moiseikin Date: Thu, 23 Mar 2017 21:29:47 +0100 Subject: [PATCH 1/3] Port to RxJava 2 (#155) * Port Store artifact to RxJava 2 --- app/build.gradle | 25 ++- .../com/nytimes/android/sample/SampleApp.java | 22 +- .../activity/PersistingStoreActivity.java | 9 +- .../sample/activity/StoreActivity.java | 19 +- .../android/sample/data/remote/Api.java | 3 +- .../android/sample/StoreIntegrationTest.java | 5 +- buildsystem/dependencies.gradle | 8 +- .../nytimes/android/external/fs/FSReader.java | 18 +- .../nytimes/android/external/fs/FSWriter.java | 3 +- .../external/fs/FileSystemPersister.java | 3 +- .../fs/FileSystemRecordPersister.java | 2 +- .../android/external/fs/SourcePersister.java | 2 +- .../external/fs/FilePersisterTest.java | 10 +- .../fs/FileSystemRecordPersisterTest.java | 10 +- .../external/fs/RecordPersisterTest.java | 7 +- .../external/fs/SourceDiskDaoStoreTest.java | 6 +- .../fs/SourceFilerReaderWriterStoreTest.java | 6 +- .../external/fs/SourcePersisterTest.java | 7 +- .../fs/StoreNetworkBeforeStaleTest.java | 2 +- .../fs/StoreRefreshWhenStaleTest.java | 24 ++- .../jackson/JacksonReaderParser.java | 7 +- .../jackson/JacksonSourceParser.java | 12 +- .../jackson/JacksonStringParser.java | 11 +- .../jackson/JacksonReaderParserStoreTest.java | 7 +- .../jackson/JacksonSourceParserStoreTest.java | 6 +- .../jackson/JacksonStringParserStoreTest.java | 7 +- .../middleware/moshi/MoshiSourceParser.java | 10 +- .../middleware/moshi/MoshiStringParser.java | 12 +- .../moshi/MoshiSourceParserTest.java | 4 +- .../moshi/MoshiStringParserStoreTest.java | 5 +- .../store/middleware/GsonReaderParser.java | 6 +- .../store/middleware/GsonSourceParser.java | 9 +- .../store/middleware/GsonStringParser.java | 8 +- .../store/GenericParserStoreTest.java | 6 +- .../store/GsonSourceListParserTest.java | 4 +- store/build.gradle | 2 +- .../android/external/store/base/DiskRead.java | 3 +- .../external/store/base/DiskWrite.java | 2 +- .../android/external/store/base/Fetcher.java | 3 +- .../external/store/base/InternalStore.java | 2 +- .../android/external/store/base/Parser.java | 11 +- .../external/store/base/Persister.java | 2 +- .../external/store/base/impl/MultiParser.java | 7 +- .../store/base/impl/RealInternalStore.java | 192 +++++++++--------- .../external/store/base/impl/RealStore.java | 3 +- .../store/base/impl/RealStoreBuilder.java | 3 +- .../store/base/impl/RepeatWhenEmits.java | 19 +- .../external/store/base/impl/Store.java | 5 +- .../store/base/impl/StoreBuilder.java | 2 +- .../external/store/base/impl/StoreUtil.java | 15 +- .../external/store/util/KeyParser.java | 12 +- .../external/store/util/NoKeyParser.java | 7 +- .../external/store/util/NoopParserFunc.java | 7 +- .../external/store/util/NoopPersister.java | 3 +- .../store/util/OnErrorResumeWithEmpty.java | 10 +- .../external/store/util/ParserException.java | 8 + .../external/store/ClearStoreMemoryTest.java | 3 +- .../external/store/ClearStoreTest.java | 3 +- .../external/store/DontCacheErrorsTest.java | 12 +- .../external/store/GetRefreshingTest.java | 20 +- .../android/external/store/KeyParserTest.java | 15 +- .../external/store/SequentialTest.java | 3 +- .../external/store/StoreBuilderTest.java | 11 +- .../android/external/store/StoreTest.java | 38 ++-- .../external/store/StoreWithParserTest.java | 19 +- .../store/base/impl/MultiParserTest.java | 10 +- .../store/base/impl/RepeatWhenEmitsTest.java | 8 +- .../store/util/NoopPersisterTest.java | 7 +- 68 files changed, 427 insertions(+), 345 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5eed9f96..06b411c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,6 +28,10 @@ android { abortOnError false disable 'InvalidPackage' } + + packagingOptions { + exclude 'META-INF/rxjava.properties' + } } dependencies { @@ -40,21 +44,20 @@ dependencies { compile libraries.supportDesign compile libraries.retrofit compile libraries.retrofitGsonConverter - compile libraries.retrofitRx + compile libraries.retrofitRx2 compile libraries.picasso compile libraries.guava annotationProcessor libraries.immutablesValue // <-- for annotation processor provided libraries.immutablesValue // <-- for annotation API provided libraries.immutablesGson // for annotations - compile 'com.nytimes.android:store:2.0.2' - compile'com.nytimes.android:cache:2.0.2' - compile'com.nytimes.android:middleware:2.0.2' - compile 'com.nytimes.android:filesystem:2.0.2' - //compile project(path: ':store') - //compile project(path: ':cache') - //compile project(path: ':middleware') - //compile project(path: ':filesystem') + //compile 'com.nytimes.android:store:2.0.2' + //compile'com.nytimes.android:cache:2.0.2' + //compile'com.nytimes.android:middleware:2.0.2' + //compile 'com.nytimes.android:filesystem:2.0.2' + compile project(path: ':store') + compile project(path: ':cache') + compile project(path: ':middleware') + compile project(path: ':filesystem') retrolambdaConfig libraries.retrolambda - compile libraries.rxAndroid - + compile libraries.rxAndroid2 } diff --git a/app/src/main/java/com/nytimes/android/sample/SampleApp.java b/app/src/main/java/com/nytimes/android/sample/SampleApp.java index c50a9ddd..a3618b0f 100644 --- a/app/src/main/java/com/nytimes/android/sample/SampleApp.java +++ b/app/src/main/java/com/nytimes/android/sample/SampleApp.java @@ -1,12 +1,10 @@ package com.nytimes.android.sample; import android.app.Application; -import android.util.Log; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.nytimes.android.external.fs.SourcePersisterFactory; -import com.nytimes.android.external.store.base.Fetcher; import com.nytimes.android.external.store.base.Persister; import com.nytimes.android.external.store.base.impl.BarCode; import com.nytimes.android.external.store.base.impl.MemoryPolicy; @@ -20,13 +18,11 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -import javax.annotation.Nonnull; - +import io.reactivex.Observable; import okio.BufferedSource; -import retrofit2.GsonConverterFactory; import retrofit2.Retrofit; -import retrofit2.RxJavaCallAdapterFactory; -import rx.Observable; +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; +import retrofit2.converter.gson.GsonConverterFactory; public class SampleApp extends Application { @@ -63,11 +59,11 @@ private Store provideRedditStore() { return StoreBuilder.barcode() .fetcher(barCode -> provideRetrofit().fetchSubreddit(barCode.getKey(), "10")) .memoryPolicy( - MemoryPolicy - .builder() - .setExpireAfter(10) - .setExpireAfterTimeUnit(TimeUnit.SECONDS) - .build() + MemoryPolicy + .builder() + .setExpireAfter(10) + .setExpireAfterTimeUnit(TimeUnit.SECONDS) + .build() ) .open(); } @@ -93,7 +89,7 @@ private Api provideRetrofit() { return new Retrofit.Builder() .baseUrl("http://reddit.com/") .addConverterFactory(GsonConverterFactory.create(provideGson())) - .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .validateEagerly(BuildConfig.DEBUG) // Fail early: check Retrofit configuration at creation time in Debug build. .build() .create(Api.class); diff --git a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java index 74e1bf24..ab264582 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java @@ -18,9 +18,9 @@ import java.util.List; -import rx.Observable; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; import static android.widget.Toast.makeText; @@ -52,6 +52,7 @@ private void initStore() { } } + @SuppressWarnings("CheckReturnValue") public void loadPosts() { BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww"); @@ -74,7 +75,7 @@ private void showPosts(List posts) { } private Observable sanitizeData(RedditData redditData) { - return Observable.from(redditData.data().children()) + return Observable.fromIterable(redditData.data().children()) .map(Children::data); } diff --git a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java index 9d4ace93..fbe295ed 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java @@ -19,9 +19,12 @@ import java.util.List; -import rx.Observable; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; +import io.reactivex.Observable; +import io.reactivex.ObservableSource; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Function; +import io.reactivex.schedulers.Schedulers; import static android.widget.Toast.makeText; @@ -51,12 +54,18 @@ private void initStore() { } } + @SuppressWarnings("CheckReturnValue") public void loadPosts() { BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww"); this.nonPersistedStore .get(awwRequest) - .flatMap(this::sanitizeData) + .flatMap(new Function>() { + @Override + public ObservableSource apply(@NonNull RedditData redditData) throws Exception { + return sanitizeData(redditData); + } + }) .toList() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -74,7 +83,7 @@ private void showPosts(List posts) { } private Observable sanitizeData(RedditData redditData) { - return Observable.from(redditData.data().children()) + return Observable.fromIterable(redditData.data().children()) .map(Children::data); } diff --git a/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java b/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java index a10be874..9c8e172e 100644 --- a/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java +++ b/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java @@ -2,12 +2,11 @@ import com.nytimes.android.sample.data.model.RedditData; -import okhttp3.Response; +import io.reactivex.Observable; import okhttp3.ResponseBody; import retrofit2.http.GET; import retrofit2.http.Path; import retrofit2.http.Query; -import rx.Observable; public interface Api { diff --git a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java index 3da98901..96dd6a00 100644 --- a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java +++ b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java @@ -7,7 +7,8 @@ import org.junit.Before; import org.junit.Test; -import rx.Observable; + +import io.reactivex.Observable; import static junit.framework.Assert.assertEquals; @@ -36,7 +37,7 @@ public void setUp() throws Exception { @Test public void testRepeatedGet() throws Exception { - String first = testStore.get(BarCode.empty()).toBlocking().first(); + String first = testStore.get(BarCode.empty()).blockingFirst(); assertEquals(first, "hello"); } diff --git a/buildsystem/dependencies.gradle b/buildsystem/dependencies.gradle index 8b693c94..8d5349cf 100644 --- a/buildsystem/dependencies.gradle +++ b/buildsystem/dependencies.gradle @@ -26,12 +26,14 @@ ext.versions = [ // Reactive. rxJava : '1.2.6', + rxJava2 : '2.0.7', rxJavaProGuardRules : '1.1.6.0', rxJavaAsyncUtil : '0.21.0', rxAndroid : '1.2.1', + rxAndroid2 : '2.0.1', // Others. - retrofit : '2.0.0-beta3', + retrofit : '2.2.0', retrolambda : '2.3.0', dagger : '2.9', jsr305 : '3.0.1', @@ -80,14 +82,16 @@ ext.libraries = [ // Reactive. rxJava : "io.reactivex:rxjava:$versions.rxJava", + rxJava2 : "io.reactivex.rxjava2:rxjava:$versions.rxJava2", rxJavaAsyncUtil : "io.reactivex:rxjava-async-util:$versions.rxJavaAsyncUtil", rxJavaProGuardRules : "com.artemzin.rxjava:proguard-rules:$versions.rxJavaProGuardRules", rxAndroid : "io.reactivex:rxandroid:$versions.rxAndroid", + rxAndroid2 : "io.reactivex.rxjava2:rxandroid:$versions.rxAndroid2", // Others. retrofit : "com.squareup.retrofit2:retrofit:$versions.retrofit", retrofitGsonConverter : "com.squareup.retrofit2:converter-gson:$versions.retrofit", - retrofitRx : "com.squareup.retrofit2:adapter-rxjava:$versions.retrofit", + retrofitRx2 : "com.squareup.retrofit2:adapter-rxjava2:$versions.retrofit", retrolambda : "net.orfjackal.retrolambda:retrolambda:$versions.retrolambda", dagger : "com.google.dagger:dagger:$versions.dagger", daggerCompiler : "com.google.dagger:dagger-compiler:$versions.dagger", diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java b/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java index 7f4eab98..bd3acdc3 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java @@ -7,10 +7,10 @@ import javax.annotation.Nonnull; +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; import okio.BufferedSource; -import rx.Emitter; -import rx.Observable; -import rx.functions.Action1; /** * FSReader is used when persisting from file system @@ -31,24 +31,24 @@ public FSReader(FileSystem fileSystem, PathResolver pathResolver) { @Nonnull @Override public Observable read(@Nonnull final T key) { - return Observable.fromEmitter(new Action1>() { + return Observable.create(new ObservableOnSubscribe() { @Override - public void call(Emitter emitter) { + public void subscribe(ObservableEmitter emitter) { String resolvedKey = pathResolver.resolve(key); boolean exists = fileSystem.exists(resolvedKey); - + if (exists) { try { BufferedSource bufferedSource = fileSystem.read(resolvedKey); emitter.onNext(bufferedSource); - emitter.onCompleted(); + emitter.onComplete(); } catch (FileNotFoundException e) { emitter.onError(e); } } else { - emitter.onCompleted(); + emitter.onComplete(); } } - }, Emitter.BackpressureMode.NONE); + }); } } diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java b/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java index 67bf9e75..e860ae3a 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java @@ -7,8 +7,9 @@ import javax.annotation.Nonnull; +import io.reactivex.Observable; import okio.BufferedSource; -import rx.Observable; + /** * FSReader is used when persisting to file system * PathResolver will be used in creating file system paths based on cache keys. diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java index 31a8ca70..0cb15952 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java @@ -5,8 +5,9 @@ import javax.annotation.Nonnull; +import io.reactivex.Observable; import okio.BufferedSource; -import rx.Observable; + /** * FileSystemPersister is used when persisting to/from file system * PathResolver will be used in creating file system paths based on cache keys. diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java index 7ebebcc4..1dce9787 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java @@ -9,8 +9,8 @@ import javax.annotation.Nonnull; +import io.reactivex.Observable; import okio.BufferedSource; -import rx.Observable; /** * FileSystemRecordPersister is used when persisting to/from file system while being stale aware diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java index 5888e2ad..02e9c123 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java @@ -8,8 +8,8 @@ import javax.annotation.Nonnull; import javax.inject.Inject; +import io.reactivex.Observable; import okio.BufferedSource; -import rx.Observable; /** * Persister to be used when storing something to persister from a BufferedSource diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java index 8c275f1f..47f2d76d 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java @@ -47,25 +47,27 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); - BufferedSource returnedValue = fileSystemPersister.read(simple).toBlocking().single(); + BufferedSource returnedValue = fileSystemPersister.read(simple).blockingFirst(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test + @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(resolvedPath)) .thenReturn(false); - fileSystemPersister.read(simple).toBlocking().single(); + fileSystemPersister.read(simple).blockingFirst(); } @Test + @SuppressWarnings("CheckReturnValue") public void writeThenRead() throws IOException { when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); when(fileSystem.exists(resolvedPath)).thenReturn(true); - fileSystemPersister.write(simple, bufferedSource).toBlocking().single(); - BufferedSource source = fileSystemPersister.read(simple).toBlocking().first(); + fileSystemPersister.write(simple, bufferedSource).blockingFirst(); + BufferedSource source = fileSystemPersister.read(simple).blockingFirst(); InOrder inOrder = inOrder(fileSystem); inOrder.verify(fileSystem).write(resolvedPath, bufferedSource); inOrder.verify(fileSystem).exists(resolvedPath); diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java index 8d86bc36..3ed2f303 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java @@ -50,25 +50,27 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); - BufferedSource returnedValue = fileSystemPersister.read(simple).toBlocking().single(); + BufferedSource returnedValue = fileSystemPersister.read(simple).blockingFirst(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test + @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(resolvedPath)) .thenReturn(false); - fileSystemPersister.read(simple).toBlocking().single(); + fileSystemPersister.read(simple).blockingFirst(); } @Test + @SuppressWarnings("CheckReturnValue") public void writeThenRead() throws IOException { when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); when(fileSystem.exists(resolvedPath)).thenReturn(true); - fileSystemPersister.write(simple, bufferedSource).toBlocking().single(); - BufferedSource source = fileSystemPersister.read(simple).toBlocking().first(); + fileSystemPersister.write(simple, bufferedSource).blockingFirst(); + BufferedSource source = fileSystemPersister.read(simple).blockingFirst(); InOrder inOrder = inOrder(fileSystem); inOrder.verify(fileSystem).write(resolvedPath, bufferedSource); inOrder.verify(fileSystem).exists(resolvedPath); diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java index d2a0a365..5dd94b12 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java @@ -45,7 +45,7 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(simple.toString())).thenReturn(bufferedSource); - BufferedSource returnedValue = sourcePersister.read(simple).toBlocking().single(); + BufferedSource returnedValue = sourcePersister.read(simple).blockingFirst(); assertThat(returnedValue).isEqualTo(bufferedSource); } @@ -74,17 +74,18 @@ public void missingTest() { } @Test + @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(SourcePersister.pathForBarcode(simple))) .thenReturn(false); - sourcePersister.read(simple).toBlocking().single(); + sourcePersister.read(simple).blockingFirst(); } @Test public void write() throws IOException { - assertThat(sourcePersister.write(simple, bufferedSource).toBlocking().single()).isTrue(); + assertThat(sourcePersister.write(simple, bufferedSource).blockingSingle()).isTrue(); } @Test diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java index 68f5bfbe..84f7f0e8 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java @@ -14,9 +14,9 @@ import java.io.ByteArrayInputStream; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static com.google.common.base.Charsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -65,9 +65,9 @@ public void testSimple() { when(diskDAO.write(barCode, source)) .thenReturn(Observable.just(true)); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); - result = store.get(barCode).toBlocking().first(); + result = store.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java index 800990ad..9df3ec02 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java @@ -13,9 +13,9 @@ import java.io.ByteArrayInputStream; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static com.google.common.base.Charsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -65,9 +65,9 @@ public void testSimple() { when(fileWriter.write(barCode, source)) .thenReturn(Observable.just(true)); - Foo result = simpleStore.get(barCode).toBlocking().first(); + Foo result = simpleStore.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); - result = simpleStore.get(barCode).toBlocking().first(); + result = simpleStore.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java index befc8b2f..073722f2 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java @@ -44,22 +44,23 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(simple.toString())).thenReturn(bufferedSource); - BufferedSource returnedValue = sourcePersister.read(simple).toBlocking().single(); + BufferedSource returnedValue = sourcePersister.read(simple).blockingSingle(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test + @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(SourcePersister.pathForBarcode(simple))) .thenReturn(false); - sourcePersister.read(simple).toBlocking().single(); + sourcePersister.read(simple).blockingSingle(); } @Test public void write() throws IOException { - assertThat(sourcePersister.write(simple, bufferedSource).toBlocking().single()).isTrue(); + assertThat(sourcePersister.write(simple, bufferedSource).blockingSingle()).isTrue(); } @Test diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java index bbfc9f54..c7691975 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java @@ -14,8 +14,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; +import io.reactivex.Observable; import okio.BufferedSource; -import rx.Observable; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.never; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java index 57cb80bd..a5483244 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java @@ -13,10 +13,10 @@ import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; import okio.BufferedSource; -import rx.Observable; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -81,20 +81,22 @@ public void diskWasNotRefreshedWhenFreshRecord() { when(persister.write(barCode, network1)) .thenReturn(Observable.just(true)); - BufferedSource result = store.get(barCode) - .test() - .awaitTerminalEvent() - .getOnNextEvents() - .get(0); - assertThat(result).isEqualTo(disk1); + TestObserver testObserver = store + .get(barCode) + .test(); + testObserver.awaitTerminalEvent(); + testObserver.assertNoErrors(); + testObserver.assertResult(disk1); verify(fetcher, times(0)).fetch(barCode); verify(persister, times(1)).getRecordState(barCode); store.clear(barCode); - result = store.get(barCode).test().awaitTerminalEvent().getOnNextEvents().get(0); - assertThat(result).isEqualTo(disk2); + testObserver = store + .get(barCode) + .test(); + testObserver.awaitTerminalEvent(); + testObserver.assertResult(disk2); verify(fetcher, times(0)).fetch(barCode); verify(persister, times(2)).getRecordState(barCode); - } } diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java index a43f476f..a43eab43 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import java.io.IOException; import java.io.Reader; @@ -13,6 +14,8 @@ import javax.annotation.Nonnull; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; + public class JacksonReaderParser implements Parser { private final ObjectMapper objectMapper; @@ -30,11 +33,11 @@ public JacksonReaderParser(@Nonnull ObjectMapper objectMapper, @Nonnull Type typ } @Override - public Parsed call(@Nonnull Reader reader) { + public Parsed apply(@NonNull Reader reader) throws ParserException { try { return objectMapper.readValue(reader, parsedType); } catch (IOException e) { - return null; + throw new ParserException(e.getMessage(), e); } } } diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java index 262fb67a..c797ac72 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java @@ -4,15 +4,16 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; import okio.BufferedSource; public class JacksonSourceParser implements Parser { @@ -32,14 +33,13 @@ public JacksonSourceParser(@Nonnull ObjectMapper objectMapper, @Nonnull Type typ } @Override - @Nullable - @SuppressWarnings("PMD.EmptyCatchBlock") - public Parsed call(@Nonnull BufferedSource source) { - InputStream inputStream = source.inputStream(); + @SuppressWarnings({"PMD.EmptyCatchBlock"}) + public Parsed apply(@NonNull BufferedSource bufferedSource) throws ParserException { + InputStream inputStream = bufferedSource.inputStream(); try { return objectMapper.readValue(inputStream, parsedType); } catch (IOException e) { - return null; + throw new ParserException(e.getMessage(), e); } finally { try { if (inputStream != null) { diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java index 2f1fa6a2..c171ae86 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java @@ -4,14 +4,16 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import java.io.IOException; import java.lang.reflect.Type; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; + public class JacksonStringParser implements Parser { private final ObjectMapper objectMapper; @@ -29,12 +31,11 @@ public JacksonStringParser(@Nonnull ObjectMapper objectMapper, @Nonnull Type typ } @Override - @Nullable - public Parsed call(@Nonnull String source) { + public Parsed apply(@NonNull String s) throws ParserException { try { - return objectMapper.readValue(source, parsedType); + return objectMapper.readValue(s, parsedType); } catch (IOException e) { - return null; + throw new ParserException(e.getMessage(), e); } } } diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java index cf0ee2a4..cc2d8c7e 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java @@ -20,7 +20,8 @@ import java.io.Reader; import java.io.StringReader; -import rx.Observable; + +import io.reactivex.Observable; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -66,7 +67,7 @@ public void testDefaultJacksonReaderParser() { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); @@ -85,7 +86,7 @@ public void testCustomJsonFactoryReaderParser() { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java index f19c46d3..ecbee487 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java @@ -20,9 +20,9 @@ import java.io.ByteArrayInputStream; import java.nio.charset.Charset; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -74,7 +74,7 @@ public void testDefaultJacksonSourceParser() { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); @@ -93,7 +93,7 @@ public void testCustomJsonFactorySourceParser() { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java index 382cae87..efca977b 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java @@ -17,7 +17,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import rx.Observable; + +import io.reactivex.Observable; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -61,7 +62,7 @@ public void testDefaultJacksonStringParser() { .parser(JacksonParserFactory.createStringParser(Foo.class)) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); @@ -80,7 +81,7 @@ public void testCustomJsonFactoryStringParser() { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); validateFoo(result); diff --git a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java b/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java index 2104bd7b..085ae316 100644 --- a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java +++ b/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java @@ -1,6 +1,7 @@ package com.nytimes.android.external.store.middleware.moshi; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; @@ -8,9 +9,9 @@ import java.lang.reflect.Type; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; import okio.BufferedSource; public class MoshiSourceParser implements Parser { @@ -23,12 +24,11 @@ public MoshiSourceParser(@Nonnull Moshi moshi, @Nonnull Type type) { } @Override - @Nullable - public Parsed call(BufferedSource source) { + public Parsed apply(@NonNull BufferedSource bufferedSource) throws ParserException { try { - return jsonAdapter.fromJson(source); + return jsonAdapter.fromJson(bufferedSource); } catch (IOException e) { - return null; + throw new ParserException(e.getMessage(), e); } } } diff --git a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java b/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java index 23201084..18b6af28 100644 --- a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java +++ b/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java @@ -1,6 +1,7 @@ package com.nytimes.android.external.store.middleware.moshi; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; @@ -8,9 +9,10 @@ import java.lang.reflect.Type; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; + public class MoshiStringParser implements Parser { private final JsonAdapter jsonAdapter; @@ -20,13 +22,13 @@ public MoshiStringParser(@Nonnull Moshi moshi, @Nonnull Type type) { jsonAdapter = moshi.adapter(type); } + @Override - @Nullable - public Parsed call(@Nonnull String source) { + public Parsed apply(@NonNull String s) throws ParserException { try { - return jsonAdapter.fromJson(source); + return jsonAdapter.fromJson(s); } catch (IOException e) { - return null; + throw new ParserException(e.getMessage(), e); } } } diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java index 013a5c17..d88781dd 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java @@ -18,9 +18,9 @@ import java.io.ByteArrayInputStream; import java.nio.charset.Charset; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -74,7 +74,7 @@ public void testSourceParser() throws Exception { .parser(parser) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); assertEquals(result.number, 123); assertEquals(result.string, "abc"); diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java index 278d7fc0..4a8b2b52 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java @@ -15,7 +15,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import rx.Observable; + +import io.reactivex.Observable; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.times; @@ -58,7 +59,7 @@ public void testMoshiString() { .parser(MoshiParserFactory.createStringParser(Foo.class)) .open(); - Foo result = store.get(barCode).toBlocking().first(); + Foo result = store.get(barCode).blockingFirst(); assertEquals(result.number, 123); assertEquals(result.string, "abc"); diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java index 22aad937..4aea30ca 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java @@ -2,13 +2,15 @@ import com.google.gson.Gson; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import java.io.Reader; import java.lang.reflect.Type; -import javax.annotation.Nonnull; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; + import static com.nytimes.android.external.cache.Preconditions.checkNotNull; public class GsonReaderParser implements Parser { @@ -25,7 +27,7 @@ public GsonReaderParser(Gson gson, Type type) { } @Override - public Parsed call(@Nonnull Reader reader) { + public Parsed apply(@NonNull Reader reader) throws ParserException { return gson.fromJson(reader, type); } } diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java index bfb1d79e..53454687 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java @@ -3,15 +3,16 @@ import com.google.gson.Gson; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.nio.charset.Charset; -import javax.annotation.Nonnull; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; import okio.BufferedSource; import static com.nytimes.android.external.cache.Preconditions.checkNotNull; @@ -42,11 +43,11 @@ public GsonSourceParser(Gson gson, Type type) { } @Override - public Parsed call(@Nonnull BufferedSource source) { - try (InputStreamReader reader = new InputStreamReader(source.inputStream(), Charset.forName("UTF-8"))) { + public Parsed apply(@NonNull BufferedSource bufferedSource) throws ParserException { + try (InputStreamReader reader = new InputStreamReader(bufferedSource.inputStream(), Charset.forName("UTF-8"))) { return gson.fromJson(reader, type); } catch (IOException e) { - throw new RuntimeException(e); + throw new ParserException(e.getMessage(), e); } } } diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java index 311ae4f1..3bb76767 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java @@ -2,10 +2,14 @@ import com.google.gson.Gson; import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store.util.ParserException; + import java.lang.reflect.Type; import javax.inject.Inject; +import io.reactivex.annotations.NonNull; + import static com.nytimes.android.external.cache.Preconditions.checkNotNull; public class GsonStringParser implements Parser { @@ -22,7 +26,7 @@ public GsonStringParser(Gson gson, Type parsedClass) { } @Override - public Parsed call(String source) { - return gson.fromJson(source, type); + public Parsed apply(@NonNull String s) throws ParserException { + return gson.fromJson(s, type); } } diff --git a/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java b/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java index 783c6b62..57539f5c 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java @@ -15,9 +15,9 @@ import java.io.ByteArrayInputStream; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static com.google.common.base.Charsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -67,9 +67,9 @@ public void testSimple() { when(persister.write(barCode, source)) .thenReturn(Observable.just(true)); - Foo result = simpleStore.get(barCode).toBlocking().first(); + Foo result = simpleStore.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); - result = simpleStore.get(barCode).toBlocking().first(); + result = simpleStore.get(barCode).blockingFirst(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java b/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java index 637447d5..0af9b6c1 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java @@ -18,9 +18,9 @@ import java.util.Arrays; import java.util.List; +import io.reactivex.Observable; import okio.BufferedSource; import okio.Okio; -import rx.Observable; import static com.google.common.base.Charsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -76,7 +76,7 @@ public void testSimple() { when(persister.write(barCode, source)) .thenReturn(Observable.just(true)); - List result = simpleStore.get(barCode).toBlocking().first(); + List result = simpleStore.get(barCode).blockingFirst(); assertThat(result.get(0).value).isEqualTo("a"); assertThat(result.get(1).value).isEqualTo("b"); assertThat(result.get(2).value).isEqualTo("c"); diff --git a/store/build.gradle b/store/build.gradle index aadc215e..dd8ce145 100644 --- a/store/build.gradle +++ b/store/build.gradle @@ -5,7 +5,7 @@ version = VERSION_NAME dependencies { compile project(path: ':cache') - compile libraries.rxJava + compile libraries.rxJava2 compile libraries.jsr305 testCompile libraries.mockito diff --git a/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java b/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java index aae574d3..5f2ffe9a 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java @@ -2,7 +2,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; + public interface DiskRead { @Nonnull diff --git a/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java b/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java index 0321de5c..6e92877c 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; public interface DiskWrite { /** diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java b/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java index 4fb5325d..586af418 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java @@ -2,7 +2,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; + /** * Interface for fetching new data for a Store diff --git a/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java b/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java index 4faf4fcb..f0bce432 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; /** * this interface allows us to mark a {@link Store} as "internal", exposing methods for retrieving data diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Parser.java b/store/src/main/java/com/nytimes/android/external/store/base/Parser.java index 7c514a77..0a45fc4e 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Parser.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/Parser.java @@ -1,7 +1,14 @@ package com.nytimes.android.external.store.base; -import rx.functions.Func1; +import com.nytimes.android.external.store.util.ParserException; + +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Function; //just a marker interface allowing for a reimplementation of how the parser is implemented -public interface Parser extends Func1 { +public interface Parser extends Function { + + @Override + Parsed apply(@NonNull Raw raw) throws ParserException; + } diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Persister.java b/store/src/main/java/com/nytimes/android/external/store/base/Persister.java index 8846d505..8a44d98c 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Persister.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/Persister.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; /** * Interface for fetching data from persister diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java index 26ba559b..ac8c351f 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java @@ -6,6 +6,8 @@ import java.util.ArrayList; import java.util.List; +import io.reactivex.annotations.NonNull; + import static com.nytimes.android.external.cache.Preconditions.checkArgument; import static com.nytimes.android.external.cache.Preconditions.checkNotNull; @@ -28,12 +30,13 @@ private ParserException createParserException() { } @Override + @NonNull @SuppressWarnings("unchecked") - public Parsed call(Key key, Raw raw) { + public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { Object parsed = raw; for (KeyParser parser : parsers) { try { - parsed = parser.call(key, parsed); + parsed = parser.apply(key, parsed); } catch (ClassCastException exception) { throw createParserException(); } diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java index 6bbc9096..6bba9f8a 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java @@ -17,14 +17,15 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import rx.Observable; -import rx.annotations.Experimental; -import rx.functions.Action0; -import rx.functions.Action1; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.subjects.BehaviorSubject; -import rx.subjects.PublishSubject; +import io.reactivex.Observable; +import io.reactivex.ObservableSource; +import io.reactivex.annotations.Experimental; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Action; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Function; +import io.reactivex.subjects.BehaviorSubject; +import io.reactivex.subjects.PublishSubject; import static com.nytimes.android.external.store.base.impl.StoreUtil.persisterIsStale; import static com.nytimes.android.external.store.base.impl.StoreUtil.shouldReturnNetworkBeforeStale; @@ -41,9 +42,9 @@ final class RealInternalStore implements InternalStore { Cache> inFlightRequests; Cache> memCache; + StalePolicy stalePolicy; Persister persister; KeyParser parser; - StalePolicy stalePolicy; private final PublishSubject refreshSubject = PublishSubject.create(); private Fetcher fetcher; @@ -69,11 +70,11 @@ final class RealInternalStore implements InternalStore maximumInFlightRequestsDuration) { inFlightRequests = CacheBuilder - .newBuilder() - .expireAfterWrite(maximumInFlightRequestsDuration, TimeUnit.SECONDS) - .build(); + .newBuilder() + .expireAfterWrite(maximumInFlightRequestsDuration, TimeUnit.SECONDS) + .build(); } else { inFlightRequests = CacheBuilder.newBuilder() - .expireAfterWrite(memoryPolicy.getExpireAfter(), memoryPolicy.getExpireAfterTimeUnit()) - .build(); + .expireAfterWrite(memoryPolicy.getExpireAfter(), memoryPolicy.getExpireAfterTimeUnit()) + .build(); } } private void initMemCache(MemoryPolicy memoryPolicy) { memCache = CacheBuilder - .newBuilder() - .maximumSize(memoryPolicy.getMaxSize()) - .expireAfterWrite(memoryPolicy.getExpireAfter(), memoryPolicy.getExpireAfterTimeUnit()) - .build(); + .newBuilder() + .maximumSize(memoryPolicy.getMaxSize()) + .expireAfterWrite(memoryPolicy.getExpireAfter(), memoryPolicy.getExpireAfterTimeUnit()) + .build(); } /** @@ -114,8 +115,8 @@ private void initMemCache(MemoryPolicy memoryPolicy) { @Override public Observable get(@Nonnull final Key key) { return Observable.concat( - lazyCache(key), - fetch(key) + lazyCache(key), + fetch(key) ).take(1); } @@ -124,7 +125,7 @@ public Observable get(@Nonnull final Key key) { @Experimental public Observable getRefreshing(@Nonnull final Key key) { return get(key) - .compose(StoreUtil.repeatWhenCacheEvicted(refreshSubject, key)); + .compose(StoreUtil.repeatWhenCacheEvicted(refreshSubject, key)); } @@ -133,13 +134,13 @@ public Observable getRefreshing(@Nonnull final Key key) { */ private Observable lazyCache(@Nonnull final Key key) { return Observable - .defer(new Func0>() { - @Override - public Observable call() { - return cache(key); - } - }) - .onErrorResumeNext(new OnErrorResumeWithEmpty()); + .defer(new Callable>() { + @Override + public ObservableSource call() { + return cache(key); + } + }) + .onErrorResumeNext(new OnErrorResumeWithEmpty()); } Observable cache(@Nonnull final Key key) { @@ -147,8 +148,7 @@ Observable cache(@Nonnull final Key key) { return memCache.get(key, new Callable>() { @Nonnull @Override - @SuppressWarnings("PMD.SignatureDeclareThrowsException") - public Observable call() throws Exception { + public Observable call() { return disk(key); } }); @@ -184,35 +184,36 @@ public Observable disk(@Nonnull final Key key) { Observable readDisk(@Nonnull final Key key) { return persister().read(key) - .onErrorResumeNext(new OnErrorResumeWithEmpty()) - .map(new Func1() { - @Override - public Parsed call(Raw raw) { - return parser.call(key, raw); - } - }) - .doOnNext(new Action1() { - @Override - public void call(Parsed parsed) { - updateMemory(key, parsed); - if (stalePolicy == StalePolicy.REFRESH_ON_STALE - && persisterIsStale(key, persister)) { - backfillCache(key); + .onErrorResumeNext(new OnErrorResumeWithEmpty()) + .map(new Function() { + @Override + public Parsed apply(@NonNull Raw raw) { + return parser.apply(key, raw); } - } - }).cache(); + }) + .doOnNext(new Consumer() { + @Override + public void accept(@NonNull Parsed parsed) { + updateMemory(key, parsed); + if (stalePolicy == StalePolicy.REFRESH_ON_STALE + && persisterIsStale(key, persister)) { + backfillCache(key); + } + } + }).cache(); } + @SuppressWarnings("CheckReturnValue") void backfillCache(@Nonnull Key key) { - fetch(key).subscribe(new Action1() { + fetch(key).subscribe(new Consumer() { @Override - public void call(Parsed parsed) { - //do Nothing we are just backfilling cache + public void accept(@NonNull Parsed parsed) { + // do Nothing we are just backfilling cache } - }, new Action1() { + }, new Consumer() { @Override - public void call(Throwable throwable) { - //do nothing as we are just backfilling cache + public void accept(@NonNull Throwable throwable) { + // do nothing as we are just backfilling cache } }); } @@ -227,10 +228,9 @@ public void call(Throwable throwable) { @Nonnull @Override public Observable fetch(@Nonnull final Key key) { - return Observable.defer(new Func0>() { - @Nullable + return Observable.defer(new Callable>() { @Override - public Observable call() { + public ObservableSource call() { return fetchAndPersist(key); } }); @@ -264,41 +264,41 @@ public Observable call() { @Nonnull Observable response(@Nonnull final Key key) { return fetcher() - .fetch(key) - .flatMap(new Func1>() { - @Override - public Observable call(Raw raw) { - return persister().write(key, raw) - .flatMap(new Func1>() { - @Override - public Observable call(Boolean aBoolean) { - return readDisk(key); - } - }); - } - }) - .onErrorResumeNext(new Func1>() { - @Override - public Observable call(Throwable throwable) { - if (stalePolicy == StalePolicy.NETWORK_BEFORE_STALE) { - return readDisk(key); + .fetch(key) + .flatMap(new Function>() { + @Override + public ObservableSource apply(@NonNull Raw raw) { + return persister().write(key, raw) + .flatMap(new Function>() { + @Override + public ObservableSource apply(@NonNull Boolean aBoolean) { + return readDisk(key); + } + }); } - return Observable.error(throwable); - } - }) - .doOnNext(new Action1() { - @Override - public void call(Parsed data) { - notifySubscribers(data); - } - }) - .doOnTerminate(new Action0() { - @Override - public void call() { - inFlightRequests.invalidate(key); - } - }) - .cache(); + }) + .onErrorResumeNext(new Function>() { + @Override + public ObservableSource apply(@NonNull Throwable throwable) { + if (stalePolicy == StalePolicy.NETWORK_BEFORE_STALE) { + return readDisk(key); + } + return Observable.error(throwable); + } + }) + .doOnNext(new Consumer() { + @Override + public void accept(@NonNull Parsed parsed) { + notifySubscribers(parsed); + } + }) + .doOnTerminate(new Action() { + @Override + public void run() { + inFlightRequests.invalidate(key); + } + }) + .cache(); } void notifySubscribers(Parsed data) { @@ -314,7 +314,7 @@ void notifySubscribers(Parsed data) { @Override public Observable stream(@Nonnull Key key) { - Observable stream = subject.asObservable(); + Observable stream = subject.hide(); //If nothing was emitted through the subject yet, start stream with get() value if (!subject.hasValue()) { @@ -327,7 +327,7 @@ public Observable stream(@Nonnull Key key) { @Nonnull @Override public Observable stream() { - return subject.asObservable(); + return subject.hide(); } /** diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java index b5de574c..e28b2e41 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java @@ -12,7 +12,8 @@ import javax.annotation.Nonnull; -import rx.Observable; + +import io.reactivex.Observable; import static com.nytimes.android.external.store.base.impl.StalePolicy.UNSPECIFIED; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java index 0714e637..4a1b364e 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java @@ -16,7 +16,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; + /** * Builder where there parser is used. diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java index 0a018e2a..4a2caa21 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java @@ -2,8 +2,11 @@ import javax.annotation.Nonnull; -import rx.Observable; -import rx.functions.Func1; +import io.reactivex.Observable; +import io.reactivex.ObservableSource; +import io.reactivex.ObservableTransformer; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Function; import static com.nytimes.android.external.cache.Preconditions.checkNotNull; @@ -11,7 +14,7 @@ * A Transformer that takes a source observable and re-subscribes to the upstream Observable when * it emits. */ -final class RepeatWhenEmits implements Observable.Transformer { +final class RepeatWhenEmits implements ObservableTransformer { private final Observable source; @@ -25,13 +28,13 @@ static RepeatWhenEmits from(@Nonnull Observable source) { } @Override - public Observable call(Observable upstream) { - return upstream.repeatWhen(new Func1, Observable>() { + public ObservableSource apply(Observable upstream) { + return upstream.repeatWhen(new Function, ObservableSource>() { @Override - public Observable call(Observable events) { - return events.switchMap(new Func1>() { + public ObservableSource apply(@NonNull Observable objectObservable) { + return objectObservable.switchMap(new Function>() { @Override - public Observable call(Void aVoid) { + public ObservableSource apply(@NonNull Object o) { return source; } }); diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java index 9a2eb52a..3e1f71ea 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java @@ -3,8 +3,9 @@ import javax.annotation.Nonnull; -import rx.Observable; -import rx.annotations.Experimental; +import io.reactivex.Observable; +import io.reactivex.annotations.Experimental; + /** * a {@link com.nytimes.android.external.store.base.impl.StoreBuilder StoreBuilder} diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java index 1b2f5118..3c11795e 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import rx.annotations.Beta; +import io.reactivex.annotations.Beta; /** diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java b/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java index 9d761c1f..7ccfa831 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java +++ b/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java @@ -6,9 +6,12 @@ import javax.annotation.Nonnull; -import rx.Observable; -import rx.functions.Func1; -import rx.subjects.PublishSubject; +import io.reactivex.Observable; +import io.reactivex.ObservableTransformer; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Predicate; +import io.reactivex.subjects.PublishSubject; + import static com.nytimes.android.external.store.base.RecordState.STALE; @@ -17,11 +20,11 @@ private StoreUtil() { } @Nonnull - static Observable.Transformer + static ObservableTransformer repeatWhenCacheEvicted(PublishSubject refreshSubject, @Nonnull final Key keyForRepeat) { - Observable filter = refreshSubject.filter(new Func1() { + Observable filter = refreshSubject.filter(new Predicate() { @Override - public Boolean call(Key key) { + public boolean test(@NonNull Key key) throws Exception { return key.equals(keyForRepeat); } }); diff --git a/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java b/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java index a3a8b288..6b3a1980 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java @@ -1,13 +1,11 @@ package com.nytimes.android.external.store.util; -import javax.annotation.Nonnull; - -import rx.functions.Func2; - -public interface KeyParser extends Func2 { +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.BiFunction; +public interface KeyParser extends BiFunction { @Override - @Nonnull - Parsed call(@Nonnull Key key, @Nonnull Raw raw); + Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException; + } diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java b/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java index 6b301321..49c139da 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java @@ -4,6 +4,8 @@ import javax.annotation.Nonnull; +import io.reactivex.annotations.NonNull; + public class NoKeyParser implements KeyParser { private final Parser parser; @@ -12,8 +14,7 @@ public NoKeyParser(@Nonnull Parser parser) { } @Override - @Nonnull - public Parsed call(@Nonnull Key key, @Nonnull Raw raw) { - return parser.call(raw); + public Parsed apply(@NonNull Key key, @NonNull Raw raw) throws ParserException { + return parser.apply(raw); } } diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java b/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java index 9373bd26..fad5167e 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java @@ -2,12 +2,15 @@ import com.nytimes.android.external.store.base.Parser; +import io.reactivex.annotations.NonNull; + /** * Pass-through parser for stores that parse externally */ public class NoopParserFunc implements Parser { + @Override - public Object call(Object object) { - return object; + public Parsed apply(@NonNull Raw raw) throws ParserException { + return (Parsed) raw; } } diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java b/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java index 0bd60215..6615dc9b 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java @@ -11,7 +11,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; + /** * Pass-through diskdao for stores that don't want to use persister diff --git a/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java b/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java index e1025afd..a42589a0 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java @@ -1,15 +1,17 @@ package com.nytimes.android.external.store.util; -import rx.Observable; -import rx.functions.Func1; + +import io.reactivex.Observable; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Function; /** * Resume with empty observable on error */ -public class OnErrorResumeWithEmpty implements Func1> { +public class OnErrorResumeWithEmpty implements Function> { @Override - public Observable call(Throwable throwable) { + public Observable apply(@NonNull Throwable throwable) { return Observable.empty(); } } diff --git a/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java b/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java index d3ea2298..4b7099b7 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java +++ b/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java @@ -5,7 +5,15 @@ */ public class ParserException extends RuntimeException { + public ParserException(Throwable cause) { + super(cause); + } + public ParserException(String message) { super(message); } + + public ParserException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java b/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java index 93b9472c..ff70c962 100644 --- a/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java @@ -12,7 +12,8 @@ import javax.annotation.Nonnull; -import rx.Observable; + +import io.reactivex.Observable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java b/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java index 951faa9b..426cb9fb 100644 --- a/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java @@ -16,7 +16,8 @@ import javax.annotation.Nonnull; -import rx.Observable; + +import io.reactivex.Observable; import static com.nytimes.android.external.store.GetRefreshingTest.ClearingPersister; import static org.assertj.core.api.Assertions.assertThat; diff --git a/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java b/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java index 89d3b196..bc327d06 100644 --- a/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java @@ -12,7 +12,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; + public class DontCacheErrorsTest { @@ -47,12 +48,13 @@ public void testStoreDoesntCacheErrors() throws InterruptedException { shouldThrow = true; store.get(barcode).test() - .awaitTerminalEvent() - .assertError(Exception.class); + .assertTerminated() + .assertError(Exception.class) + .awaitTerminalEvent(); shouldThrow = false; store.get(barcode).test() - .awaitTerminalEvent() - .assertNoErrors(); + .assertNoErrors() + .awaitTerminalEvent(); } } diff --git a/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java b/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java index 48353c42..e2a9b271 100644 --- a/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java @@ -18,8 +18,8 @@ import javax.annotation.Nonnull; -import rx.Observable; -import rx.observers.AssertableSubscriber; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -63,16 +63,16 @@ public void testRefreshOnClear() { when(persister.write(barcode, 2)).thenReturn(Observable.just(true)); - AssertableSubscriber refreshingObservable = store.getRefreshing(barcode).test(); - assertThat(refreshingObservable.getValueCount()).isEqualTo(1); + TestObserver refreshingObservable = store.getRefreshing(barcode).test(); + refreshingObservable.assertValueCount(1); assertThat(networkCalls.intValue()).isEqualTo(1); //clearing the store should produce another network call store.clear(barcode); - assertThat(refreshingObservable.getValueCount()).isEqualTo(2); + refreshingObservable.assertValueCount(2); assertThat(networkCalls.intValue()).isEqualTo(2); store.get(barcode).test().awaitTerminalEvent(); - assertThat(refreshingObservable.getValueCount()).isEqualTo(2); + refreshingObservable.assertValueCount(2); assertThat(networkCalls.intValue()).isEqualTo(2); } @@ -98,10 +98,10 @@ public void testRefreshOnClearAll() { when(persister.write(barcode2, 1)).thenReturn(Observable.just(true)); when(persister.write(barcode2, 2)).thenReturn(Observable.just(true)); - AssertableSubscriber testObservable1 = store.getRefreshing(barcode1).test(); - AssertableSubscriber testObservable2 = store.getRefreshing(barcode2).test(); - assertThat(testObservable1.getValueCount()).isEqualTo(1); - assertThat(testObservable2.getValueCount()).isEqualTo(1); + TestObserver testObservable1 = store.getRefreshing(barcode1).test(); + TestObserver testObservable2 = store.getRefreshing(barcode2).test(); + testObservable1.assertValueCount(1); + testObservable2.assertValueCount(1); assertThat(networkCalls.intValue()).isEqualTo(2); diff --git a/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java b/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java index 925b04f0..495f6d83 100644 --- a/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java @@ -12,8 +12,10 @@ import javax.annotation.Nonnull; -import rx.Observable; -import rx.observers.AssertableSubscriber; +import io.reactivex.Observable; +import io.reactivex.annotations.NonNull; +import io.reactivex.observers.TestObserver; + @RunWith(MockitoJUnitRunner.class) public class KeyParserTest { @@ -27,7 +29,7 @@ public void setUp() throws Exception { store = StoreBuilder.parsedWithKey() .parser(new KeyParser() { @Override - public String call(Integer integer, String s) { + public String apply(@NonNull Integer integer, @NonNull String s) { return s + integer; } }) @@ -42,12 +44,11 @@ public Observable fetch(@Nonnull Integer integer) { } @Test + @SuppressWarnings("PMD.SignatureDeclareThrowsException") public void testStoreWithKeyParserFuncNoPersister() throws Exception { - AssertableSubscriber testObservable = store.get(KEY).test().awaitTerminalEvent(); + TestObserver testObservable = store.get(KEY).test().await(); testObservable.assertNoErrors() .assertValues(NETWORK + KEY) - .assertUnsubscribed(); - - + .awaitTerminalEvent(); } } diff --git a/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java b/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java index 135b042a..ccaa85ad 100644 --- a/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java @@ -12,7 +12,8 @@ import javax.annotation.Nonnull; -import rx.Observable; + +import io.reactivex.Observable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java b/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java index 8e045e31..fdf83b0d 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java @@ -14,7 +14,8 @@ import javax.annotation.Nonnull; -import rx.Observable; +import io.reactivex.Observable; +import io.reactivex.annotations.NonNull; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +49,7 @@ public Observable write(@Nonnull Integer key, @Nonnull String s) { }) .parser(new Parser() { @Override - public Date call(String s) { + public Date apply(@NonNull String s) { return DATE; } }) @@ -73,9 +74,9 @@ public Observable fetch(@Nonnull Integer key) { } }) .open(); - Date result = store.get(5).toBlocking().first(); - result = barCodeStore.get(new BarCode("test", "5")).toBlocking().first(); - result = keyStore.get(5).toBlocking().first(); + Date result = store.get(5).blockingFirst(); + result = barCodeStore.get(new BarCode("test", "5")).blockingFirst(); + result = keyStore.get(5).blockingFirst(); assertThat(result).isNotNull(); } diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreTest.java b/store/src/test/java/com/nytimes/android/external/store/StoreTest.java index a17ce930..876ccfce 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/StoreTest.java @@ -4,9 +4,9 @@ import com.nytimes.android.external.cache.CacheBuilder; import com.nytimes.android.external.store.base.Fetcher; import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; import com.nytimes.android.external.store.base.impl.BarCode; import com.nytimes.android.external.store.base.impl.RealStore; +import com.nytimes.android.external.store.base.impl.Store; import com.nytimes.android.external.store.base.impl.StoreBuilder; import com.nytimes.android.external.store.util.NoopPersister; @@ -18,10 +18,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import rx.Emitter; -import rx.Observable; -import rx.functions.Action1; -import rx.functions.Func2; +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.BiFunction; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.spy; @@ -65,10 +66,10 @@ public void testSimple() { when(persister.write(barCode, NETWORK)) .thenReturn(Observable.just(true)); - String value = simpleStore.get(barCode).toBlocking().first(); + String value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(DISK); - value = simpleStore.get(barCode).toBlocking().first(); + value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(DISK); verify(fetcher, times(1)).fetch(barCode); } @@ -83,9 +84,9 @@ public void testDoubleTap() { .open(); Observable networkObservable = - Observable.fromEmitter(new Action1>() { + Observable.create(new ObservableOnSubscribe() { @Override - public void call(Emitter emitter) { + public void subscribe(ObservableEmitter emitter) { if (counter.incrementAndGet() == 1) { emitter.onNext(NETWORK); @@ -93,7 +94,9 @@ public void call(Emitter emitter) { emitter.onError(new RuntimeException("Yo Dawg your inflight is broken")); } } - }, Emitter.BackpressureMode.NONE); + }); + + when(fetcher.fetch(barCode)) .thenReturn(networkObservable); @@ -106,14 +109,13 @@ public void call(Emitter emitter) { String response = simpleStore.get(barCode).zipWith(simpleStore.get(barCode), - new Func2() { + new BiFunction() { @Override - public String call(String s, String s2) { + public String apply(@NonNull String s, @NonNull String s2) { return "hello"; } }) - .toBlocking() - .first(); + .blockingFirst(); assertThat(response).isEqualTo("hello"); verify(fetcher, times(1)).fetch(barCode); } @@ -133,9 +135,9 @@ public void testSubclass() { .thenReturn(Observable.just(DISK)); when(persister.write(barCode, NETWORK)).thenReturn(Observable.just(true)); - String value = simpleStore.get(barCode).toBlocking().first(); + String value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(DISK); - value = simpleStore.get(barCode).toBlocking().first(); + value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(DISK); verify(fetcher, times(1)).fetch(barCode); } @@ -151,14 +153,14 @@ public void testNoopAndDefault() { when(fetcher.fetch(barCode)) .thenReturn(Observable.just(NETWORK)); - String value = simpleStore.get(barCode).toBlocking().first(); + String value = simpleStore.get(barCode).blockingFirst(); verify(fetcher, times(1)).fetch(barCode); verify(persister, times(1)).write(barCode, NETWORK); verify(persister, times(2)).read(barCode); assertThat(value).isEqualTo(NETWORK); - value = simpleStore.get(barCode).toBlocking().first(); + value = simpleStore.get(barCode).blockingFirst(); verify(persister, times(2)).read(barCode); verify(persister, times(1)).write(barCode, NETWORK); verify(fetcher, times(1)).fetch(barCode); diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java b/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java index cab9500d..54207b3c 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java @@ -11,7 +11,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import rx.Observable; + +import io.reactivex.Observable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; @@ -32,7 +33,7 @@ public class StoreWithParserTest { private final BarCode barCode = new BarCode("key", "value"); @Test - public void testSimple() { + public void testSimple() throws Exception { MockitoAnnotations.initMocks(this); @@ -52,17 +53,17 @@ public void testSimple() { when(persister.write(barCode, NETWORK)) .thenReturn(Observable.just(true)); - when(parser.call(DISK)).thenReturn(barCode.getKey()); + when(parser.apply(DISK)).thenReturn(barCode.getKey()); - String value = simpleStore.get(barCode).toBlocking().first(); + String value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(barCode.getKey()); - value = simpleStore.get(barCode).toBlocking().first(); + value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(barCode.getKey()); verify(fetcher, times(1)).fetch(barCode); } @Test - public void testSubclass() { + public void testSubclass() throws Exception { MockitoAnnotations.initMocks(this); Store simpleStore = new SampleParsingStore(fetcher, persister, parser); @@ -77,11 +78,11 @@ public void testSubclass() { when(persister.write(barCode, NETWORK)) .thenReturn(Observable.just(true)); - when(parser.call(DISK)).thenReturn(barCode.getKey()); + when(parser.apply(DISK)).thenReturn(barCode.getKey()); - String value = simpleStore.get(barCode).toBlocking().first(); + String value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(barCode.getKey()); - value = simpleStore.get(barCode).toBlocking().first(); + value = simpleStore.get(barCode).blockingFirst(); assertThat(value).isEqualTo(barCode.getKey()); verify(fetcher, times(1)).fetch(barCode); } diff --git a/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java b/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java index ef5a7f27..a9b6557f 100644 --- a/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java @@ -19,21 +19,21 @@ public class MultiParserTest { private static final Parser PARSER_1 = new Parser() { @Override - public String call(Integer value) { + public String apply(Integer value) { return String.valueOf(value); } }; private static final Parser PARSER_2 = new Parser() { @Override - public BarCode call(String value) { + public BarCode apply(String value) { return new BarCode(value, "KEY"); } }; private static final Parser PARSER_3 = new Parser() { @Override - public UUID call(BarCode barCode) { + public UUID apply(BarCode barCode) { return UUID.randomUUID(); } }; @@ -49,7 +49,7 @@ public void shouldParseChainProperly() { parsersChain.add(new NoKeyParser<>(PARSER_3)); KeyParser parser = new MultiParser<>(parsersChain); - UUID parsed = parser.call(new Object(), 100); + UUID parsed = parser.apply(new Object(), 100); assertNotNull(parsed); } @@ -64,7 +64,7 @@ public void shouldFailIfOneOfParsersIsInvalid() { parsersChain.add(new NoKeyParser<>(PARSER_2)); KeyParser parser = new MultiParser<>(parsersChain); - UUID parsed = parser.call(new Object(), 100); + UUID parsed = parser.apply(new Object(), 100); assertNotNull(parsed); } diff --git a/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java b/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java index e9e83ba1..729647b7 100644 --- a/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java @@ -4,9 +4,9 @@ import java.util.concurrent.Callable; -import rx.Observable; -import rx.observers.AssertableSubscriber; -import rx.subjects.PublishSubject; +import io.reactivex.Observable; +import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.PublishSubject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -25,7 +25,7 @@ public void testTransformer() throws Exception { // create an observable and apply the transformer to test PublishSubject source = PublishSubject.create(); - AssertableSubscriber testSubscriber = Observable.fromCallable(mockCallable) + TestObserver testSubscriber = Observable.fromCallable(mockCallable) .compose(RepeatWhenEmits.from(source)) .test(); diff --git a/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java b/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java index 6e374db6..9e45724b 100644 --- a/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java +++ b/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java @@ -12,11 +12,10 @@ public class NoopPersisterTest { @Test public void writeReadTest() { - NoopPersister persister = NoopPersister.create(); - boolean success = persister.write(barCode, "foo").toBlocking().first(); + boolean success = persister.write(barCode, "foo").blockingFirst(); assertThat(success).isTrue(); - String rawValue = persister.read(barCode).toBlocking().first(); + String rawValue = persister.read(barCode).blockingFirst(); assertThat(rawValue).isEqualTo("foo"); } @@ -24,7 +23,7 @@ public void writeReadTest() { public void noopParserFuncTest() { NoopParserFunc noopParserFunc = new NoopParserFunc<>(); String input = "foo"; - String output = (String) noopParserFunc.call(input); + String output = (String) noopParserFunc.apply(input); assertThat(input).isEqualTo(output); //intended object ref comparison assertThat(input).isSameAs(output); From f009e11a0b89adef35f4152006e021ad2098af91 Mon Sep 17 00:00:00 2001 From: Mike Nakhimovich Date: Thu, 23 Mar 2017 17:48:16 -0400 Subject: [PATCH 2/3] Feature/rx2 package rename (#171) * first pass at store2 artifacts --- .../com/nytimes/android/sample/SampleApp.java | 14 +++++----- .../activity/PersistingStoreActivity.java | 4 +-- .../sample/activity/StoreActivity.java | 4 +-- .../android/sample/StoreIntegrationTest.java | 6 ++--- build.gradle | 6 ++--- filesystem/gradle.properties | 2 +- .../{fs => fs2}/BarCodePathResolver.java | 4 +-- .../external/{fs => fs2}/FSReader.java | 6 ++--- .../external/{fs => fs2}/FSWriter.java | 6 ++--- .../{fs => fs2}/FileSystemPersister.java | 6 ++--- .../FileSystemPersisterFactory.java | 16 ++++++------ .../FileSystemRecordPersister.java | 10 +++---- .../external/{fs => fs2}/PathResolver.java | 2 +- .../external/{fs => fs2}/RecordPersister.java | 10 +++---- .../{fs => fs2}/RecordPersisterFactory.java | 14 +++++----- .../{fs => fs2}/SourceFileReader.java | 12 ++++----- .../{fs => fs2}/SourceFileWriter.java | 8 +++--- .../external/{fs => fs2}/SourcePersister.java | 8 +++--- .../{fs => fs2}/SourcePersisterFactory.java | 18 ++++++------- .../android/external/{fs => fs2}/Util.java | 2 +- .../BreadthFirstFileTreeIterator.java | 2 +- .../{fs => fs2}/filesystem/FSFile.java | 4 +-- .../{fs => fs2}/filesystem/FileSystem.java | 4 +-- .../filesystem/FileSystemFactory.java | 2 +- .../filesystem/FileSystemImpl.java | 6 ++--- .../{fs => fs2}/FilePersisterTest.java | 8 +++--- .../FileSystemRecordPersisterTest.java | 8 +++--- .../external/{fs => fs2}/MultiTest.java | 6 ++--- .../{fs => fs2}/RecordPersisterTest.java | 8 +++--- .../{fs => fs2}/SourceDiskDaoStoreTest.java | 12 ++++----- .../SourceFilerReaderWriterStoreTest.java | 12 ++++----- .../{fs => fs2}/SourcePersisterTest.java | 6 ++--- .../StoreNetworkBeforeStaleTest.java | 12 ++++----- .../StoreRefreshWhenStaleTest.java | 12 ++++----- .../external/{fs => fs2}/UtilTest.java | 2 +- .../BreadthFirstFileTreeIteratorTest.java | 2 +- .../external/{fs => fs2}/impl/SimpleTest.java | 8 +++--- middleware-jackson/gradle.properties | 2 +- .../jackson/JacksonParserFactory.java | 4 +-- .../jackson/JacksonReaderParser.java | 6 ++--- .../jackson/JacksonSourceParser.java | 6 ++--- .../jackson/JacksonStringParser.java | 6 ++--- .../jackson/JacksonReaderParserStoreTest.java | 16 ++++++------ .../jackson/JacksonSourceParserStoreTest.java | 16 ++++++------ .../jackson/JacksonStringParserStoreTest.java | 16 ++++++------ .../middleware/jackson/data/Bar.java | 2 +- .../middleware/jackson/data/Foo.java | 2 +- middleware-moshi/gradle.properties | 2 +- .../middleware/moshi/MoshiParserFactory.java | 4 +-- .../middleware/moshi/MoshiSourceParser.java | 6 ++--- .../middleware/moshi/MoshiStringParser.java | 6 ++--- .../moshi/MoshiSourceParserTest.java | 18 ++++++------- .../moshi/MoshiStringParserStoreTest.java | 16 ++++++------ .../middleware/moshi/data/Bar.java | 2 +- .../middleware/moshi/data/Foo.java | 2 +- middleware/gradle.properties | 2 +- .../middleware/GsonParserFactory.java | 4 +-- .../middleware/GsonReaderParser.java | 6 ++--- .../middleware/GsonSourceParser.java | 6 ++--- .../middleware/GsonStringParser.java | 6 ++--- .../GenericParserStoreTest.java | 16 ++++++------ .../GsonParserFactoryTest.java | 4 +-- .../GsonSourceListParserTest.java | 16 ++++++------ store/gradle.properties | 2 +- .../{store => store2}/base/Clearable.java | 2 +- .../{store => store2}/base/DiskRead.java | 2 +- .../{store => store2}/base/DiskWrite.java | 2 +- .../{store => store2}/base/Fetcher.java | 2 +- .../{store => store2}/base/InternalStore.java | 6 ++--- .../{store => store2}/base/Parser.java | 4 +-- .../{store => store2}/base/Persister.java | 2 +- .../base/RecordProvider.java | 2 +- .../{store => store2}/base/RecordState.java | 2 +- .../{store => store2}/base/impl/BarCode.java | 7 ++--- .../base/impl/MemoryPolicy.java | 10 ++++--- .../base/impl/MultiParser.java | 6 ++--- .../base/impl/ParsingStoreBuilder.java | 2 +- .../base/impl/RealInternalStore.java | 21 +++++++-------- .../base/impl/RealStore.java | 26 +++++++++---------- .../base/impl/RealStoreBuilder.java | 24 ++++++++--------- .../base/impl/RepeatWhenEmits.java | 2 +- .../base/impl/StalePolicy.java | 2 +- .../{store => store2}/base/impl/Store.java | 4 +-- .../base/impl/StoreBuilder.java | 2 +- .../base/impl/StoreUtil.java | 10 +++---- .../{store => store2}/util/KeyParser.java | 2 +- .../{store => store2}/util/NoKeyParser.java | 4 +-- .../util/NoopParserFunc.java | 4 +-- .../{store => store2}/util/NoopPersister.java | 8 +++--- .../util/OnErrorResumeWithEmpty.java | 2 +- .../util/ParserException.java | 2 +- .../external/store/SampleParsingStore.java | 17 ------------ .../android/external/store/SampleStore.java | 13 ---------- .../ClearStoreMemoryTest.java | 10 +++---- .../{store => store2}/ClearStoreTest.java | 12 ++++----- .../DontCacheErrorsTest.java | 10 +++---- .../{store => store2}/GetRefreshingTest.java | 16 ++++++------ .../{store => store2}/KeyParserTest.java | 10 +++---- .../external/store2/SampleParsingStore.java | 17 ++++++++++++ .../android/external/store2/SampleStore.java | 13 ++++++++++ .../{store => store2}/SequentialTest.java | 10 +++---- .../{store => store2}/StoreBuilderTest.java | 14 +++++----- .../external/{store => store2}/StoreTest.java | 16 ++++++------ .../StoreWithParserTest.java | 16 ++++++------ .../base/impl/MultiParserTest.java | 10 +++---- .../base/impl/RepeatWhenEmitsTest.java | 2 +- .../util/NoopPersisterTest.java | 4 +-- 107 files changed, 407 insertions(+), 411 deletions(-) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/BarCodePathResolver.java (67%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/FSReader.java (90%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/FSWriter.java (87%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/FileSystemPersister.java (89%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/FileSystemPersisterFactory.java (84%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/FileSystemRecordPersister.java (89%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/PathResolver.java (88%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/RecordPersister.java (78%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/RecordPersisterFactory.java (77%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/SourceFileReader.java (64%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/SourceFileWriter.java (52%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/SourcePersister.java (86%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/SourcePersisterFactory.java (79%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/Util.java (98%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/filesystem/BreadthFirstFileTreeIterator.java (98%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/filesystem/FSFile.java (95%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/filesystem/FileSystem.java (97%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/filesystem/FileSystemFactory.java (91%) rename filesystem/src/main/java/com/nytimes/android/external/{fs => fs2}/filesystem/FileSystemImpl.java (96%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/FilePersisterTest.java (91%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/FileSystemRecordPersisterTest.java (93%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/MultiTest.java (92%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/RecordPersisterTest.java (92%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/SourceDiskDaoStoreTest.java (85%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/SourceFilerReaderWriterStoreTest.java (86%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/SourcePersisterTest.java (91%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/StoreNetworkBeforeStaleTest.java (90%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/StoreRefreshWhenStaleTest.java (89%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/UtilTest.java (97%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/filesystem/BreadthFirstFileTreeIteratorTest.java (97%) rename filesystem/src/test/java/com/nytimes/android/external/{fs => fs2}/impl/SimpleTest.java (95%) rename middleware-jackson/src/main/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonParserFactory.java (97%) rename middleware-jackson/src/main/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonReaderParser.java (86%) rename middleware-jackson/src/main/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonSourceParser.java (89%) rename middleware-jackson/src/main/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonStringParser.java (86%) rename middleware-jackson/src/test/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonReaderParserStoreTest.java (88%) rename middleware-jackson/src/test/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonSourceParserStoreTest.java (89%) rename middleware-jackson/src/test/java/com/nytimes/android/external/{store => store2}/middleware/jackson/JacksonStringParserStoreTest.java (87%) rename middleware-jackson/src/test/java/com/nytimes/android/external/{store => store2}/middleware/jackson/data/Bar.java (67%) rename middleware-jackson/src/test/java/com/nytimes/android/external/{store => store2}/middleware/jackson/data/Foo.java (81%) rename middleware-moshi/src/main/java/com/nytimes/android/external/{store => store2}/middleware/moshi/MoshiParserFactory.java (94%) rename middleware-moshi/src/main/java/com/nytimes/android/external/{store => store2}/middleware/moshi/MoshiSourceParser.java (81%) rename middleware-moshi/src/main/java/com/nytimes/android/external/{store => store2}/middleware/moshi/MoshiStringParser.java (80%) rename middleware-moshi/src/test/java/com/nytimes/android/external/{store => store2}/middleware/moshi/MoshiSourceParserTest.java (85%) rename middleware-moshi/src/test/java/com/nytimes/android/external/{store => store2}/middleware/moshi/MoshiStringParserStoreTest.java (84%) rename middleware-moshi/src/test/java/com/nytimes/android/external/{store => store2}/middleware/moshi/data/Bar.java (63%) rename middleware-moshi/src/test/java/com/nytimes/android/external/{store => store2}/middleware/moshi/data/Foo.java (80%) rename middleware/src/main/java/com/nytimes/android/external/{store => store2}/middleware/GsonParserFactory.java (95%) rename middleware/src/main/java/com/nytimes/android/external/{store => store2}/middleware/GsonReaderParser.java (80%) rename middleware/src/main/java/com/nytimes/android/external/{store => store2}/middleware/GsonSourceParser.java (89%) rename middleware/src/main/java/com/nytimes/android/external/{store => store2}/middleware/GsonStringParser.java (80%) rename middleware/src/test/java/com/nytimes/android/external/{store => store2}/GenericParserStoreTest.java (82%) rename middleware/src/test/java/com/nytimes/android/external/{store => store2}/GsonParserFactoryTest.java (94%) rename middleware/src/test/java/com/nytimes/android/external/{store => store2}/GsonSourceListParserTest.java (84%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/Clearable.java (83%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/DiskRead.java (76%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/DiskWrite.java (88%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/Fetcher.java (89%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/InternalStore.java (60%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/Parser.java (73%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/Persister.java (94%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/RecordProvider.java (73%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/RecordState.java (52%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/BarCode.java (87%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/MemoryPolicy.java (86%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/MultiParser.java (88%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/ParsingStoreBuilder.java (85%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/RealInternalStore.java (94%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/RealStore.java (82%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/RealStoreBuilder.java (86%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/RepeatWhenEmits.java (96%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/StalePolicy.java (60%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/Store.java (94%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/StoreBuilder.java (93%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/base/impl/StoreUtil.java (81%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/KeyParser.java (84%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/NoKeyParser.java (80%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/NoopParserFunc.java (73%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/NoopPersister.java (89%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/OnErrorResumeWithEmpty.java (89%) rename store/src/main/java/com/nytimes/android/external/{store => store2}/util/ParserException.java (88%) delete mode 100644 store/src/test/java/com/nytimes/android/external/store/SampleParsingStore.java delete mode 100644 store/src/test/java/com/nytimes/android/external/store/SampleStore.java rename store/src/test/java/com/nytimes/android/external/{store => store2}/ClearStoreMemoryTest.java (87%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/ClearStoreTest.java (91%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/DontCacheErrorsTest.java (84%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/GetRefreshingTest.java (92%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/KeyParserTest.java (84%) create mode 100644 store/src/test/java/com/nytimes/android/external/store2/SampleParsingStore.java create mode 100644 store/src/test/java/com/nytimes/android/external/store2/SampleStore.java rename store/src/test/java/com/nytimes/android/external/{store => store2}/SequentialTest.java (84%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/StoreBuilderTest.java (86%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/StoreTest.java (92%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/StoreWithParserTest.java (86%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/base/impl/MultiParserTest.java (86%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/base/impl/RepeatWhenEmitsTest.java (95%) rename store/src/test/java/com/nytimes/android/external/{store => store2}/util/NoopPersisterTest.java (88%) diff --git a/app/src/main/java/com/nytimes/android/sample/SampleApp.java b/app/src/main/java/com/nytimes/android/sample/SampleApp.java index a3618b0f..2feefda4 100644 --- a/app/src/main/java/com/nytimes/android/sample/SampleApp.java +++ b/app/src/main/java/com/nytimes/android/sample/SampleApp.java @@ -4,13 +4,13 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.nytimes.android.external.fs.SourcePersisterFactory; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.MemoryPolicy; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.GsonParserFactory; +import com.nytimes.android.external.fs2.SourcePersisterFactory; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.MemoryPolicy; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.GsonParserFactory; import com.nytimes.android.sample.data.model.GsonAdaptersModel; import com.nytimes.android.sample.data.model.RedditData; import com.nytimes.android.sample.data.remote.Api; diff --git a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java index ab264582..1e61f53b 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java @@ -7,8 +7,8 @@ import android.support.v7.widget.Toolbar; import android.widget.Toast; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; import com.nytimes.android.sample.R; import com.nytimes.android.sample.SampleApp; import com.nytimes.android.sample.data.model.Children; diff --git a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java index fbe295ed..d01d0123 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java @@ -8,8 +8,8 @@ import android.util.Log; import android.widget.Toast; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; import com.nytimes.android.sample.R; import com.nytimes.android.sample.SampleApp; import com.nytimes.android.sample.data.model.Children; diff --git a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java index 96dd6a00..f3fcc9fd 100644 --- a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java +++ b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java @@ -1,8 +1,8 @@ package com.nytimes.android.sample; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/build.gradle b/build.gradle index 5344529a..fb70c488 100644 --- a/build.gradle +++ b/build.gradle @@ -49,13 +49,11 @@ allprojects { } ext { - // SDK versions - // POM file GROUP = "com.nytimes.android" - VERSION_NAME = "2.0.3-SNAPSHOT" + VERSION_NAME = "0.0.1-SNAPSHOT" POM_PACKAGING = "pom" - POM_DESCRIPTION = "Store" + POM_DESCRIPTION = "Store2 is built with RxJava2" POM_URL = "https://github.com/nytimes/Store/" POM_SCM_URL = "https://github.com/nytimes/Store/" diff --git a/filesystem/gradle.properties b/filesystem/gradle.properties index af82b201..44840389 100644 --- a/filesystem/gradle.properties +++ b/filesystem/gradle.properties @@ -1,3 +1,3 @@ POM_NAME=com.nytimes.android -POM_ARTIFACT_ID=filesystem +POM_ARTIFACT_ID=filesystem2 POM_PACKAGING=aar diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/BarCodePathResolver.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/BarCodePathResolver.java similarity index 67% rename from filesystem/src/main/java/com/nytimes/android/external/fs/BarCodePathResolver.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/BarCodePathResolver.java index c9da92bb..6ae2a391 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/BarCodePathResolver.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/BarCodePathResolver.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.BarCode; import javax.annotation.Nonnull; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java similarity index 90% rename from filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java index bd3acdc3..56d7a095 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FSReader.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.DiskRead; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.DiskRead; import java.io.FileNotFoundException; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java similarity index 87% rename from filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java index e860ae3a..e8f6ea3b 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FSWriter.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.DiskWrite; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.DiskWrite; import java.util.concurrent.Callable; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java similarity index 89% rename from filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java index 0cb15952..d1f73a26 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.Persister; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.Persister; import javax.annotation.Nonnull; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersisterFactory.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersisterFactory.java similarity index 84% rename from filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersisterFactory.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersisterFactory.java index bb829d05..9374b2f1 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemPersisterFactory.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersisterFactory.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.fs.filesystem.FileSystemFactory; -import com.nytimes.android.external.store.base.Persister; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.fs2.filesystem.FileSystemFactory; +import com.nytimes.android.external.store2.base.Persister; import java.io.File; import java.io.IOException; @@ -19,7 +19,7 @@ private FileSystemPersisterFactory() { /** * Returns a new {@link BufferedSource} persister with the provided file as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -34,7 +34,7 @@ public static Persister create(@Nonnull File root, /** * Returns a new {@link BufferedSource} persister with the provided fileSystem as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -49,7 +49,7 @@ public static Persister create(@Nonnull FileSystem fi /** * Returns a new {@link BufferedSource} persister with the provided file as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -68,7 +68,7 @@ public static Persister create(@Nonnull File root, /** * Returns a new {@link BufferedSource} persister with the provided fileSystem as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. **/ @Nonnull public static Persister create(@Nonnull FileSystem fileSystem, diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java similarity index 89% rename from filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java index 1dce9787..6b238ad1 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/FileSystemRecordPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.RecordProvider; -import com.nytimes.android.external.store.base.RecordState; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.RecordProvider; +import com.nytimes.android.external.store2.base.RecordState; import java.util.concurrent.TimeUnit; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/PathResolver.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/PathResolver.java similarity index 88% rename from filesystem/src/main/java/com/nytimes/android/external/fs/PathResolver.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/PathResolver.java index befbdeae..7c570cbe 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/PathResolver.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/PathResolver.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import javax.annotation.Nonnull; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersister.java similarity index 78% rename from filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersister.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersister.java index 155cc0ba..5968b614 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersister.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.RecordProvider; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.RecordProvider; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; import java.util.concurrent.TimeUnit; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersisterFactory.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersisterFactory.java similarity index 77% rename from filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersisterFactory.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersisterFactory.java index 529e3586..25ae2bd3 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/RecordPersisterFactory.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/RecordPersisterFactory.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.fs.filesystem.FileSystemFactory; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.fs2.filesystem.FileSystemFactory; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; import java.io.File; import java.io.IOException; @@ -23,7 +23,7 @@ private RecordPersisterFactory() { /** * Returns a new {@link BufferedSource} persister with the provided file as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -39,7 +39,7 @@ public static Persister create(@Nonnull File root, /** * Returns a new {@link BufferedSource} persister with the provided fileSystem as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. **/ @Nonnull public static Persister create(@Nonnull FileSystem fileSystem, diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileReader.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileReader.java similarity index 64% rename from filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileReader.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileReader.java index 61a872e9..99a1bfdd 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileReader.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileReader.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.DiskRead; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.DiskRead; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; import java.util.concurrent.TimeUnit; @@ -11,7 +11,7 @@ import okio.BufferedSource; -import static com.nytimes.android.external.fs.SourcePersister.pathForBarcode; +import static com.nytimes.android.external.fs2.SourcePersister.pathForBarcode; public class SourceFileReader extends FSReader implements DiskRead { diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileWriter.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileWriter.java similarity index 52% rename from filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileWriter.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileWriter.java index 08580c72..2b9a5df8 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/SourceFileWriter.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourceFileWriter.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.DiskWrite; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.DiskWrite; +import com.nytimes.android.external.store2.base.impl.BarCode; import okio.BufferedSource; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java similarity index 86% rename from filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java index 02e9c123..be2de69e 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; import javax.annotation.Nonnull; import javax.inject.Inject; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersisterFactory.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersisterFactory.java similarity index 79% rename from filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersisterFactory.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersisterFactory.java index d7473705..53c996cd 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/SourcePersisterFactory.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersisterFactory.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.fs.filesystem.FileSystemFactory; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.fs2.filesystem.FileSystemFactory; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; import java.io.File; import java.io.IOException; @@ -24,7 +24,7 @@ private SourcePersisterFactory() { /** * Returns a new {@link BufferedSource} persister with the provided file as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -40,7 +40,7 @@ public static Persister create(@Nonnull File root, /** * Returns a new {@link BufferedSource} persister with the provided fileSystem as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. **/ @Nonnull public static Persister create(@Nonnull FileSystem fileSystem, @@ -54,7 +54,7 @@ public static Persister create(@Nonnull FileSystem file /** * Returns a new {@link BufferedSource} persister with the provided file as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. * * @throws IOException */ @@ -68,7 +68,7 @@ public static Persister create(@Nonnull File root) thro /** * Returns a new {@link BufferedSource} persister with the provided fileSystem as the root of the - * persistence {@link com.nytimes.android.external.fs.filesystem.FileSystem}. + * persistence {@link FileSystem}. **/ @Nonnull public static Persister create(@Nonnull FileSystem fileSystem) { diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/Util.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/Util.java similarity index 98% rename from filesystem/src/main/java/com/nytimes/android/external/fs/Util.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/Util.java index 24f997c2..d2ee25e2 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/Util.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/Util.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import java.io.File; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIterator.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIterator.java similarity index 98% rename from filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIterator.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIterator.java index 78b591ab..fb8e6e89 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIterator.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIterator.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; /* * Copyright 2004-2007 the original author or authors. diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FSFile.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FSFile.java similarity index 95% rename from filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FSFile.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FSFile.java index 5cf94a29..79e3d9db 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FSFile.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FSFile.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; -import com.nytimes.android.external.fs.Util; +import com.nytimes.android.external.fs2.Util; import java.io.File; import java.io.FileNotFoundException; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystem.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystem.java similarity index 97% rename from filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystem.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystem.java index bfe2524a..6df95584 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystem.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystem.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; -import com.nytimes.android.external.store.base.RecordState; +import com.nytimes.android.external.store2.base.RecordState; import java.io.File; import java.io.FileNotFoundException; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemFactory.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemFactory.java similarity index 91% rename from filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemFactory.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemFactory.java index 902fb5ce..71696ef8 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemFactory.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemFactory.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; import java.io.File; import java.io.IOException; diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemImpl.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemImpl.java similarity index 96% rename from filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemImpl.java rename to filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemImpl.java index ea187b43..84633804 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs/filesystem/FileSystemImpl.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/filesystem/FileSystemImpl.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; import com.nytimes.android.external.cache.CacheLoader; import com.nytimes.android.external.cache.LoadingCache; -import com.nytimes.android.external.fs.Util; -import com.nytimes.android.external.store.base.RecordState; +import com.nytimes.android.external.fs2.Util; +import com.nytimes.android.external.store2.base.RecordState; import java.io.File; import java.io.FileNotFoundException; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java similarity index 91% rename from filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java index 47f2d76d..8d631645 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/FilePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; import org.junit.Rule; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java similarity index 93% rename from filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java index 3ed2f303..5b303c25 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/FileSystemRecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; import org.junit.Rule; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/MultiTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/MultiTest.java similarity index 92% rename from filesystem/src/test/java/com/nytimes/android/external/fs/MultiTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/MultiTest.java index 8ca61cc7..2933cde1 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/MultiTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/MultiTest.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import com.google.common.collect.ImmutableMap; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.fs.filesystem.FileSystemFactory; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.fs2.filesystem.FileSystemFactory; import org.junit.Test; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java similarity index 92% rename from filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java index 5dd94b12..265d4327 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/RecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; import org.junit.Rule; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java similarity index 85% rename from filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java index 84f7f0e8..6f5879f5 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceDiskDaoStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java @@ -1,12 +1,12 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.GsonSourceParser; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.GsonSourceParser; import org.junit.Test; import org.mockito.Mock; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java similarity index 86% rename from filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java index 9df3ec02..cf045515 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourceFilerReaderWriterStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.GsonSourceParser; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.GsonSourceParser; import org.junit.Test; import org.mockito.Mock; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java similarity index 91% rename from filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java index 073722f2..776abc6a 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/SourcePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; import org.junit.Rule; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java similarity index 90% rename from filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java index c7691975..cca5ba00 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreNetworkBeforeStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java @@ -1,10 +1,10 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java similarity index 89% rename from filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java index a5483244..1054791c 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/StoreRefreshWhenStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java @@ -1,10 +1,10 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.RecordState; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/UtilTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/UtilTest.java similarity index 97% rename from filesystem/src/test/java/com/nytimes/android/external/fs/UtilTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/UtilTest.java index 75351581..6d8ce72e 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/UtilTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/UtilTest.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs; +package com.nytimes.android.external.fs2; import org.junit.Test; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIteratorTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIteratorTest.java similarity index 97% rename from filesystem/src/test/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIteratorTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIteratorTest.java index ea7e122a..b18d6e29 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/filesystem/BreadthFirstFileTreeIteratorTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/filesystem/BreadthFirstFileTreeIteratorTest.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.fs.filesystem; +package com.nytimes.android.external.fs2.filesystem; import org.junit.Before; import org.junit.Test; diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs/impl/SimpleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/impl/SimpleTest.java similarity index 95% rename from filesystem/src/test/java/com/nytimes/android/external/fs/impl/SimpleTest.java rename to filesystem/src/test/java/com/nytimes/android/external/fs2/impl/SimpleTest.java index c2f86f5e..790ed595 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs/impl/SimpleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/impl/SimpleTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.fs.impl; +package com.nytimes.android.external.fs2.impl; -import com.nytimes.android.external.fs.filesystem.FileSystem; -import com.nytimes.android.external.fs.filesystem.FileSystemFactory; -import com.nytimes.android.external.store.base.RecordState; +import com.nytimes.android.external.fs2.filesystem.FileSystem; +import com.nytimes.android.external.fs2.filesystem.FileSystemFactory; +import com.nytimes.android.external.store2.base.RecordState; import org.junit.Before; import org.junit.Test; diff --git a/middleware-jackson/gradle.properties b/middleware-jackson/gradle.properties index f80d5ec9..a3ffb436 100644 --- a/middleware-jackson/gradle.properties +++ b/middleware-jackson/gradle.properties @@ -1,3 +1,3 @@ POM_NAME=com.nytimes.android -POM_ARTIFACT_ID=middleware-jackson +POM_ARTIFACT_ID=middleware-jackson2 POM_PACKAGING=aar diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonParserFactory.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonParserFactory.java similarity index 97% rename from middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonParserFactory.java rename to middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonParserFactory.java index 60da6bbe..950a5457 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonParserFactory.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonParserFactory.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; import com.nytimes.android.external.cache.Preconditions; -import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store2.base.Parser; import java.io.Reader; import java.lang.reflect.Type; diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParser.java similarity index 86% rename from middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java rename to middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParser.java index a43eab43..14af5a58 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParser.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.io.IOException; import java.io.Reader; diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParser.java similarity index 89% rename from middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java rename to middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParser.java index c797ac72..3d63aa1b 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParser.java @@ -1,10 +1,10 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.io.IOException; import java.io.InputStream; diff --git a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParser.java similarity index 86% rename from middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java rename to middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParser.java index c171ae86..9531893c 100644 --- a/middleware-jackson/src/main/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParser.java +++ b/middleware-jackson/src/main/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParser.java @@ -1,10 +1,10 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.io.IOException; import java.lang.reflect.Type; diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java similarity index 88% rename from middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java rename to middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java index cc2d8c7e..0e7ffd28 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonReaderParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java @@ -1,14 +1,14 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.jackson.data.Foo; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.jackson.data.Foo; import org.junit.Before; import org.junit.Rule; diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java similarity index 89% rename from middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java rename to middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java index ecbee487..d11b7602 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonSourceParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java @@ -1,14 +1,14 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.jackson.data.Foo; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.jackson.data.Foo; import org.junit.Before; import org.junit.Rule; diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java similarity index 87% rename from middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java rename to middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java index efca977b..1fda4304 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/JacksonStringParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java @@ -1,14 +1,14 @@ -package com.nytimes.android.external.store.middleware.jackson; +package com.nytimes.android.external.store2.middleware.jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.jackson.data.Foo; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.jackson.data.Foo; import org.junit.Before; import org.junit.Rule; diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Bar.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Bar.java similarity index 67% rename from middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Bar.java rename to middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Bar.java index 766161da..3bc0f74e 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Bar.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Bar.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.middleware.jackson.data; +package com.nytimes.android.external.store2.middleware.jackson.data; public class Bar { public String string; diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Foo.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Foo.java similarity index 81% rename from middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Foo.java rename to middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Foo.java index 5bcb180d..fac48d7e 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store/middleware/jackson/data/Foo.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/data/Foo.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.middleware.jackson.data; +package com.nytimes.android.external.store2.middleware.jackson.data; import java.util.List; diff --git a/middleware-moshi/gradle.properties b/middleware-moshi/gradle.properties index 72eed9ac..4c907633 100644 --- a/middleware-moshi/gradle.properties +++ b/middleware-moshi/gradle.properties @@ -1,3 +1,3 @@ POM_NAME=com.nytimes.android -POM_ARTIFACT_ID=middleware-moshi +POM_ARTIFACT_ID=middleware-moshi2 POM_PACKAGING=aar diff --git a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiParserFactory.java b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiParserFactory.java similarity index 94% rename from middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiParserFactory.java rename to middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiParserFactory.java index fe3d6f85..21d4aa03 100644 --- a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiParserFactory.java +++ b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiParserFactory.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.store.middleware.moshi; +package com.nytimes.android.external.store2.middleware.moshi; import com.nytimes.android.external.cache.Preconditions; -import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store2.base.Parser; import com.squareup.moshi.Moshi; import java.lang.reflect.Type; diff --git a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParser.java similarity index 81% rename from middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java rename to middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParser.java index 085ae316..a5c7ef0d 100644 --- a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParser.java +++ b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParser.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.store.middleware.moshi; +package com.nytimes.android.external.store2.middleware.moshi; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; diff --git a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParser.java similarity index 80% rename from middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java rename to middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParser.java index 18b6af28..9dc76f27 100644 --- a/middleware-moshi/src/main/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParser.java +++ b/middleware-moshi/src/main/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParser.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.store.middleware.moshi; +package com.nytimes.android.external.store2.middleware.moshi; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java similarity index 85% rename from middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java rename to middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java index d88781dd..adcd8387 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiSourceParserTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java @@ -1,12 +1,12 @@ -package com.nytimes.android.external.store.middleware.moshi; - -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.ParsingStoreBuilder; -import com.nytimes.android.external.store.middleware.moshi.data.Foo; +package com.nytimes.android.external.store2.middleware.moshi; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.ParsingStoreBuilder; +import com.nytimes.android.external.store2.middleware.moshi.data.Foo; import org.junit.Before; import org.junit.Rule; diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java similarity index 84% rename from middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java rename to middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java index 4a8b2b52..1ae50aac 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/MoshiStringParserStoreTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.store.middleware.moshi; - -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.ParsingStoreBuilder; -import com.nytimes.android.external.store.middleware.moshi.data.Foo; +package com.nytimes.android.external.store2.middleware.moshi; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.ParsingStoreBuilder; +import com.nytimes.android.external.store2.middleware.moshi.data.Foo; import com.squareup.moshi.Moshi; import org.junit.Before; diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Bar.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Bar.java similarity index 63% rename from middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Bar.java rename to middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Bar.java index 692271c8..b39eb19c 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Bar.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Bar.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.middleware.moshi.data; +package com.nytimes.android.external.store2.middleware.moshi.data; public class Bar { public String string; diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Foo.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Foo.java similarity index 80% rename from middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Foo.java rename to middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Foo.java index 19abfaf9..a73fd1e1 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store/middleware/moshi/data/Foo.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/data/Foo.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.middleware.moshi.data; +package com.nytimes.android.external.store2.middleware.moshi.data; import java.util.List; diff --git a/middleware/gradle.properties b/middleware/gradle.properties index 62f4368e..226dc101 100644 --- a/middleware/gradle.properties +++ b/middleware/gradle.properties @@ -1,3 +1,3 @@ POM_NAME=com.nytimes.android -POM_ARTIFACT_ID=middleware +POM_ARTIFACT_ID=middleware2 POM_PACKAGING=aar diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonParserFactory.java b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonParserFactory.java similarity index 95% rename from middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonParserFactory.java rename to middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonParserFactory.java index c42441ec..267fd5b9 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonParserFactory.java +++ b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonParserFactory.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.store.middleware; +package com.nytimes.android.external.store2.middleware; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store2.base.Parser; import java.io.Reader; import java.lang.reflect.Type; diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonReaderParser.java similarity index 80% rename from middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java rename to middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonReaderParser.java index 4aea30ca..40c5a636 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonReaderParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonReaderParser.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.store.middleware; +package com.nytimes.android.external.store2.middleware; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.io.Reader; import java.lang.reflect.Type; diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonSourceParser.java similarity index 89% rename from middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java rename to middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonSourceParser.java index 53454687..ac7ab225 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonSourceParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonSourceParser.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store.middleware; +package com.nytimes.android.external.store2.middleware; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.io.IOException; import java.io.InputStreamReader; diff --git a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonStringParser.java similarity index 80% rename from middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java rename to middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonStringParser.java index 3bb76767..0dcf7474 100644 --- a/middleware/src/main/java/com/nytimes/android/external/store/middleware/GsonStringParser.java +++ b/middleware/src/main/java/com/nytimes/android/external/store2/middleware/GsonStringParser.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.store.middleware; +package com.nytimes.android.external.store2.middleware; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.ParserException; import java.lang.reflect.Type; diff --git a/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java b/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java similarity index 82% rename from middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java rename to middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java index 57539f5c..94bbd4a7 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store/GenericParserStoreTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java @@ -1,13 +1,13 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; import com.google.gson.Gson; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.GsonParserFactory; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.GsonParserFactory; import org.junit.Test; import org.mockito.Mock; diff --git a/middleware/src/test/java/com/nytimes/android/external/store/GsonParserFactoryTest.java b/middleware/src/test/java/com/nytimes/android/external/store2/GsonParserFactoryTest.java similarity index 94% rename from middleware/src/test/java/com/nytimes/android/external/store/GsonParserFactoryTest.java rename to middleware/src/test/java/com/nytimes/android/external/store2/GsonParserFactoryTest.java index fedd0cea..a8677390 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store/GsonParserFactoryTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store2/GsonParserFactoryTest.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; import com.google.gson.Gson; -import com.nytimes.android.external.store.middleware.GsonParserFactory; +import com.nytimes.android.external.store2.middleware.GsonParserFactory; import org.junit.Before; import org.junit.Rule; diff --git a/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java b/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java similarity index 84% rename from middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java rename to middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java index 0af9b6c1..c6522c42 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store/GsonSourceListParserTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java @@ -1,14 +1,14 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.middleware.GsonParserFactory; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.middleware.GsonParserFactory; import org.junit.Test; import org.mockito.Mock; diff --git a/store/gradle.properties b/store/gradle.properties index a02df4a1..e72a6d5c 100644 --- a/store/gradle.properties +++ b/store/gradle.properties @@ -1,3 +1,3 @@ POM_NAME=com.nytimes.android -POM_ARTIFACT_ID=store +POM_ARTIFACT_ID=store2 POM_PACKAGING=aar diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Clearable.java b/store/src/main/java/com/nytimes/android/external/store2/base/Clearable.java similarity index 83% rename from store/src/main/java/com/nytimes/android/external/store/base/Clearable.java rename to store/src/main/java/com/nytimes/android/external/store2/base/Clearable.java index 9b8baef3..a037914e 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Clearable.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Clearable.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java b/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java similarity index 76% rename from store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java rename to store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java index 5f2ffe9a..17ba6b0a 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/DiskRead.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java b/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java similarity index 88% rename from store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java rename to store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java index 6e92877c..8736e463 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/DiskWrite.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java b/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java similarity index 89% rename from store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java rename to store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java index 586af418..2e697698 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Fetcher.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java similarity index 60% rename from store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java rename to store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java index f0bce432..e79c4d0a 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/InternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java @@ -1,13 +1,13 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; -import com.nytimes.android.external.store.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.Store; import javax.annotation.Nonnull; import io.reactivex.Observable; /** - * this interface allows us to mark a {@link Store} as "internal", exposing methods for retrieving data +2 * this interface allows us to mark a {@link Store} as "internal", exposing methods for retrieving data * directly from memory or from disk. */ public interface InternalStore extends Store { diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Parser.java b/store/src/main/java/com/nytimes/android/external/store2/base/Parser.java similarity index 73% rename from store/src/main/java/com/nytimes/android/external/store/base/Parser.java rename to store/src/main/java/com/nytimes/android/external/store2/base/Parser.java index 0a45fc4e..a3af271c 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Parser.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Parser.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.util.ParserException; import io.reactivex.annotations.NonNull; import io.reactivex.functions.Function; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/Persister.java b/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java similarity index 94% rename from store/src/main/java/com/nytimes/android/external/store/base/Persister.java rename to store/src/main/java/com/nytimes/android/external/store2/base/Persister.java index 8a44d98c..5e29d1e4 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/Persister.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/RecordProvider.java b/store/src/main/java/com/nytimes/android/external/store2/base/RecordProvider.java similarity index 73% rename from store/src/main/java/com/nytimes/android/external/store/base/RecordProvider.java rename to store/src/main/java/com/nytimes/android/external/store2/base/RecordProvider.java index 41d7141f..99750f30 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/RecordProvider.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/RecordProvider.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/RecordState.java b/store/src/main/java/com/nytimes/android/external/store2/base/RecordState.java similarity index 52% rename from store/src/main/java/com/nytimes/android/external/store/base/RecordState.java rename to store/src/main/java/com/nytimes/android/external/store2/base/RecordState.java index 480b806c..fe1feaa1 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/RecordState.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/RecordState.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base; +package com.nytimes.android.external.store2.base; public enum RecordState { FRESH, STALE, MISSING diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/BarCode.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/BarCode.java similarity index 87% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/BarCode.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/BarCode.java index ed16a8e4..c46f9994 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/BarCode.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/BarCode.java @@ -1,17 +1,18 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import com.nytimes.android.external.cache.Preconditions; +import com.nytimes.android.external.store2.base.Persister; import java.io.Serializable; import javax.annotation.Nonnull; /** - * {@link com.nytimes.android.external.store.base.impl.BarCode Barcode} is used as a unique + * {@link BarCode Barcode} is used as a unique * identifier for a particular {@link Store Store} *

* Barcode will be passed to Fetcher - * and {@link com.nytimes.android.external.store.base.Persister Persister} + * and {@link Persister Persister} **/ public final class BarCode implements Serializable { diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/MemoryPolicy.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/MemoryPolicy.java similarity index 86% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/MemoryPolicy.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/MemoryPolicy.java index 1a153814..875e712b 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/MemoryPolicy.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/MemoryPolicy.java @@ -1,18 +1,20 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; +import com.nytimes.android.external.store2.util.NoopPersister; + import java.util.concurrent.TimeUnit; /** * MemoryPolicy holds all required info to create MemoryCache and - * {@link com.nytimes.android.external.store.util.NoopPersister NoopPersister} + * {@link NoopPersister NoopPersister} *

* This class is used, in order to define the appropriate parameters for the MemoryCache * to be built. *

- * MemoryPolicy is used by a {@link com.nytimes.android.external.store.base.impl.Store Store} + * MemoryPolicy is used by a {@link Store Store} * and defines the in-memory cache behavior. It is also used by - * {@link com.nytimes.android.external.store.util.NoopPersister NoopPersister} + * {@link NoopPersister NoopPersister} * to define a basic caching mechanism. */ public class MemoryPolicy { diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/MultiParser.java similarity index 88% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/MultiParser.java index ac8c351f..ebf392a5 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/MultiParser.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/MultiParser.java @@ -1,7 +1,7 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; -import com.nytimes.android.external.store.util.KeyParser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.util.KeyParser; +import com.nytimes.android.external.store2.util.ParserException; import java.util.ArrayList; import java.util.List; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/ParsingStoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/ParsingStoreBuilder.java similarity index 85% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/ParsingStoreBuilder.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/ParsingStoreBuilder.java index fd4a380c..b4af35f6 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/ParsingStoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/ParsingStoreBuilder.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java similarity index 94% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java index 6bba9f8a..fb914e51 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealInternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java @@ -1,13 +1,13 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import com.nytimes.android.external.cache.Cache; import com.nytimes.android.external.cache.CacheBuilder; -import com.nytimes.android.external.store.base.Clearable; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.InternalStore; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.util.KeyParser; -import com.nytimes.android.external.store.util.OnErrorResumeWithEmpty; +import com.nytimes.android.external.store2.base.Clearable; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.InternalStore; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.util.KeyParser; +import com.nytimes.android.external.store2.util.OnErrorResumeWithEmpty; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; @@ -27,9 +27,6 @@ import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.PublishSubject; -import static com.nytimes.android.external.store.base.impl.StoreUtil.persisterIsStale; -import static com.nytimes.android.external.store.base.impl.StoreUtil.shouldReturnNetworkBeforeStale; - /** * Store to be used for loading an object different data sources * @@ -175,7 +172,7 @@ public Observable memory(@Nonnull Key key) { @Nonnull @Override public Observable disk(@Nonnull final Key key) { - if (shouldReturnNetworkBeforeStale(persister, stalePolicy, key)) { + if (StoreUtil.shouldReturnNetworkBeforeStale(persister, stalePolicy, key)) { return Observable.empty(); } @@ -196,7 +193,7 @@ public Parsed apply(@NonNull Raw raw) { public void accept(@NonNull Parsed parsed) { updateMemory(key, parsed); if (stalePolicy == StalePolicy.REFRESH_ON_STALE - && persisterIsStale(key, persister)) { + && StoreUtil.persisterIsStale(key, persister)) { backfillCache(key); } } diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java similarity index 82% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java index e28b2e41..86392a00 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java @@ -1,13 +1,13 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.InternalStore; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.util.KeyParser; -import com.nytimes.android.external.store.util.NoKeyParser; -import com.nytimes.android.external.store.util.NoopParserFunc; -import com.nytimes.android.external.store.util.NoopPersister; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.InternalStore; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.util.KeyParser; +import com.nytimes.android.external.store2.util.NoKeyParser; +import com.nytimes.android.external.store2.util.NoopParserFunc; +import com.nytimes.android.external.store2.util.NoopPersister; import javax.annotation.Nonnull; @@ -15,8 +15,6 @@ import io.reactivex.Observable; -import static com.nytimes.android.external.store.base.impl.StalePolicy.UNSPECIFIED; - public class RealStore implements Store { private final InternalStore internalStore; @@ -28,7 +26,7 @@ public RealStore(InternalStore internalStore) { public RealStore(Fetcher fetcher) { final Parser noOpFunc = new NoopParserFunc<>(); internalStore = new RealInternalStore<>(fetcher, NoopPersister.create(), - new NoKeyParser(noOpFunc), UNSPECIFIED); + new NoKeyParser(noOpFunc), StalePolicy.UNSPECIFIED); } public RealStore(Fetcher fetcher, @@ -37,7 +35,7 @@ public RealStore(Fetcher fetcher, internalStore = new RealInternalStore<>(fetcher, persister, new NoKeyParser(noOpFunc), - UNSPECIFIED); + StalePolicy.UNSPECIFIED); } public RealStore(Fetcher fetcher, @@ -46,7 +44,7 @@ public RealStore(Fetcher fetcher, internalStore = new RealInternalStore<>(fetcher, persister, new NoKeyParser(parser), - UNSPECIFIED); + StalePolicy.UNSPECIFIED); } diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java similarity index 86% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java index 4a1b364e..7f7180c0 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RealStoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java @@ -1,15 +1,15 @@ -package com.nytimes.android.external.store.base.impl; - - -import com.nytimes.android.external.store.base.DiskRead; -import com.nytimes.android.external.store.base.DiskWrite; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.util.KeyParser; -import com.nytimes.android.external.store.util.NoKeyParser; -import com.nytimes.android.external.store.util.NoopParserFunc; -import com.nytimes.android.external.store.util.NoopPersister; +package com.nytimes.android.external.store2.base.impl; + + +import com.nytimes.android.external.store2.base.DiskRead; +import com.nytimes.android.external.store2.base.DiskWrite; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.util.KeyParser; +import com.nytimes.android.external.store2.util.NoKeyParser; +import com.nytimes.android.external.store2.util.NoopParserFunc; +import com.nytimes.android.external.store2.util.NoopPersister; import java.util.ArrayList; import java.util.List; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmits.java similarity index 96% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmits.java index 4a2caa21..f22276e1 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmits.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmits.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/StalePolicy.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StalePolicy.java similarity index 60% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/StalePolicy.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/StalePolicy.java index 6e43f163..4e8cd840 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/StalePolicy.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StalePolicy.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; public enum StalePolicy { UNSPECIFIED, REFRESH_ON_STALE, NETWORK_BEFORE_STALE diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java similarity index 94% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java index 3e1f71ea..165f66c7 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/Store.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import javax.annotation.Nonnull; @@ -8,7 +8,7 @@ /** - * a {@link com.nytimes.android.external.store.base.impl.StoreBuilder StoreBuilder} + * a {@link StoreBuilder StoreBuilder} * will return an instance of a store *

* A {@link Store Store} can diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreBuilder.java similarity index 93% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreBuilder.java index 3c11795e..c9ac27b8 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreBuilder.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreUtil.java similarity index 81% rename from store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java rename to store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreUtil.java index 7ccfa831..570f2e5f 100644 --- a/store/src/main/java/com/nytimes/android/external/store/base/impl/StoreUtil.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/StoreUtil.java @@ -1,8 +1,8 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.RecordProvider; -import com.nytimes.android.external.store.base.RecordState; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.RecordProvider; +import com.nytimes.android.external.store2.base.RecordState; import javax.annotation.Nonnull; @@ -13,7 +13,7 @@ import io.reactivex.subjects.PublishSubject; -import static com.nytimes.android.external.store.base.RecordState.STALE; +import static com.nytimes.android.external.store2.base.RecordState.STALE; final class StoreUtil { private StoreUtil() { diff --git a/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java b/store/src/main/java/com/nytimes/android/external/store2/util/KeyParser.java similarity index 84% rename from store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java rename to store/src/main/java/com/nytimes/android/external/store2/util/KeyParser.java index 6b3a1980..6f7ec7d1 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/KeyParser.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/KeyParser.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; import io.reactivex.annotations.NonNull; import io.reactivex.functions.BiFunction; diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java b/store/src/main/java/com/nytimes/android/external/store2/util/NoKeyParser.java similarity index 80% rename from store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java rename to store/src/main/java/com/nytimes/android/external/store2/util/NoKeyParser.java index 49c139da..81d57368 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoKeyParser.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/NoKeyParser.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; -import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store2.base.Parser; import javax.annotation.Nonnull; diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java b/store/src/main/java/com/nytimes/android/external/store2/util/NoopParserFunc.java similarity index 73% rename from store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java rename to store/src/main/java/com/nytimes/android/external/store2/util/NoopParserFunc.java index fad5167e..29665449 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoopParserFunc.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/NoopParserFunc.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; -import com.nytimes.android.external.store.base.Parser; +import com.nytimes.android.external.store2.base.Parser; import io.reactivex.annotations.NonNull; diff --git a/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java b/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java similarity index 89% rename from store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java rename to store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java index 6615dc9b..f12bfdb1 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/NoopPersister.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; import com.nytimes.android.external.cache.Cache; import com.nytimes.android.external.cache.CacheBuilder; -import com.nytimes.android.external.store.base.Clearable; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.MemoryPolicy; +import com.nytimes.android.external.store2.base.Clearable; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.MemoryPolicy; import java.util.concurrent.TimeUnit; diff --git a/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java b/store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java similarity index 89% rename from store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java rename to store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java index a42589a0..acd108e9 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/OnErrorResumeWithEmpty.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; import io.reactivex.Observable; diff --git a/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java b/store/src/main/java/com/nytimes/android/external/store2/util/ParserException.java similarity index 88% rename from store/src/main/java/com/nytimes/android/external/store/util/ParserException.java rename to store/src/main/java/com/nytimes/android/external/store2/util/ParserException.java index 4b7099b7..ebee0e4c 100644 --- a/store/src/main/java/com/nytimes/android/external/store/util/ParserException.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/ParserException.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; /** * Exception thrown when one of the provided parsers fails. diff --git a/store/src/test/java/com/nytimes/android/external/store/SampleParsingStore.java b/store/src/test/java/com/nytimes/android/external/store/SampleParsingStore.java deleted file mode 100644 index b190b246..00000000 --- a/store/src/test/java/com/nytimes/android/external/store/SampleParsingStore.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nytimes.android.external.store; - -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.RealStore; - - -public class SampleParsingStore extends RealStore { - - public SampleParsingStore(Fetcher fetcher, - Persister persister, - Parser parser) { - super(fetcher, persister, parser); - } -} diff --git a/store/src/test/java/com/nytimes/android/external/store/SampleStore.java b/store/src/test/java/com/nytimes/android/external/store/SampleStore.java deleted file mode 100644 index 15468f07..00000000 --- a/store/src/test/java/com/nytimes/android/external/store/SampleStore.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.nytimes.android.external.store; - -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.RealStore; - - -public class SampleStore extends RealStore { - public SampleStore(Fetcher fetcher, Persister persister) { - super(fetcher, persister); - } -} diff --git a/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java similarity index 87% rename from store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java rename to store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java index ff70c962..aacc7afd 100644 --- a/store/src/test/java/com/nytimes/android/external/store/ClearStoreMemoryTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java similarity index 91% rename from store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java rename to store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java index 426cb9fb..f5efa452 100644 --- a/store/src/test/java/com/nytimes/android/external/store/ClearStoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; @@ -19,7 +19,7 @@ import io.reactivex.Observable; -import static com.nytimes.android.external.store.GetRefreshingTest.ClearingPersister; +import static com.nytimes.android.external.store2.GetRefreshingTest.ClearingPersister; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java b/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java similarity index 84% rename from store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java rename to store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java index bc327d06..b9be589c 100644 --- a/store/src/test/java/com/nytimes/android/external/store/DontCacheErrorsTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java b/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java similarity index 92% rename from store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java rename to store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java index e2a9b271..724ee186 100644 --- a/store/src/test/java/com/nytimes/android/external/store/GetRefreshingTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.store; - -import com.nytimes.android.external.store.base.Clearable; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +package com.nytimes.android.external.store2; + +import com.nytimes.android.external.store2.base.Clearable; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java b/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java similarity index 84% rename from store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java rename to store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java index 495f6d83..8ea532cd 100644 --- a/store/src/test/java/com/nytimes/android/external/store/KeyParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.util.KeyParser; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.util.KeyParser; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store2/SampleParsingStore.java b/store/src/test/java/com/nytimes/android/external/store2/SampleParsingStore.java new file mode 100644 index 00000000..9a12b41c --- /dev/null +++ b/store/src/test/java/com/nytimes/android/external/store2/SampleParsingStore.java @@ -0,0 +1,17 @@ +package com.nytimes.android.external.store2; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.RealStore; + + +public class SampleParsingStore extends RealStore { + + public SampleParsingStore(Fetcher fetcher, + Persister persister, + Parser parser) { + super(fetcher, persister, parser); + } +} diff --git a/store/src/test/java/com/nytimes/android/external/store2/SampleStore.java b/store/src/test/java/com/nytimes/android/external/store2/SampleStore.java new file mode 100644 index 00000000..c63a6c53 --- /dev/null +++ b/store/src/test/java/com/nytimes/android/external/store2/SampleStore.java @@ -0,0 +1,13 @@ +package com.nytimes.android.external.store2; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.RealStore; + + +public class SampleStore extends RealStore { + public SampleStore(Fetcher fetcher, Persister persister) { + super(fetcher, persister); + } +} diff --git a/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java b/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java similarity index 84% rename from store/src/test/java/com/nytimes/android/external/store/SequentialTest.java rename to store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java index ccaa85ad..910c08e6 100644 --- a/store/src/test/java/com/nytimes/android/external/store/SequentialTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java similarity index 86% rename from store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java rename to store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java index fdf83b0d..40a3fe92 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreBuilderTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java @@ -1,12 +1,12 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java similarity index 92% rename from store/src/test/java/com/nytimes/android/external/store/StoreTest.java rename to store/src/test/java/com/nytimes/android/external/store2/StoreTest.java index 876ccfce..9353de8e 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java @@ -1,14 +1,14 @@ -package com.nytimes.android.external.store; +package com.nytimes.android.external.store2; import com.nytimes.android.external.cache.Cache; import com.nytimes.android.external.cache.CacheBuilder; -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.RealStore; -import com.nytimes.android.external.store.base.impl.Store; -import com.nytimes.android.external.store.base.impl.StoreBuilder; -import com.nytimes.android.external.store.util.NoopPersister; +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.RealStore; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; +import com.nytimes.android.external.store2.util.NoopPersister; import org.junit.Before; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java similarity index 86% rename from store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java rename to store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java index 54207b3c..19217e67 100644 --- a/store/src/test/java/com/nytimes/android/external/store/StoreWithParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java @@ -1,11 +1,11 @@ -package com.nytimes.android.external.store; - -import com.nytimes.android.external.store.base.Fetcher; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.base.Persister; -import com.nytimes.android.external.store.base.impl.BarCode; -import com.nytimes.android.external.store.base.impl.ParsingStoreBuilder; -import com.nytimes.android.external.store.base.impl.Store; +package com.nytimes.android.external.store2; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.ParsingStoreBuilder; +import com.nytimes.android.external.store2.base.impl.Store; import org.junit.Test; import org.mockito.Mock; diff --git a/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java b/store/src/test/java/com/nytimes/android/external/store2/base/impl/MultiParserTest.java similarity index 86% rename from store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java rename to store/src/test/java/com/nytimes/android/external/store2/base/impl/MultiParserTest.java index a9b6557f..5479cbd2 100644 --- a/store/src/test/java/com/nytimes/android/external/store/base/impl/MultiParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/base/impl/MultiParserTest.java @@ -1,9 +1,9 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; -import com.nytimes.android.external.store.base.Parser; -import com.nytimes.android.external.store.util.KeyParser; -import com.nytimes.android.external.store.util.NoKeyParser; -import com.nytimes.android.external.store.util.ParserException; +import com.nytimes.android.external.store2.base.Parser; +import com.nytimes.android.external.store2.util.KeyParser; +import com.nytimes.android.external.store2.util.NoKeyParser; +import com.nytimes.android.external.store2.util.ParserException; import org.junit.Rule; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java b/store/src/test/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmitsTest.java similarity index 95% rename from store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java rename to store/src/test/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmitsTest.java index 729647b7..ab1dc100 100644 --- a/store/src/test/java/com/nytimes/android/external/store/base/impl/RepeatWhenEmitsTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/base/impl/RepeatWhenEmitsTest.java @@ -1,4 +1,4 @@ -package com.nytimes.android.external.store.base.impl; +package com.nytimes.android.external.store2.base.impl; import org.junit.Test; diff --git a/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java b/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java similarity index 88% rename from store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java rename to store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java index 9e45724b..3c1962ef 100644 --- a/store/src/test/java/com/nytimes/android/external/store/util/NoopPersisterTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java @@ -1,6 +1,6 @@ -package com.nytimes.android.external.store.util; +package com.nytimes.android.external.store2.util; -import com.nytimes.android.external.store.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Test; From 20445fff13aa76cf8b842b190c702a2f9f1dacbc Mon Sep 17 00:00:00 2001 From: Tair Date: Mon, 24 Apr 2017 23:37:45 +0300 Subject: [PATCH 3/3] RxJava2 Migration: Return single/maybe where appropriate. (#185) * RxJava2 Migration: Return single/maybe where appropriate. * Remove no longer used class. * Pull in the fix for #181 from develop. * Re-iterated solution #181 issue. --- .../com/nytimes/android/sample/SampleApp.java | 7 +- .../activity/PersistingStoreActivity.java | 2 +- .../sample/activity/StoreActivity.java | 2 +- .../android/sample/data/remote/Api.java | 10 +- .../android/sample/StoreIntegrationTest.java | 19 +--- .../android/external/fs2/FSReader.java | 17 ++-- .../android/external/fs2/FSWriter.java | 6 +- .../external/fs2/FileSystemPersister.java | 7 +- .../fs2/FileSystemRecordPersister.java | 7 +- .../android/external/fs2/SourcePersister.java | 7 +- .../external/fs2/FilePersisterTest.java | 17 +--- .../fs2/FileSystemRecordPersisterTest.java | 14 +-- .../external/fs2/RecordPersisterTest.java | 12 +-- .../external/fs2/SourceDiskDaoStoreTest.java | 15 +-- .../fs2/SourceFilerReaderWriterStoreTest.java | 15 +-- .../external/fs2/SourcePersisterTest.java | 8 +- .../fs2/StoreNetworkBeforeStaleFailTest.java | 76 ++++++++++++++ .../fs2/StoreNetworkBeforeStaleTest.java | 41 ++++++-- .../fs2/StoreRefreshWhenStaleTest.java | 17 ++-- .../jackson/JacksonReaderParserStoreTest.java | 15 +-- .../jackson/JacksonSourceParserStoreTest.java | 15 +-- .../jackson/JacksonStringParserStoreTest.java | 15 +-- .../moshi/MoshiSourceParserTest.java | 13 +-- .../moshi/MoshiStringParserStoreTest.java | 13 +-- .../store2/GenericParserStoreTest.java | 15 +-- .../store2/GsonSourceListParserTest.java | 13 +-- .../external/store2/base/DiskRead.java | 5 +- .../external/store2/base/DiskWrite.java | 4 +- .../android/external/store2/base/Fetcher.java | 4 +- .../external/store2/base/InternalStore.java | 6 +- .../external/store2/base/Persister.java | 7 +- .../store2/base/impl/RealInternalStore.java | 98 ++++++++++--------- .../external/store2/base/impl/RealStore.java | 10 +- .../store2/base/impl/RealStoreBuilder.java | 8 +- .../external/store2/base/impl/Store.java | 5 +- .../external/store2/util/NoopPersister.java | 18 ++-- .../store2/util/OnErrorResumeWithEmpty.java | 17 ---- .../external/store2/ClearStoreMemoryTest.java | 7 +- .../external/store2/ClearStoreTest.java | 43 ++++---- .../external/store2/DontCacheErrorsTest.java | 6 +- .../external/store2/GetRefreshingTest.java | 47 ++++----- .../external/store2/KeyParserTest.java | 6 +- .../external/store2/SequentialTest.java | 11 +-- .../external/store2/StoreBuilderTest.java | 29 +++--- .../android/external/store2/StoreTest.java | 56 +++++------ .../external/store2/StoreWithParserTest.java | 27 ++--- .../store2/util/NoopPersisterTest.java | 4 +- 47 files changed, 444 insertions(+), 372 deletions(-) create mode 100644 filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleFailTest.java delete mode 100644 store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java diff --git a/app/src/main/java/com/nytimes/android/sample/SampleApp.java b/app/src/main/java/com/nytimes/android/sample/SampleApp.java index 2feefda4..29c5305b 100644 --- a/app/src/main/java/com/nytimes/android/sample/SampleApp.java +++ b/app/src/main/java/com/nytimes/android/sample/SampleApp.java @@ -18,7 +18,8 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -import io.reactivex.Observable; +import io.reactivex.Single; +import okhttp3.ResponseBody; import okio.BufferedSource; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; @@ -80,9 +81,9 @@ private Persister newPersister() throws IOException { return SourcePersisterFactory.create(getApplicationContext().getCacheDir()); } - private Observable fetcher(BarCode barCode) { + private Single fetcher(BarCode barCode) { return provideRetrofit().fetchSubredditForPersister(barCode.getKey(), "10") - .map(responseBody -> responseBody.source()); + .map(ResponseBody::source); } private Api provideRetrofit() { diff --git a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java index 1e61f53b..63abce3f 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/PersistingStoreActivity.java @@ -58,7 +58,7 @@ public void loadPosts() { this.persistedStore .get(awwRequest) - .flatMap(this::sanitizeData) + .flatMapObservable(this::sanitizeData) .toList() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) diff --git a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java index d01d0123..f4391a05 100644 --- a/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java +++ b/app/src/main/java/com/nytimes/android/sample/activity/StoreActivity.java @@ -60,7 +60,7 @@ public void loadPosts() { this.nonPersistedStore .get(awwRequest) - .flatMap(new Function>() { + .flatMapObservable(new Function>() { @Override public ObservableSource apply(@NonNull RedditData redditData) throws Exception { return sanitizeData(redditData); diff --git a/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java b/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java index 9c8e172e..65e8d5a8 100644 --- a/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java +++ b/app/src/main/java/com/nytimes/android/sample/data/remote/Api.java @@ -2,7 +2,7 @@ import com.nytimes.android.sample.data.model.RedditData; -import io.reactivex.Observable; +import io.reactivex.Single; import okhttp3.ResponseBody; import retrofit2.http.GET; import retrofit2.http.Path; @@ -11,10 +11,10 @@ public interface Api { @GET("r/{subredditName}/new/.json") - Observable fetchSubreddit(@Path("subredditName") String subredditName, - @Query("limit") String limit); + Single fetchSubreddit(@Path("subredditName") String subredditName, + @Query("limit") String limit); @GET("r/{subredditName}/new/.json") - Observable fetchSubredditForPersister(@Path("subredditName") String subredditName, - @Query("limit") String limit); + Single fetchSubredditForPersister(@Path("subredditName") String subredditName, + @Query("limit") String limit); } diff --git a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java index f3fcc9fd..2b796a48 100644 --- a/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java +++ b/app/src/test/java/com/nytimes/android/sample/StoreIntegrationTest.java @@ -7,37 +7,24 @@ import org.junit.Before; import org.junit.Test; - -import io.reactivex.Observable; +import io.reactivex.Single; import static junit.framework.Assert.assertEquals; -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ public class StoreIntegrationTest { private Store testStore; - @Test - public void addition_isCorrect() throws Exception { - - } - - @Before public void setUp() throws Exception { testStore = StoreBuilder.barcode() - .fetcher(barCode -> Observable.just("hello")) + .fetcher(barCode -> Single.just("hello")) .open(); - } @Test public void testRepeatedGet() throws Exception { - String first = testStore.get(BarCode.empty()).blockingFirst(); + String first = testStore.get(BarCode.empty()).blockingGet(); assertEquals(first, "hello"); } diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java index 56d7a095..94e5f37a 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSReader.java @@ -7,9 +7,9 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; -import io.reactivex.ObservableEmitter; -import io.reactivex.ObservableOnSubscribe; +import io.reactivex.Maybe; +import io.reactivex.MaybeEmitter; +import io.reactivex.MaybeOnSubscribe; import okio.BufferedSource; /** @@ -20,6 +20,7 @@ * @param key type */ public class FSReader implements DiskRead { + private static final String ERROR_MESSAGE = "resolvedKey does not resolve to a file"; final FileSystem fileSystem; final PathResolver pathResolver; @@ -30,23 +31,23 @@ public FSReader(FileSystem fileSystem, PathResolver pathResolver) { @Nonnull @Override - public Observable read(@Nonnull final T key) { - return Observable.create(new ObservableOnSubscribe() { + public Maybe read(@Nonnull final T key) { + return Maybe.create(new MaybeOnSubscribe() { @Override - public void subscribe(ObservableEmitter emitter) { + public void subscribe(MaybeEmitter emitter) { String resolvedKey = pathResolver.resolve(key); boolean exists = fileSystem.exists(resolvedKey); if (exists) { try { BufferedSource bufferedSource = fileSystem.read(resolvedKey); - emitter.onNext(bufferedSource); + emitter.onSuccess(bufferedSource); emitter.onComplete(); } catch (FileNotFoundException e) { emitter.onError(e); } } else { - emitter.onComplete(); + emitter.onError(new FileNotFoundException(ERROR_MESSAGE + resolvedKey)); } } }); diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java index e8f6ea3b..52047fa7 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FSWriter.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Single; import okio.BufferedSource; /** @@ -27,8 +27,8 @@ public FSWriter(FileSystem fileSystem, PathResolver pathResolver) { @Nonnull @Override - public Observable write(@Nonnull final T key, @Nonnull final BufferedSource data) { - return Observable.fromCallable(new Callable() { + public Single write(@Nonnull final T key, @Nonnull final BufferedSource data) { + return Single.fromCallable(new Callable() { @Nonnull @Override @SuppressWarnings("PMD.SignatureDeclareThrowsException") diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java index d1f73a26..df20fc5d 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemPersister.java @@ -5,7 +5,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; /** @@ -34,13 +35,13 @@ public static Persister create(FileSystem fileSystem, @Nonnull @Override - public Observable read(@Nonnull final T key) { + public Maybe read(@Nonnull final T key) { return fileReader.read(key); } @Nonnull @Override - public Observable write(@Nonnull final T key, @Nonnull final BufferedSource data) { + public Single write(@Nonnull final T key, @Nonnull final BufferedSource data) { return fileWriter.write(key, data); } } diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java index 6b238ad1..a312d11a 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/FileSystemRecordPersister.java @@ -9,7 +9,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; /** @@ -59,13 +60,13 @@ public RecordState getRecordState(@Nonnull Key key) { @Nonnull @Override - public Observable read(@Nonnull Key key) { + public Maybe read(@Nonnull Key key) { return fileReader.read(key); } @Nonnull @Override - public Observable write(@Nonnull Key key, @Nonnull BufferedSource bufferedSource) { + public Single write(@Nonnull Key key, @Nonnull BufferedSource bufferedSource) { return fileWriter.write(key, bufferedSource); } } diff --git a/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java index be2de69e..8f18a0e4 100644 --- a/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java +++ b/filesystem/src/main/java/com/nytimes/android/external/fs2/SourcePersister.java @@ -8,7 +8,8 @@ import javax.annotation.Nonnull; import javax.inject.Inject; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; /** @@ -44,13 +45,13 @@ static String pathForBarcode(@Nonnull BarCode barCode) { @Nonnull @Override - public Observable read(@Nonnull final BarCode barCode) { + public Maybe read(@Nonnull final BarCode barCode) { return sourceFileReader.read(barCode); } @Nonnull @Override - public Observable write(@Nonnull final BarCode barCode, @Nonnull final BufferedSource data) { + public Single write(@Nonnull final BarCode barCode, @Nonnull final BufferedSource data) { return sourceFileWriter.write(barCode, data); } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java index 8d631645..76b47fbc 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/FilePersisterTest.java @@ -5,16 +5,13 @@ import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.NoSuchElementException; import okio.BufferedSource; @@ -23,8 +20,6 @@ import static org.mockito.Mockito.when; public class FilePersisterTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Mock FileSystem fileSystem; @@ -47,18 +42,17 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); - BufferedSource returnedValue = fileSystemPersister.read(simple).blockingFirst(); + BufferedSource returnedValue = fileSystemPersister.read(simple).blockingGet(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { - expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(resolvedPath)) .thenReturn(false); - fileSystemPersister.read(simple).blockingFirst(); + fileSystemPersister.read(simple).test().assertError(FileNotFoundException.class); } @Test @@ -66,16 +60,13 @@ public void readDoesNotExist() throws FileNotFoundException { public void writeThenRead() throws IOException { when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); when(fileSystem.exists(resolvedPath)).thenReturn(true); - fileSystemPersister.write(simple, bufferedSource).blockingFirst(); - BufferedSource source = fileSystemPersister.read(simple).blockingFirst(); + fileSystemPersister.write(simple, bufferedSource).blockingGet(); + BufferedSource source = fileSystemPersister.read(simple).blockingGet(); InOrder inOrder = inOrder(fileSystem); inOrder.verify(fileSystem).write(resolvedPath, bufferedSource); inOrder.verify(fileSystem).exists(resolvedPath); inOrder.verify(fileSystem).read(resolvedPath); assertThat(source).isEqualTo(bufferedSource); - - } - } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java index 5b303c25..feb76542 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/FileSystemRecordPersisterTest.java @@ -5,16 +5,13 @@ import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; import okio.BufferedSource; @@ -24,8 +21,6 @@ import static org.mockito.Mockito.when; public class FileSystemRecordPersisterTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Mock FileSystem fileSystem; @@ -50,18 +45,17 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); - BufferedSource returnedValue = fileSystemPersister.read(simple).blockingFirst(); + BufferedSource returnedValue = fileSystemPersister.read(simple).blockingGet(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { - expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(resolvedPath)) .thenReturn(false); - fileSystemPersister.read(simple).blockingFirst(); + fileSystemPersister.read(simple).test().assertError(FileNotFoundException.class); } @Test @@ -69,8 +63,8 @@ public void readDoesNotExist() throws FileNotFoundException { public void writeThenRead() throws IOException { when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource); when(fileSystem.exists(resolvedPath)).thenReturn(true); - fileSystemPersister.write(simple, bufferedSource).blockingFirst(); - BufferedSource source = fileSystemPersister.read(simple).blockingFirst(); + fileSystemPersister.write(simple, bufferedSource).blockingGet(); + BufferedSource source = fileSystemPersister.read(simple).blockingGet(); InOrder inOrder = inOrder(fileSystem); inOrder.verify(fileSystem).write(resolvedPath, bufferedSource); inOrder.verify(fileSystem).exists(resolvedPath); diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java index 265d4327..31dbe754 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/RecordPersisterTest.java @@ -5,15 +5,12 @@ import com.nytimes.android.external.store2.base.impl.BarCode; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; import okio.BufferedSource; @@ -22,8 +19,6 @@ import static org.mockito.Mockito.when; public class RecordPersisterTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Mock FileSystem fileSystem; @@ -45,7 +40,7 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(simple.toString())).thenReturn(bufferedSource); - BufferedSource returnedValue = sourcePersister.read(simple).blockingFirst(); + BufferedSource returnedValue = sourcePersister.read(simple).blockingGet(); assertThat(returnedValue).isEqualTo(bufferedSource); } @@ -76,16 +71,15 @@ public void missingTest() { @Test @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { - expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(SourcePersister.pathForBarcode(simple))) .thenReturn(false); - sourcePersister.read(simple).blockingFirst(); + sourcePersister.read(simple).test().assertError(FileNotFoundException.class); } @Test public void write() throws IOException { - assertThat(sourcePersister.write(simple, bufferedSource).blockingSingle()).isTrue(); + assertThat(sourcePersister.write(simple, bufferedSource).blockingGet()).isTrue(); } @Test diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java index 6f5879f5..1a16764d 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceDiskDaoStoreTest.java @@ -14,7 +14,8 @@ import java.io.ByteArrayInputStream; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -54,20 +55,20 @@ public void testSimple() { BufferedSource source = source(sourceData); - Observable value = Observable.just(source); + Single value = Single.just(source); when(fetcher.fetch(barCode)) .thenReturn(value); when(diskDAO.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(value); + .thenReturn(Maybe.empty()) + .thenReturn(value.toMaybe()); when(diskDAO.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); - result = store.get(barCode).blockingFirst(); + result = store.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java index cf045515..8e4ed779 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourceFilerReaderWriterStoreTest.java @@ -13,7 +13,8 @@ import java.io.ByteArrayInputStream; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -54,20 +55,20 @@ public void testSimple() { String sourceData = new Gson().toJson(foo); BufferedSource source = source(sourceData); - Observable value = Observable.just(source); + Single value = Single.just(source); when(fetcher.fetch(barCode)) .thenReturn(value); when(fileReader.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(value); + .thenReturn(Maybe.empty()) + .thenReturn(value.toMaybe()); when(fileWriter.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); - Foo result = simpleStore.get(barCode).blockingFirst(); + Foo result = simpleStore.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); - result = simpleStore.get(barCode).blockingFirst(); + result = simpleStore.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java index 776abc6a..bb3bf645 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/SourcePersisterTest.java @@ -12,7 +12,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.util.NoSuchElementException; import okio.BufferedSource; @@ -44,23 +43,22 @@ public void readExists() throws FileNotFoundException { .thenReturn(true); when(fileSystem.read(simple.toString())).thenReturn(bufferedSource); - BufferedSource returnedValue = sourcePersister.read(simple).blockingSingle(); + BufferedSource returnedValue = sourcePersister.read(simple).blockingGet(); assertThat(returnedValue).isEqualTo(bufferedSource); } @Test @SuppressWarnings("CheckReturnValue") public void readDoesNotExist() throws FileNotFoundException { - expectedException.expect(NoSuchElementException.class); when(fileSystem.exists(SourcePersister.pathForBarcode(simple))) .thenReturn(false); - sourcePersister.read(simple).blockingSingle(); + sourcePersister.read(simple).test().assertError(FileNotFoundException.class); } @Test public void write() throws IOException { - assertThat(sourcePersister.write(simple, bufferedSource).blockingSingle()).isTrue(); + assertThat(sourcePersister.write(simple, bufferedSource).blockingGet()).isTrue(); } @Test diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleFailTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleFailTest.java new file mode 100644 index 00000000..bcfae6eb --- /dev/null +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleFailTest.java @@ -0,0 +1,76 @@ +package com.nytimes.android.external.fs2; + +import com.nytimes.android.external.store2.base.Fetcher; +import com.nytimes.android.external.store2.base.Persister; +import com.nytimes.android.external.store2.base.RecordProvider; +import com.nytimes.android.external.store2.base.RecordState; +import com.nytimes.android.external.store2.base.impl.BarCode; +import com.nytimes.android.external.store2.base.impl.Store; +import com.nytimes.android.external.store2.base.impl.StoreBuilder; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; + +import javax.annotation.Nonnull; + +import io.reactivex.Maybe; +import io.reactivex.Single; +import okio.BufferedSource; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class StoreNetworkBeforeStaleFailTest { + private static final Exception sorry = new Exception("sorry"); + private static final BarCode barCode = new BarCode("key", "value"); + @Mock + Fetcher fetcher; + Store store; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + store = StoreBuilder.barcode() + .fetcher(fetcher) + .persister(new TestPersister()) + .networkBeforeStale() + .open(); + + } + + @Test + public void networkBeforeStaleNoNetworkResponse() { + Single exception = Single.error(sorry); + when(fetcher.fetch(barCode)) + .thenReturn(exception); + store.get(barCode).test().assertError(sorry); + verify(fetcher, times(1)).fetch(barCode); + } + + final class TestPersister implements Persister, RecordProvider { + @Nonnull + @Override + public RecordState getRecordState(@Nonnull BarCode barCode) { + return RecordState.MISSING; + } + + @Nonnull + @Override + public Maybe read(@Nonnull BarCode barCode) { + return Maybe.error(sorry); + } + + @Nonnull + @Override + public Single write(@Nonnull BarCode barCode, + @Nonnull BufferedSource bufferedSource) { + return Single.just(true); + } + } +} diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java index cca5ba00..5a1c8d4e 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreNetworkBeforeStaleTest.java @@ -14,7 +14,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import static org.mockito.Mockito.inOrder; @@ -25,6 +26,8 @@ @RunWith(MockitoJUnitRunner.class) public class StoreNetworkBeforeStaleTest { + + Exception sorry = new Exception("sorry"); @Mock Fetcher fetcher; @Mock @@ -55,13 +58,13 @@ public void setUp() { @Test public void networkBeforeDiskWhenStale() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.error(new Exception())); + .thenReturn(Single.error(new Exception())); when(persister.read(barCode)) - .thenReturn(Observable.just(disk1)); //get should return from disk + .thenReturn(Maybe.just(disk1)); //get should return from disk when(persister.getRecordState(barCode)).thenReturn(RecordState.STALE); when(persister.write(barCode, network1)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); store.get(barCode).test().awaitTerminalEvent(); @@ -74,14 +77,14 @@ public void networkBeforeDiskWhenStale() { @Test public void noNetworkBeforeStaleWhenMissingRecord() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(network1)); + .thenReturn(Single.just(network1)); when(persister.read(barCode)) - .thenReturn(Observable.empty(), Observable.just(disk1)); //first call should return + .thenReturn(Maybe.empty(), Maybe.just(disk1)); //first call should return // empty, second call after network should return the network value when(persister.getRecordState(barCode)).thenReturn(RecordState.MISSING); when(persister.write(barCode, network1)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); store.get(barCode).test().awaitTerminalEvent(); @@ -95,7 +98,7 @@ public void noNetworkBeforeStaleWhenMissingRecord() { @Test public void noNetworkBeforeStaleWhenFreshRecord() { when(persister.read(barCode)) - .thenReturn(Observable.just(disk1)); //get should return from disk + .thenReturn(Maybe.just(disk1)); //get should return from disk when(persister.getRecordState(barCode)).thenReturn(RecordState.FRESH); store.get(barCode).test().awaitTerminalEvent(); @@ -104,4 +107,26 @@ public void noNetworkBeforeStaleWhenFreshRecord() { verify(persister, never()).write(barCode, network1); verify(persister, times(1)).read(barCode); } + + @Test + public void networkBeforeStaleNoNetworkResponse() { + Single singleError = Single.error(sorry); + Maybe maybeError = Maybe.error(sorry); + when(fetcher.fetch(barCode)) + .thenReturn(singleError); + when(persister.read(barCode)) + .thenReturn(maybeError, maybeError); //first call should return + // empty, second call after network should return the network value + when(persister.getRecordState(barCode)).thenReturn(RecordState.MISSING); + + when(persister.write(barCode, network1)) + .thenReturn(Single.just(true)); + + store.get(barCode).test().assertError(sorry); + + InOrder inOrder = inOrder(fetcher, persister); + inOrder.verify(persister, times(1)).read(barCode); + inOrder.verify(fetcher, times(1)).fetch(barCode); + inOrder.verify(persister, times(1)).read(barCode); + } } diff --git a/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java index 1054791c..2f3fe9bc 100644 --- a/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java +++ b/filesystem/src/test/java/com/nytimes/android/external/fs2/StoreRefreshWhenStaleTest.java @@ -13,7 +13,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import io.reactivex.observers.TestObserver; import okio.BufferedSource; @@ -53,13 +54,13 @@ public void setUp() { @Test public void diskWasRefreshedWhenStaleRecord() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(network1)); + .thenReturn(Single.just(network1)); when(persister.read(barCode)) - .thenReturn(Observable.just(disk1)); //get should return from disk + .thenReturn(Maybe.just(disk1)); //get should return from disk when(persister.getRecordState(barCode)).thenReturn(RecordState.STALE); when(persister.write(barCode, network1)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); store.get(barCode).test().awaitTerminalEvent(); verify(fetcher, times(1)).fetch(barCode); @@ -72,14 +73,14 @@ public void diskWasRefreshedWhenStaleRecord() { @Test public void diskWasNotRefreshedWhenFreshRecord() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(network1)); + .thenReturn(Single.just(network1)); when(persister.read(barCode)) - .thenReturn(Observable.just(disk1)) //get should return from disk - .thenReturn(Observable.just(disk2)); //backfill should read from disk again + .thenReturn(Maybe.just(disk1)) //get should return from disk + .thenReturn(Maybe.just(disk2)); //backfill should read from disk again when(persister.getRecordState(barCode)).thenReturn(RecordState.FRESH); when(persister.write(barCode, network1)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); TestObserver testObserver = store .get(barCode) diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java index 0e7ffd28..83b8ccf1 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonReaderParserStoreTest.java @@ -21,7 +21,8 @@ import java.io.StringReader; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -48,14 +49,14 @@ public void setUp() throws Exception { Reader source = new StringReader(sourceString); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(source)); + .thenReturn(Single.just(source)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(source)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(source)); when(persister.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); } @Test @@ -67,7 +68,7 @@ public void testDefaultJacksonReaderParser() { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); @@ -86,7 +87,7 @@ public void testCustomJsonFactoryReaderParser() { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java index d11b7602..1a4b23bc 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonSourceParserStoreTest.java @@ -20,7 +20,8 @@ import java.io.ByteArrayInputStream; import java.nio.charset.Charset; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -55,14 +56,14 @@ public void setUp() throws Exception { assertNotNull(bufferedSource); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(bufferedSource)); + .thenReturn(Single.just(bufferedSource)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(bufferedSource)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(bufferedSource)); when(persister.write(barCode, bufferedSource)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); } @Test @@ -74,7 +75,7 @@ public void testDefaultJacksonSourceParser() { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); @@ -93,7 +94,7 @@ public void testCustomJsonFactorySourceParser() { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); diff --git a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java index 1fda4304..1e892371 100644 --- a/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java +++ b/middleware-jackson/src/test/java/com/nytimes/android/external/store2/middleware/jackson/JacksonStringParserStoreTest.java @@ -18,7 +18,8 @@ import org.mockito.MockitoAnnotations; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -44,14 +45,14 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(source)); + .thenReturn(Single.just(source)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(source)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(source)); when(persister.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); } @Test @@ -62,7 +63,7 @@ public void testDefaultJacksonStringParser() { .parser(JacksonParserFactory.createStringParser(Foo.class)) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); @@ -81,7 +82,7 @@ public void testCustomJsonFactoryStringParser() { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); validateFoo(result); diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java index adcd8387..07b0148a 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiSourceParserTest.java @@ -18,7 +18,8 @@ import java.io.ByteArrayInputStream; import java.nio.charset.Charset; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -53,14 +54,14 @@ public void setUp() throws Exception { assertNotNull(bufferedSource); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(bufferedSource)); + .thenReturn(Single.just(bufferedSource)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(bufferedSource)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(bufferedSource)); when(persister.write(barCode, bufferedSource)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); } @Test @@ -74,7 +75,7 @@ public void testSourceParser() throws Exception { .parser(parser) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); assertEquals(result.number, 123); assertEquals(result.string, "abc"); diff --git a/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java index 1ae50aac..4cf9d627 100644 --- a/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java +++ b/middleware-moshi/src/test/java/com/nytimes/android/external/store2/middleware/moshi/MoshiStringParserStoreTest.java @@ -16,7 +16,8 @@ import org.mockito.MockitoAnnotations; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.times; @@ -41,14 +42,14 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(source)); + .thenReturn(Single.just(source)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(source)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(source)); when(persister.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); } @Test @@ -59,7 +60,7 @@ public void testMoshiString() { .parser(MoshiParserFactory.createStringParser(Foo.class)) .open(); - Foo result = store.get(barCode).blockingFirst(); + Foo result = store.get(barCode).blockingGet(); assertEquals(result.number, 123); assertEquals(result.string, "abc"); diff --git a/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java b/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java index 94bbd4a7..1c702848 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store2/GenericParserStoreTest.java @@ -15,7 +15,8 @@ import java.io.ByteArrayInputStream; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -56,20 +57,20 @@ public void testSimple() { BufferedSource source = source(sourceData); - Observable value = Observable.just(source); + Single value = Single.just(source); when(fetcher.fetch(barCode)) .thenReturn(value); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(value); + .thenReturn(Maybe.empty()) + .thenReturn(value.toMaybe()); when(persister.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); - Foo result = simpleStore.get(barCode).blockingFirst(); + Foo result = simpleStore.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); - result = simpleStore.get(barCode).blockingFirst(); + result = simpleStore.get(barCode).blockingGet(); assertThat(result.bar).isEqualTo(KEY); verify(fetcher, times(1)).fetch(barCode); } diff --git a/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java b/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java index c6522c42..5a26bb8b 100644 --- a/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java +++ b/middleware/src/test/java/com/nytimes/android/external/store2/GsonSourceListParserTest.java @@ -18,7 +18,8 @@ import java.util.Arrays; import java.util.List; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import okio.BufferedSource; import okio.Okio; @@ -65,18 +66,18 @@ public void testSimple() { BufferedSource source = source(sourceData); - Observable value = Observable.just(source); + Single value = Single.just(source); when(fetcher.fetch(barCode)) .thenReturn(value); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(value); + .thenReturn(Maybe.empty()) + .thenReturn(value.toMaybe()); when(persister.write(barCode, source)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); - List result = simpleStore.get(barCode).blockingFirst(); + List result = simpleStore.get(barCode).blockingGet(); assertThat(result.get(0).value).isEqualTo("a"); assertThat(result.get(1).value).isEqualTo("b"); assertThat(result.get(2).value).isEqualTo("c"); diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java b/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java index 17ba6b0a..4247bbda 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/DiskRead.java @@ -2,10 +2,9 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; - +import io.reactivex.Maybe; public interface DiskRead { @Nonnull - Observable read(@Nonnull Key key); + Maybe read(@Nonnull Key key); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java b/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java index 8736e463..0eb31de9 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/DiskWrite.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Single; public interface DiskWrite { /** @@ -11,5 +11,5 @@ public interface DiskWrite { * either return Observable.empty or throw an exception */ @Nonnull - Observable write(@Nonnull Key key, @Nonnull Raw raw); + Single write(@Nonnull Key key, @Nonnull Raw raw); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java b/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java index 2e697698..242992c3 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Fetcher.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Single; /** @@ -17,5 +17,5 @@ public interface Fetcher { * @return Observable that emits {@link Raw} data */ @Nonnull - Observable fetch(@Nonnull Key key); + Single fetch(@Nonnull Key key); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java index e79c4d0a..7ceb110e 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/InternalStore.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; /** 2 * this interface allows us to mark a {@link Store} as "internal", exposing methods for retrieving data @@ -12,8 +12,8 @@ */ public interface InternalStore extends Store { @Nonnull - Observable memory(@Nonnull final Key key); + Maybe memory(@Nonnull final Key key); @Nonnull - Observable disk(@Nonnull final Key key); + Maybe disk(@Nonnull final Key key); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java b/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java index 5e29d1e4..d11bdc55 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/Persister.java @@ -2,7 +2,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; /** * Interface for fetching data from persister @@ -19,7 +20,7 @@ public interface Persister extends DiskRead, DiskWrite read(@Nonnull final Key key); + Maybe read(@Nonnull final Key key); /** * @param key to use to store data to persister @@ -27,5 +28,5 @@ public interface Persister extends DiskRead, DiskWrite write(@Nonnull final Key key, @Nonnull final Raw raw); + Single write(@Nonnull final Key key, @Nonnull final Raw raw); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java index fb914e51..30072737 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealInternalStore.java @@ -7,7 +7,6 @@ import com.nytimes.android.external.store2.base.InternalStore; import com.nytimes.android.external.store2.base.Persister; import com.nytimes.android.external.store2.util.KeyParser; -import com.nytimes.android.external.store2.util.OnErrorResumeWithEmpty; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; @@ -17,8 +16,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import io.reactivex.Maybe; +import io.reactivex.MaybeSource; import io.reactivex.Observable; -import io.reactivex.ObservableSource; +import io.reactivex.Single; +import io.reactivex.SingleSource; import io.reactivex.annotations.Experimental; import io.reactivex.annotations.NonNull; import io.reactivex.functions.Action; @@ -37,8 +39,8 @@ */ @SuppressWarnings("PMD") final class RealInternalStore implements InternalStore { - Cache> inFlightRequests; - Cache> memCache; + Cache> inFlightRequests; + Cache> memCache; StalePolicy stalePolicy; Persister persister; KeyParser parser; @@ -110,11 +112,10 @@ private void initMemCache(MemoryPolicy memoryPolicy) { */ @Nonnull @Override - public Observable get(@Nonnull final Key key) { - return Observable.concat( - lazyCache(key), - fetch(key) - ).take(1); + public Single get(@Nonnull final Key key) { + return lazyCache(key) + .switchIfEmpty(fetch(key).toMaybe()) + .toSingle(); } @Override @@ -122,6 +123,7 @@ public Observable get(@Nonnull final Key key) { @Experimental public Observable getRefreshing(@Nonnull final Key key) { return get(key) + .toObservable() .compose(StoreUtil.repeatWhenCacheEvicted(refreshSubject, key)); } @@ -129,37 +131,37 @@ public Observable getRefreshing(@Nonnull final Key key) { /** * @return data from memory */ - private Observable lazyCache(@Nonnull final Key key) { - return Observable - .defer(new Callable>() { + private Maybe lazyCache(@Nonnull final Key key) { + return Maybe + .defer(new Callable>() { @Override - public ObservableSource call() { + public MaybeSource call() { return cache(key); } }) - .onErrorResumeNext(new OnErrorResumeWithEmpty()); + .onErrorResumeNext(Maybe.empty()); } - Observable cache(@Nonnull final Key key) { + Maybe cache(@Nonnull final Key key) { try { - return memCache.get(key, new Callable>() { + return memCache.get(key, new Callable>() { @Nonnull @Override - public Observable call() { + public Maybe call() { return disk(key); } }); } catch (ExecutionException e) { - return Observable.empty(); + return Maybe.empty(); } } @Nonnull @Override - public Observable memory(@Nonnull Key key) { - Observable cachedValue = memCache.getIfPresent(key); - return cachedValue == null ? Observable.empty() : cachedValue; + public Maybe memory(@Nonnull Key key) { + Maybe cachedValue = memCache.getIfPresent(key); + return cachedValue == null ? Maybe.empty() : cachedValue; } /** @@ -171,24 +173,24 @@ public Observable memory(@Nonnull Key key) { */ @Nonnull @Override - public Observable disk(@Nonnull final Key key) { + public Maybe disk(@Nonnull final Key key) { if (StoreUtil.shouldReturnNetworkBeforeStale(persister, stalePolicy, key)) { - return Observable.empty(); + return Maybe.empty(); } return readDisk(key); } - Observable readDisk(@Nonnull final Key key) { + Maybe readDisk(@Nonnull final Key key) { return persister().read(key) - .onErrorResumeNext(new OnErrorResumeWithEmpty()) + .onErrorResumeNext(Maybe.empty()) .map(new Function() { @Override public Parsed apply(@NonNull Raw raw) { return parser.apply(key, raw); } }) - .doOnNext(new Consumer() { + .doOnSuccess(new Consumer() { @Override public void accept(@NonNull Parsed parsed) { updateMemory(key, parsed); @@ -224,10 +226,10 @@ public void accept(@NonNull Throwable throwable) { */ @Nonnull @Override - public Observable fetch(@Nonnull final Key key) { - return Observable.defer(new Callable>() { + public Single fetch(@Nonnull final Key key) { + return Single.defer(new Callable>() { @Override - public ObservableSource call() { + public SingleSource call() { return fetchAndPersist(key); } }); @@ -244,52 +246,54 @@ public ObservableSource call() { * @return observable that emits a {@link Parsed} value */ @Nullable - Observable fetchAndPersist(@Nonnull final Key key) { + Single fetchAndPersist(@Nonnull final Key key) { try { - return inFlightRequests.get(key, new Callable>() { + return inFlightRequests.get(key, new Callable>() { @Nonnull @Override - public Observable call() { + public Single call() { return response(key); } }); } catch (ExecutionException e) { - return Observable.empty(); + return Single.error(e); } } @Nonnull - Observable response(@Nonnull final Key key) { + Single response(@Nonnull final Key key) { return fetcher() .fetch(key) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public ObservableSource apply(@NonNull Raw raw) { + public SingleSource apply(@NonNull Raw raw) { return persister().write(key, raw) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public ObservableSource apply(@NonNull Boolean aBoolean) { - return readDisk(key); + public SingleSource apply(@NonNull Boolean aBoolean) { + return readDisk(key).toSingle(); } }); } }) - .onErrorResumeNext(new Function>() { + .onErrorResumeNext(new Function>() { @Override - public ObservableSource apply(@NonNull Throwable throwable) { + public SingleSource apply(@NonNull Throwable throwable) { if (stalePolicy == StalePolicy.NETWORK_BEFORE_STALE) { - return readDisk(key); + return readDisk(key) + .switchIfEmpty(Maybe.error(throwable)) + .toSingle(); } - return Observable.error(throwable); + return Single.error(throwable); } }) - .doOnNext(new Consumer() { + .doOnSuccess(new Consumer() { @Override public void accept(@NonNull Parsed parsed) { notifySubscribers(parsed); } }) - .doOnTerminate(new Action() { + .doAfterTerminate(new Action() { @Override public void run() { inFlightRequests.invalidate(key); @@ -315,7 +319,7 @@ public Observable stream(@Nonnull Key key) { //If nothing was emitted through the subject yet, start stream with get() value if (!subject.hasValue()) { - return stream.startWith(get(key)); + return stream.startWith(get(key).toObservable()); } return stream; @@ -334,7 +338,7 @@ public Observable stream() { * @param data */ void updateMemory(@Nonnull final Key key, final Parsed data) { - memCache.put(key, Observable.just(data)); + memCache.put(key, Maybe.just(data)); } @Override diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java index 86392a00..4286b8b3 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStore.java @@ -13,7 +13,9 @@ import javax.annotation.Nonnull; +import io.reactivex.Maybe; import io.reactivex.Observable; +import io.reactivex.Single; public class RealStore implements Store { @@ -69,7 +71,7 @@ public RealStore(Fetcher fetcher, @Nonnull @Override - public Observable get(@Nonnull final Key key) { + public Single get(@Nonnull final Key key) { return internalStore.get(key); } @@ -87,7 +89,7 @@ public Observable getRefreshing(@Nonnull Key key) { */ @Nonnull @Override - public Observable fetch(@Nonnull final Key key) { + public Single fetch(@Nonnull final Key key) { return internalStore.fetch(key); } @@ -128,12 +130,12 @@ public void clear(@Nonnull Key key) { internalStore.clear(key); } - protected Observable memory(@Nonnull Key key) { + protected Maybe memory(@Nonnull Key key) { return internalStore.memory(key); } @Nonnull - protected Observable disk(@Nonnull Key key) { + protected Maybe disk(@Nonnull Key key) { return internalStore.disk(key); } diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java index 7f7180c0..e18423b9 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/RealStoreBuilder.java @@ -16,7 +16,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; /** @@ -54,13 +55,13 @@ public RealStoreBuilder persister(final @Nonnull DiskRead() { @Nonnull @Override - public Observable read(@Nonnull Key key) { + public Maybe read(@Nonnull Key key) { return diskRead.read(key); } @Nonnull @Override - public Observable write(@Nonnull Key key, @Nonnull Raw raw) { + public Single write(@Nonnull Key key, @Nonnull Raw raw) { return diskWrite.write(key, raw); } }; @@ -81,7 +82,6 @@ public RealStoreBuilder parser(final @Nonnull KeyParser parsers(final @Nonnull List parsers) { diff --git a/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java b/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java index 165f66c7..21b82216 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java +++ b/store/src/main/java/com/nytimes/android/external/store2/base/impl/Store.java @@ -4,6 +4,7 @@ import javax.annotation.Nonnull; import io.reactivex.Observable; +import io.reactivex.Single; import io.reactivex.annotations.Experimental; @@ -24,7 +25,7 @@ public interface Store { * Sources are Memory Cache, Disk Cache, Inflight, Network Response */ @Nonnull - Observable get(@Nonnull V key); + Single get(@Nonnull V key); /** * Calls store.get(), additionally will repeat anytime store.clear(barcode) is called @@ -39,7 +40,7 @@ public interface Store { * Return an Observable of T for requested Barcode skipping Memory & Disk Cache */ @Nonnull - Observable fetch(@Nonnull V key); + Single fetch(@Nonnull V key); /** * @return an Observable that emits "fresh" new response from the store that hit the fetcher diff --git a/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java b/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java index f12bfdb1..8c6f1299 100644 --- a/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java +++ b/store/src/main/java/com/nytimes/android/external/store2/util/NoopPersister.java @@ -1,6 +1,5 @@ package com.nytimes.android.external.store2.util; - import com.nytimes.android.external.cache.Cache; import com.nytimes.android.external.cache.CacheBuilder; import com.nytimes.android.external.store2.base.Clearable; @@ -11,14 +10,15 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; /** * Pass-through diskdao for stores that don't want to use persister */ public class NoopPersister implements Persister, Clearable { - protected final Cache> networkResponses; + protected final Cache> networkResponses; NoopPersister(MemoryPolicy memoryPolicy) { this.networkResponses = CacheBuilder @@ -50,16 +50,16 @@ public static NoopPersister create(MemoryPolicy memoryPolic @Nonnull @Override - public Observable read(@Nonnull Key key) { - Observable cachedValue = networkResponses.getIfPresent(key); - return cachedValue == null ? Observable.empty() : cachedValue; + public Maybe read(@Nonnull Key key) { + Maybe cachedValue = networkResponses.getIfPresent(key); + return cachedValue == null ? Maybe.empty() : cachedValue; } @Nonnull @Override - public Observable write(@Nonnull Key key, @Nonnull Raw raw) { - networkResponses.put(key, Observable.just(raw)); - return Observable.just(true); + public Single write(@Nonnull Key key, @Nonnull Raw raw) { + networkResponses.put(key, Maybe.just(raw)); + return Single.just(true); } @Override diff --git a/store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java b/store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java deleted file mode 100644 index acd108e9..00000000 --- a/store/src/main/java/com/nytimes/android/external/store2/util/OnErrorResumeWithEmpty.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nytimes.android.external.store2.util; - - -import io.reactivex.Observable; -import io.reactivex.annotations.NonNull; -import io.reactivex.functions.Function; - -/** - * Resume with empty observable on error - */ -public class OnErrorResumeWithEmpty implements Function> { - - @Override - public Observable apply(@NonNull Throwable throwable) { - return Observable.empty(); - } -} diff --git a/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java index aacc7afd..b8821401 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreMemoryTest.java @@ -12,8 +12,7 @@ import javax.annotation.Nonnull; - -import io.reactivex.Observable; +import io.reactivex.Single; import static org.assertj.core.api.Assertions.assertThat; @@ -29,8 +28,8 @@ public void setUp() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.fromCallable(new Callable() { + public Single fetch(@Nonnull BarCode barCode) { + return Single.fromCallable(new Callable() { @Override public Integer call() { return networkCalls++; diff --git a/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java index f5efa452..27d842a3 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/ClearStoreTest.java @@ -17,7 +17,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import static com.nytimes.android.external.store2.GetRefreshingTest.ClearingPersister; import static org.assertj.core.api.Assertions.assertThat; @@ -38,8 +39,8 @@ public void setUp() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.fromCallable(new Callable() { + public Single fetch(@Nonnull BarCode barCode) { + return Single.fromCallable(new Callable() { @Override public Integer call() { return networkCalls.incrementAndGet(); @@ -57,12 +58,12 @@ public void testClearSingleBarCode() { BarCode barcode = new BarCode("type", "key"); when(persister.read(barcode)) - .thenReturn(Observable.empty()) //read from disk on get - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing - .thenReturn(Observable.just(1)); //read from disk after making additional network call - when(persister.write(barcode, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode, 2)).thenReturn(Observable.just(true)); + .thenReturn(Maybe.empty()) //read from disk on get + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing + .thenReturn(Maybe.just(1)); //read from disk after making additional network call + when(persister.write(barcode, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode, 2)).thenReturn(Single.just(true)); store.get(barcode).test().awaitTerminalEvent(); @@ -81,21 +82,21 @@ public void testClearAllBarCodes() { BarCode barcode2 = new BarCode("type2", "key2"); when(persister.read(barcode1)) - .thenReturn(Observable.empty()) //read from disk - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing disk cache - .thenReturn(Observable.just(1)); //read from disk after making additional network call - when(persister.write(barcode1, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode1, 2)).thenReturn(Observable.just(true)); + .thenReturn(Maybe.empty()) //read from disk + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing disk cache + .thenReturn(Maybe.just(1)); //read from disk after making additional network call + when(persister.write(barcode1, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode1, 2)).thenReturn(Single.just(true)); when(persister.read(barcode2)) - .thenReturn(Observable.empty()) //read from disk - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing disk cache - .thenReturn(Observable.just(1)); //read from disk after making additional network call + .thenReturn(Maybe.empty()) //read from disk + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing disk cache + .thenReturn(Maybe.just(1)); //read from disk after making additional network call - when(persister.write(barcode2, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode2, 2)).thenReturn(Observable.just(true)); + when(persister.write(barcode2, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode2, 2)).thenReturn(Single.just(true)); // each request should produce one call diff --git a/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java b/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java index b9be589c..0ed07462 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/DontCacheErrorsTest.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Single; public class DontCacheErrorsTest { @@ -26,8 +26,8 @@ public void setUp() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.fromCallable(new Callable() { + public Single fetch(@Nonnull BarCode barCode) { + return Single.fromCallable(new Callable() { @Override public Integer call() { if (shouldThrow) { diff --git a/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java b/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java index 724ee186..47bac47f 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/GetRefreshingTest.java @@ -18,7 +18,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import io.reactivex.observers.TestObserver; import static org.assertj.core.api.Assertions.assertThat; @@ -38,8 +39,8 @@ public void setUp() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.fromCallable(new Callable() { + public Single fetch(@Nonnull BarCode barCode) { + return Single.fromCallable(new Callable() { @Override public Integer call() { return networkCalls.incrementAndGet(); @@ -55,12 +56,12 @@ public Integer call() { public void testRefreshOnClear() { BarCode barcode = new BarCode("type", "key"); when(persister.read(barcode)) - .thenReturn(Observable.empty()) //read from disk - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing disk cache - .thenReturn(Observable.just(1)); //read from disk after making additional network call - when(persister.write(barcode, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode, 2)).thenReturn(Observable.just(true)); + .thenReturn(Maybe.empty()) //read from disk + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing disk cache + .thenReturn(Maybe.just(1)); //read from disk after making additional network call + when(persister.write(barcode, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode, 2)).thenReturn(Single.just(true)); TestObserver refreshingObservable = store.getRefreshing(barcode).test(); @@ -82,21 +83,21 @@ public void testRefreshOnClearAll() { BarCode barcode2 = new BarCode("type", "key2"); when(persister.read(barcode1)) - .thenReturn(Observable.empty()) //read from disk - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing disk cache - .thenReturn(Observable.just(1)); //read from disk after making additional network call - when(persister.write(barcode1, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode1, 2)).thenReturn(Observable.just(true)); + .thenReturn(Maybe.empty()) //read from disk + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing disk cache + .thenReturn(Maybe.just(1)); //read from disk after making additional network call + when(persister.write(barcode1, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode1, 2)).thenReturn(Single.just(true)); when(persister.read(barcode2)) - .thenReturn(Observable.empty()) //read from disk - .thenReturn(Observable.just(1)) //read from disk after fetching from network - .thenReturn(Observable.empty()) //read from disk after clearing disk cache - .thenReturn(Observable.just(1)); //read from disk after making additional network call + .thenReturn(Maybe.empty()) //read from disk + .thenReturn(Maybe.just(1)) //read from disk after fetching from network + .thenReturn(Maybe.empty()) //read from disk after clearing disk cache + .thenReturn(Maybe.just(1)); //read from disk after making additional network call - when(persister.write(barcode2, 1)).thenReturn(Observable.just(true)); - when(persister.write(barcode2, 2)).thenReturn(Observable.just(true)); + when(persister.write(barcode2, 1)).thenReturn(Single.just(true)); + when(persister.write(barcode2, 2)).thenReturn(Single.just(true)); TestObserver testObservable1 = store.getRefreshing(barcode1).test(); TestObserver testObservable2 = store.getRefreshing(barcode2).test(); @@ -120,13 +121,13 @@ public void clear(@Nonnull BarCode key) { @Nonnull @Override - public Observable read(@Nonnull BarCode barCode) { + public Maybe read(@Nonnull BarCode barCode) { throw new RuntimeException(); } @Nonnull @Override - public Observable write(@Nonnull BarCode barCode, @Nonnull Integer integer) { + public Single write(@Nonnull BarCode barCode, @Nonnull Integer integer) { throw new RuntimeException(); } } diff --git a/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java b/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java index 8ea532cd..759c25a0 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/KeyParserTest.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Single; import io.reactivex.annotations.NonNull; import io.reactivex.observers.TestObserver; @@ -36,8 +36,8 @@ public String apply(@NonNull Integer integer, @NonNull String s) { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull Integer integer) { - return Observable.just(NETWORK); + public Single fetch(@Nonnull Integer integer) { + return Single.just(NETWORK); } }).open(); diff --git a/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java b/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java index 910c08e6..738df9f3 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/SequentialTest.java @@ -12,8 +12,7 @@ import javax.annotation.Nonnull; - -import io.reactivex.Observable; +import io.reactivex.Single; import static org.assertj.core.api.Assertions.assertThat; @@ -29,8 +28,8 @@ public void setUp() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.fromCallable(new Callable() { + public Single fetch(@Nonnull BarCode barCode) { + return Single.fromCallable(new Callable() { @Override public Integer call() { return networkCalls++; @@ -53,8 +52,8 @@ public void sequentially() { @Test public void parallel() { BarCode b = new BarCode("one", "two"); - Observable first = store.get(b); - Observable second = store.get(b); + Single first = store.get(b); + Single second = store.get(b); first.test().awaitTerminalEvent(); second.test().awaitTerminalEvent(); diff --git a/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java index 40a3fe92..0e9effd8 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreBuilderTest.java @@ -14,7 +14,8 @@ import javax.annotation.Nonnull; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import io.reactivex.annotations.NonNull; import static org.assertj.core.api.Assertions.assertThat; @@ -30,21 +31,21 @@ public void testBuildersBuildWithCorrectTypes() { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull Integer key) { - return Observable.just(String.valueOf(key)); + public Single fetch(@Nonnull Integer key) { + return Single.just(String.valueOf(key)); } }) .persister(new Persister() { @Nonnull @Override - public Observable read(@Nonnull Integer key) { - return Observable.just(String.valueOf(key)); + public Maybe read(@Nonnull Integer key) { + return Maybe.just(String.valueOf(key)); } @Nonnull @Override - public Observable write(@Nonnull Integer key, @Nonnull String s) { - return Observable.empty(); + public Single write(@Nonnull Integer key, @Nonnull String s) { + return Single.just(true); } }) .parser(new Parser() { @@ -59,8 +60,8 @@ public Date apply(@NonNull String s) { Store barCodeStore = StoreBuilder.barcode().fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull BarCode barCode) { - return Observable.just(DATE); + public Single fetch(@Nonnull BarCode barCode) { + return Single.just(DATE); } }).open(); @@ -69,14 +70,14 @@ public Observable fetch(@Nonnull BarCode barCode) { .fetcher(new Fetcher() { @Nonnull @Override - public Observable fetch(@Nonnull Integer key) { - return Observable.just(DATE); + public Single fetch(@Nonnull Integer key) { + return Single.just(DATE); } }) .open(); - Date result = store.get(5).blockingFirst(); - result = barCodeStore.get(new BarCode("test", "5")).blockingFirst(); - result = keyStore.get(5).blockingFirst(); + Date result = store.get(5).blockingGet(); + result = barCodeStore.get(new BarCode("test", "5")).blockingGet(); + result = keyStore.get(5).blockingGet(); assertThat(result).isNotNull(); } diff --git a/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java index 9353de8e..e11d6fc7 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreTest.java @@ -18,9 +18,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.Observable; -import io.reactivex.ObservableEmitter; -import io.reactivex.ObservableOnSubscribe; +import io.reactivex.Maybe; +import io.reactivex.Single; +import io.reactivex.SingleEmitter; +import io.reactivex.SingleOnSubscribe; import io.reactivex.annotations.NonNull; import io.reactivex.functions.BiFunction; @@ -57,19 +58,19 @@ public void testSimple() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(NETWORK)); + .thenReturn(Single.just(NETWORK)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(DISK)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(DISK)); when(persister.write(barCode, NETWORK)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); - String value = simpleStore.get(barCode).blockingFirst(); + String value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(DISK); - value = simpleStore.get(barCode).blockingFirst(); + value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(DISK); verify(fetcher, times(1)).fetch(barCode); } @@ -83,13 +84,12 @@ public void testDoubleTap() { .fetcher(fetcher) .open(); - Observable networkObservable = - Observable.create(new ObservableOnSubscribe() { + Single networkSingle = + Single.create(new SingleOnSubscribe() { @Override - public void subscribe(ObservableEmitter emitter) { + public void subscribe(SingleEmitter emitter) { if (counter.incrementAndGet() == 1) { - emitter.onNext(NETWORK); - + emitter.onSuccess(NETWORK); } else { emitter.onError(new RuntimeException("Yo Dawg your inflight is broken")); } @@ -98,14 +98,14 @@ public void subscribe(ObservableEmitter emitter) { when(fetcher.fetch(barCode)) - .thenReturn(networkObservable); + .thenReturn(networkSingle); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(DISK)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(DISK)); when(persister.write(barCode, NETWORK)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); String response = simpleStore.get(barCode).zipWith(simpleStore.get(barCode), @@ -115,7 +115,7 @@ public String apply(@NonNull String s, @NonNull String s2) { return "hello"; } }) - .blockingFirst(); + .blockingGet(); assertThat(response).isEqualTo("hello"); verify(fetcher, times(1)).fetch(barCode); } @@ -128,16 +128,16 @@ public void testSubclass() { simpleStore.clear(); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(NETWORK)); + .thenReturn(Single.just(NETWORK)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(DISK)); - when(persister.write(barCode, NETWORK)).thenReturn(Observable.just(true)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(DISK)); + when(persister.write(barCode, NETWORK)).thenReturn(Single.just(true)); - String value = simpleStore.get(barCode).blockingFirst(); + String value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(DISK); - value = simpleStore.get(barCode).blockingFirst(); + value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(DISK); verify(fetcher, times(1)).fetch(barCode); } @@ -151,16 +151,16 @@ public void testNoopAndDefault() { when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(NETWORK)); + .thenReturn(Single.just(NETWORK)); - String value = simpleStore.get(barCode).blockingFirst(); + String value = simpleStore.get(barCode).blockingGet(); verify(fetcher, times(1)).fetch(barCode); verify(persister, times(1)).write(barCode, NETWORK); verify(persister, times(2)).read(barCode); assertThat(value).isEqualTo(NETWORK); - value = simpleStore.get(barCode).blockingFirst(); + value = simpleStore.get(barCode).blockingGet(); verify(persister, times(2)).read(barCode); verify(persister, times(1)).write(barCode, NETWORK); verify(fetcher, times(1)).fetch(barCode); diff --git a/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java b/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java index 19217e67..29292b10 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/StoreWithParserTest.java @@ -12,7 +12,8 @@ import org.mockito.MockitoAnnotations; -import io.reactivex.Observable; +import io.reactivex.Maybe; +import io.reactivex.Single; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; @@ -44,20 +45,20 @@ public void testSimple() throws Exception { .open(); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(NETWORK)); + .thenReturn(Single.just(NETWORK)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(DISK)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(DISK)); when(persister.write(barCode, NETWORK)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); when(parser.apply(DISK)).thenReturn(barCode.getKey()); - String value = simpleStore.get(barCode).blockingFirst(); + String value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(barCode.getKey()); - value = simpleStore.get(barCode).blockingFirst(); + value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(barCode.getKey()); verify(fetcher, times(1)).fetch(barCode); } @@ -69,20 +70,20 @@ public void testSubclass() throws Exception { Store simpleStore = new SampleParsingStore(fetcher, persister, parser); when(fetcher.fetch(barCode)) - .thenReturn(Observable.just(NETWORK)); + .thenReturn(Single.just(NETWORK)); when(persister.read(barCode)) - .thenReturn(Observable.empty()) - .thenReturn(Observable.just(DISK)); + .thenReturn(Maybe.empty()) + .thenReturn(Maybe.just(DISK)); when(persister.write(barCode, NETWORK)) - .thenReturn(Observable.just(true)); + .thenReturn(Single.just(true)); when(parser.apply(DISK)).thenReturn(barCode.getKey()); - String value = simpleStore.get(barCode).blockingFirst(); + String value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(barCode.getKey()); - value = simpleStore.get(barCode).blockingFirst(); + value = simpleStore.get(barCode).blockingGet(); assertThat(value).isEqualTo(barCode.getKey()); verify(fetcher, times(1)).fetch(barCode); } diff --git a/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java b/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java index 3c1962ef..5e805b28 100644 --- a/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java +++ b/store/src/test/java/com/nytimes/android/external/store2/util/NoopPersisterTest.java @@ -13,9 +13,9 @@ public class NoopPersisterTest { @Test public void writeReadTest() { NoopPersister persister = NoopPersister.create(); - boolean success = persister.write(barCode, "foo").blockingFirst(); + boolean success = persister.write(barCode, "foo").blockingGet(); assertThat(success).isTrue(); - String rawValue = persister.read(barCode).blockingFirst(); + String rawValue = persister.read(barCode).blockingGet(); assertThat(rawValue).isEqualTo("foo"); }