diff --git a/data/.gitignore b/app/.gitignore similarity index 100% rename from data/.gitignore rename to app/.gitignore diff --git a/presentation/build.gradle b/app/build.gradle similarity index 80% rename from presentation/build.gradle rename to app/build.gradle index be2b2abb..2d3501d8 100644 --- a/presentation/build.gradle +++ b/app/build.gradle @@ -1,6 +1,16 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'me.tatarka:gradle-retrolambda:3.2.3' + } +} + apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'com.fernandocejas.frodo' +apply plugin: 'me.tatarka.retrolambda' frodo { enabled = true @@ -24,8 +34,8 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } packagingOptions { @@ -65,17 +75,19 @@ android { dependencies { def presentationDependencies = rootProject.ext.presentationDependencies def presentationTestDependencies = rootProject.ext.presentationTestDependencies + def dataDependencies = rootProject.ext.dataDependencies + def testDependencies = rootProject.ext.dataTestDependencies def developmentDependencies = rootProject.ext.developmentDependencies - compile project(':domain') - compile project(':data') - apt presentationDependencies.daggerCompiler compile presentationDependencies.dagger + compile dataDependencies.okHttp + compile dataDependencies.gson compile presentationDependencies.butterKnife compile presentationDependencies.recyclerView compile presentationDependencies.rxJava compile presentationDependencies.rxAndroid + compile dataDependencies.androidAnnotations provided presentationDependencies.javaxAnnotation androidTestCompile presentationTestDependencies.mockito @@ -84,6 +96,11 @@ dependencies { androidTestCompile presentationTestDependencies.espresso androidTestCompile presentationTestDependencies.testingSupportLib + testCompile testDependencies.junit + testCompile testDependencies.assertj + testCompile testDependencies.mockito + testCompile testDependencies.robolectric + //Development compile developmentDependencies.leakCanary } diff --git a/data/proguard-rules.pro b/app/proguard-rules.pro similarity index 100% rename from data/proguard-rules.pro rename to app/proguard-rules.pro diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserDetailsActivityTest.java b/app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserDetailsActivityTest.java similarity index 93% rename from presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserDetailsActivityTest.java rename to app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserDetailsActivityTest.java index 812c4e0d..0c0d3a62 100644 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserDetailsActivityTest.java +++ b/app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserDetailsActivityTest.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.test.view.activity; +package com.fernandocejas.android10.sample.test.users; import android.app.Fragment; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.view.activity.UserDetailsActivity; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.users.UserDetailsActivity; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.assertion.ViewAssertions.matches; diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserListActivityTest.java b/app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserListActivityTest.java similarity index 90% rename from presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserListActivityTest.java rename to app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserListActivityTest.java index 187e6f8d..edea2a06 100644 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/view/activity/UserListActivityTest.java +++ b/app/src/androidTest/java/com/fernandocejas/android10/sample/test/users/UserListActivityTest.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.test.view.activity; +package com.fernandocejas.android10.sample.test.users; import android.app.Fragment; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.view.activity.UserListActivity; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.users.UserListActivity; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; diff --git a/presentation/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml similarity index 80% rename from presentation/src/main/AndroidManifest.xml rename to app/src/main/AndroidManifest.xml index 1aaea4ca..2bac0477 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,13 +1,13 @@ + package="com.fernandocejas.android10.sample.app"> @@ -22,12 +22,12 @@ diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/AndroidApplication.java b/app/src/main/java/com/fernandocejas/android10/sample/app/AndroidApplication.java similarity index 79% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/AndroidApplication.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/AndroidApplication.java index 006bb115..1f20ff75 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/AndroidApplication.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/AndroidApplication.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation; +package com.fernandocejas.android10.sample.app; import android.app.Application; -import com.fernandocejas.android10.sample.presentation.internal.di.components.ApplicationComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.components.DaggerApplicationComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.ApplicationModule; +import com.fernandocejas.android10.sample.app.core.di.components.ApplicationComponent; +import com.fernandocejas.android10.sample.app.core.di.components.DaggerApplicationComponent; +import com.fernandocejas.android10.sample.app.core.di.modules.ApplicationModule; import com.squareup.leakcanary.LeakCanary; /** diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/HasComponent.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/HasComponent.java similarity index 91% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/HasComponent.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/HasComponent.java index 1e744459..ffc7e6c5 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/HasComponent.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/HasComponent.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di; +package com.fernandocejas.android10.sample.app.core.di; /** * Interface representing a contract for clients that contains a component for dependency injection. diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/PerActivity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/PerActivity.java similarity index 93% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/PerActivity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/PerActivity.java index ba04d9c6..0022703c 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/PerActivity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/PerActivity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di; +package com.fernandocejas.android10.sample.app.core.di; import java.lang.annotation.Retention; import javax.inject.Scope; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ActivityComponent.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ActivityComponent.java similarity index 76% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ActivityComponent.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ActivityComponent.java index a7ffc0d9..2ff16d27 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ActivityComponent.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ActivityComponent.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.components; +package com.fernandocejas.android10.sample.app.core.di.components; import android.app.Activity; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.ActivityModule; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; +import com.fernandocejas.android10.sample.app.core.di.modules.ActivityModule; import dagger.Component; /** @@ -25,7 +25,7 @@ * Activity-level components should extend this component. * * Subtypes of ActivityComponent should be decorated with annotation: - * {@link com.fernandocejas.android10.sample.presentation.internal.di.PerActivity} + * {@link PerActivity} */ @PerActivity @Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class) diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ApplicationComponent.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ApplicationComponent.java similarity index 70% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ApplicationComponent.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ApplicationComponent.java index 23e08b1d..a2175030 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/ApplicationComponent.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/components/ApplicationComponent.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.components; +package com.fernandocejas.android10.sample.app.core.di.components; import android.content.Context; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.ApplicationModule; -import com.fernandocejas.android10.sample.presentation.view.activity.BaseActivity; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.users.UserRepository; +import com.fernandocejas.android10.sample.app.core.di.modules.ApplicationModule; +import com.fernandocejas.android10.sample.app.view.activity.BaseActivity; import dagger.Component; import javax.inject.Singleton; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ActivityModule.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ActivityModule.java similarity index 87% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ActivityModule.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ActivityModule.java index 3f7f97c1..84fcb472 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ActivityModule.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ActivityModule.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.modules; +package com.fernandocejas.android10.sample.app.core.di.modules; import android.app.Activity; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; import dagger.Module; import dagger.Provides; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ApplicationModule.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ApplicationModule.java similarity index 66% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ApplicationModule.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ApplicationModule.java index c6ef8e62..185b18d1 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/ApplicationModule.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/di/modules/ApplicationModule.java @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.modules; +package com.fernandocejas.android10.sample.app.core.di.modules; import android.content.Context; -import com.fernandocejas.android10.sample.data.cache.UserCache; -import com.fernandocejas.android10.sample.data.cache.UserCacheImpl; -import com.fernandocejas.android10.sample.data.executor.JobExecutor; -import com.fernandocejas.android10.sample.data.repository.UserDataRepository; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; -import com.fernandocejas.android10.sample.presentation.AndroidApplication; -import com.fernandocejas.android10.sample.presentation.UIThread; -import com.fernandocejas.android10.sample.presentation.navigation.Navigator; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; +import com.fernandocejas.android10.sample.app.users.cache.UserCacheImpl; +import com.fernandocejas.android10.sample.app.core.executor.JobExecutor; +import com.fernandocejas.android10.sample.app.users.UserDataRepository; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.users.UserRepository; +import com.fernandocejas.android10.sample.app.AndroidApplication; +import com.fernandocejas.android10.sample.app.core.executor.UIThread; import dagger.Module; import dagger.Provides; import javax.inject.Singleton; diff --git a/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/JobExecutor.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/JobExecutor.java new file mode 100644 index 00000000..dbe656d1 --- /dev/null +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/JobExecutor.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 Fernando Cejas Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fernandocejas.android10.sample.app.core.executor; + +import android.support.annotation.NonNull; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import javax.inject.Inject; +import javax.inject.Singleton; + +/** + * Decorated {@link java.util.concurrent.ThreadPoolExecutor} + */ +@Singleton +public class JobExecutor implements ThreadExecutor { + private final ThreadPoolExecutor threadPoolExecutor; + + @Inject + JobExecutor() { + this.threadPoolExecutor = new ThreadPoolExecutor(3, 5, 10, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(), new JobThreadFactory()); + } + + @Override public void execute(@NonNull Runnable runnable) { + this.threadPoolExecutor.execute(runnable); + } + + private static class JobThreadFactory implements ThreadFactory { + private int counter = 0; + + @Override public Thread newThread(@NonNull Runnable runnable) { + return new Thread(runnable, "android_" + counter++); + } + } +} diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/PostExecutionThread.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/PostExecutionThread.java similarity index 94% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/PostExecutionThread.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/PostExecutionThread.java index a69f2859..4e212d6f 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/PostExecutionThread.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/PostExecutionThread.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.executor; +package com.fernandocejas.android10.sample.app.core.executor; import rx.Scheduler; diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/ThreadExecutor.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/ThreadExecutor.java similarity index 74% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/ThreadExecutor.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/ThreadExecutor.java index ef19ebcc..06fe7d25 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/executor/ThreadExecutor.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/ThreadExecutor.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.executor; +package com.fernandocejas.android10.sample.app.core.executor; import java.util.concurrent.Executor; /** * Executor implementation can be based on different frameworks or techniques of asynchronous - * execution, but every implementation will execute the - * {@link com.fernandocejas.android10.sample.domain.interactor.UseCase} out of the UI thread. + * execution, but every implementation will execute UseCases out of the UI thread. */ public interface ThreadExecutor extends Executor {} diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/UIThread.java b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/UIThread.java similarity index 86% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/UIThread.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/UIThread.java index bd4ceca4..6a53a58c 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/UIThread.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/core/executor/UIThread.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation; +package com.fernandocejas.android10.sample.app.core.executor; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; import javax.inject.Inject; import javax.inject.Singleton; import rx.Scheduler; @@ -29,7 +28,7 @@ public class UIThread implements PostExecutionThread { @Inject - public UIThread() {} + UIThread() {} @Override public Scheduler getScheduler() { return AndroidSchedulers.mainThread(); diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/net/ApiConnection.java b/app/src/main/java/com/fernandocejas/android10/sample/app/data/ApiConnection.java similarity index 91% rename from data/src/main/java/com/fernandocejas/android10/sample/data/net/ApiConnection.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/data/ApiConnection.java index b5e153b7..cc825b17 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/net/ApiConnection.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/data/ApiConnection.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.net; +package com.fernandocejas.android10.sample.app.data; import android.support.annotation.Nullable; import com.squareup.okhttp.OkHttpClient; @@ -29,7 +29,7 @@ * Implements {@link java.util.concurrent.Callable} so when executed asynchronously can * return a value. */ -public class ApiConnection implements Callable { +class ApiConnection implements Callable { private static final String CONTENT_TYPE_LABEL = "Content-Type"; private static final String CONTENT_TYPE_VALUE_JSON = "application/json; charset=utf-8"; @@ -41,7 +41,7 @@ private ApiConnection(String url) throws MalformedURLException { this.url = new URL(url); } - public static ApiConnection createGET(String url) throws MalformedURLException { + static ApiConnection createGET(String url) throws MalformedURLException { return new ApiConnection(url); } @@ -52,7 +52,7 @@ public static ApiConnection createGET(String url) throws MalformedURLException { * @return A string response */ @Nullable - public String requestSyncCall() { + String requestSyncCall() { connectToApi(); return response; } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/FileManager.java b/app/src/main/java/com/fernandocejas/android10/sample/app/data/FileManager.java similarity index 97% rename from data/src/main/java/com/fernandocejas/android10/sample/data/cache/FileManager.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/data/FileManager.java index 2cdd43b4..91d753af 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/FileManager.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/data/FileManager.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache; +package com.fernandocejas.android10.sample.app.data; import android.content.Context; import android.content.SharedPreferences; @@ -69,7 +69,7 @@ public String readFileContent(File file) { FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((stringLine = bufferedReader.readLine()) != null) { - fileContentBuilder.append(stringLine + "\n"); + fileContentBuilder.append(stringLine).append("\n"); } bufferedReader.close(); fileReader.close(); diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApi.java b/app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApi.java similarity index 85% rename from data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApi.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApi.java index f99d8f52..1f7629b7 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApi.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApi.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.net; +package com.fernandocejas.android10.sample.app.data; -import com.fernandocejas.android10.sample.data.entity.UserEntity; +import com.fernandocejas.android10.sample.app.users.UserEntity; import java.util.List; import rx.Observable; @@ -23,7 +23,7 @@ * RestApi for retrieving data from the network. */ public interface RestApi { - String API_BASE_URL = "http://www.android10.org/myapi/"; + String API_BASE_URL = "https://raw.githubusercontent.com/android10/Sample-Data/master/Android-CleanArchitecture/"; /** Api url for getting all users */ String API_URL_GET_USER_LIST = API_BASE_URL + "users.json"; diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApiImpl.java b/app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApiImpl.java similarity index 93% rename from data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApiImpl.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApiImpl.java index 1450000f..7d2213c4 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/net/RestApiImpl.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/data/RestApiImpl.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.net; +package com.fernandocejas.android10.sample.app.data; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.data.entity.mapper.UserEntityJsonMapper; -import com.fernandocejas.android10.sample.data.exception.NetworkConnectionException; +import com.fernandocejas.android10.sample.app.users.UserEntity; +import com.fernandocejas.android10.sample.app.exception.NetworkConnectionException; +import com.fernandocejas.android10.sample.app.users.UserEntityJsonMapper; import com.fernandocejas.frodo.annotation.RxLogObservable; import java.net.MalformedURLException; import java.util.List; diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializer.java b/app/src/main/java/com/fernandocejas/android10/sample/app/data/Serializer.java similarity index 56% rename from data/src/main/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializer.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/data/Serializer.java index 6e053187..f72116bb 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializer.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/data/Serializer.java @@ -13,42 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache.serializer; +package com.fernandocejas.android10.sample.app.data; -import com.fernandocejas.android10.sample.data.entity.UserEntity; import com.google.gson.Gson; import javax.inject.Inject; import javax.inject.Singleton; /** - * Class user as Serializer/Deserializer for user entities. + * Json Serializer/Deserializer. */ @Singleton -public class JsonSerializer { +public class Serializer { private final Gson gson = new Gson(); - @Inject - public JsonSerializer() {} + @Inject Serializer() {} /** * Serialize an object to Json. - * - * @param userEntity {@link UserEntity} to serialize. + * @param object to serialize. */ - public String serialize(UserEntity userEntity) { - String jsonString = gson.toJson(userEntity, UserEntity.class); - return jsonString; + public String serialize(Object object, Class clazz) { + return gson.toJson(object, clazz); } /** * Deserialize a json representation of an object. - * - * @param jsonString A json string to deserialize. - * @return {@link UserEntity} + * @param string A json string to deserialize. */ - public UserEntity deserialize(String jsonString) { - UserEntity userEntity = gson.fromJson(jsonString, UserEntity.class); - return userEntity; + public T deserialize(String string, Class clazz) { + return gson.fromJson(string, clazz); } } diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundle.java b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundle.java similarity index 94% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundle.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundle.java index 1942eba1..27127829 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundle.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundle.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.exception; +package com.fernandocejas.android10.sample.app.exception; /** * Wrapper around Exceptions used to manage default errors. diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/ErrorBundle.java b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorBundle.java similarity index 93% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/ErrorBundle.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorBundle.java index 2ae66ebb..4c3862f9 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/exception/ErrorBundle.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorBundle.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.exception; +package com.fernandocejas.android10.sample.app.exception; /** * Interface to represent a wrapper around an {@link java.lang.Exception} to manage errors. diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/exception/ErrorMessageFactory.java b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorMessageFactory.java similarity index 84% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/exception/ErrorMessageFactory.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorMessageFactory.java index 861f1d73..ab0d6a65 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/exception/ErrorMessageFactory.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/ErrorMessageFactory.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.exception; +package com.fernandocejas.android10.sample.app.exception; import android.content.Context; -import com.fernandocejas.android10.sample.data.exception.NetworkConnectionException; -import com.fernandocejas.android10.sample.data.exception.UserNotFoundException; -import com.fernandocejas.android10.sample.presentation.R; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.users.UserNotFoundException; /** * Factory used to create error messages from an Exception as a condition. diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/NetworkConnectionException.java b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/NetworkConnectionException.java similarity index 78% rename from data/src/main/java/com/fernandocejas/android10/sample/data/exception/NetworkConnectionException.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/exception/NetworkConnectionException.java index 987a106b..d04c5bfe 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/NetworkConnectionException.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/NetworkConnectionException.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.exception; +package com.fernandocejas.android10.sample.app.exception; /** * Exception throw by the application when a there is a network connection exception. @@ -24,14 +24,6 @@ public NetworkConnectionException() { super(); } - public NetworkConnectionException(final String message) { - super(message); - } - - public NetworkConnectionException(final String message, final Throwable cause) { - super(message, cause); - } - public NetworkConnectionException(final Throwable cause) { super(cause); } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundle.java b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundle.java similarity index 80% rename from data/src/main/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundle.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundle.java index c232adbe..41302be4 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundle.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundle.java @@ -13,18 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.exception; - -import com.fernandocejas.android10.sample.domain.exception.ErrorBundle; +package com.fernandocejas.android10.sample.app.exception; /** * Wrapper around Exceptions used to manage errors in the repository. */ -public class RepositoryErrorBundle implements ErrorBundle { +class RepositoryErrorBundle implements ErrorBundle { private final Exception exception; - public RepositoryErrorBundle(Exception exception) { + RepositoryErrorBundle(Exception exception) { this.exception = exception; } diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/DefaultSubscriber.java b/app/src/main/java/com/fernandocejas/android10/sample/app/interactor/DefaultSubscriber.java similarity index 94% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/DefaultSubscriber.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/interactor/DefaultSubscriber.java index 81abea5c..7f60d47a 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/DefaultSubscriber.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/interactor/DefaultSubscriber.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.interactor; /** * Default subscriber base class to be used whenever you want default error handling. diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/UseCase.java b/app/src/main/java/com/fernandocejas/android10/sample/app/interactor/UseCase.java similarity index 91% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/UseCase.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/interactor/UseCase.java index 5bb63005..22e79e8b 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/UseCase.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/interactor/UseCase.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.interactor; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import rx.Subscriber; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; import rx.Observable; +import rx.Subscriber; import rx.Subscription; import rx.schedulers.Schedulers; import rx.subscriptions.Subscriptions; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/navigation/Navigator.java b/app/src/main/java/com/fernandocejas/android10/sample/app/navigation/Navigator.java similarity index 86% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/navigation/Navigator.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/navigation/Navigator.java index fb2577aa..466cae05 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/navigation/Navigator.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/navigation/Navigator.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.navigation; +package com.fernandocejas.android10.sample.app.navigation; import android.content.Context; import android.content.Intent; -import com.fernandocejas.android10.sample.presentation.view.activity.UserDetailsActivity; -import com.fernandocejas.android10.sample.presentation.view.activity.UserListActivity; +import com.fernandocejas.android10.sample.app.users.UserDetailsActivity; +import com.fernandocejas.android10.sample.app.users.UserListActivity; import javax.inject.Inject; import javax.inject.Singleton; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/Presenter.java b/app/src/main/java/com/fernandocejas/android10/sample/app/presenter/Presenter.java similarity index 94% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/Presenter.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/presenter/Presenter.java index 3768fe4f..1ea546aa 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/Presenter.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/presenter/Presenter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.presenter; +package com.fernandocejas.android10.sample.app.presenter; /** * Interface representing a Presenter in a model view presenter (MVP) pattern. diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStore.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStore.java similarity index 86% rename from data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStore.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStore.java index a5eda5ad..bda7fa02 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStore.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStore.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.cache.UserCache; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.data.net.RestApi; +import com.fernandocejas.android10.sample.app.data.RestApi; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; import java.util.List; import rx.Observable; import rx.functions.Action1; diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStore.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStore.java similarity index 87% rename from data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStore.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStore.java index fb02b4ad..04bcf234 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStore.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStore.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.cache.UserCache; -import com.fernandocejas.android10.sample.data.entity.UserEntity; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; import java.util.List; import rx.Observable; diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetails.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserDetails.java similarity index 72% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetails.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserDetails.java index 134fc4d0..e542a69d 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetails.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserDetails.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.interactor.UseCase; import javax.inject.Inject; import rx.Observable; @@ -26,13 +25,13 @@ * This class is an implementation of {@link UseCase} that represents a use case for * retrieving data related to an specific {@link User}. */ -public class GetUserDetails extends UseCase { +class GetUserDetails extends UseCase { private final int userId; private final UserRepository userRepository; @Inject - public GetUserDetails(int userId, UserRepository userRepository, + GetUserDetails(int userId, UserRepository userRepository, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) { super(threadExecutor, postExecutionThread); this.userId = userId; diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserList.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserList.java similarity index 70% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserList.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserList.java index 0780ff3d..366979b9 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/interactor/GetUserList.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/GetUserList.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.interactor.UseCase; import javax.inject.Inject; import rx.Observable; @@ -26,12 +25,12 @@ * This class is an implementation of {@link UseCase} that represents a use case for * retrieving a collection of all {@link User}. */ -public class GetUserList extends UseCase { +class GetUserList extends UseCase { private final UserRepository userRepository; @Inject - public GetUserList(UserRepository userRepository, ThreadExecutor threadExecutor, + GetUserList(UserRepository userRepository, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) { super(threadExecutor, postExecutionThread); this.userRepository = userRepository; diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/User.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/User.java similarity index 51% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/User.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/User.java index d62a021d..45d4a162 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/User.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/User.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain; +package com.fernandocejas.android10.sample.app.users; /** * Class that represents a User in the domain layer. */ -public class User { +class User { private final int userId; - public User(int userId) { + User(int userId) { this.userId = userId; } @@ -32,62 +32,47 @@ public User(int userId) { private String description; private int followers; - public int getUserId() { + int getUserId() { return userId; } - public String getCoverUrl() { + String getCoverUrl() { return coverUrl; } - public void setCoverUrl(String coverUrl) { + void setCoverUrl(String coverUrl) { this.coverUrl = coverUrl; } - public String getFullName() { + String getFullName() { return fullName; } - public void setFullName(String fullName) { + void setFullName(String fullName) { this.fullName = fullName; } - public String getEmail() { + String getEmail() { return email; } - public void setEmail(String email) { + void setEmail(String email) { this.email = email; } - public String getDescription() { + String getDescription() { return description; } - public void setDescription(String description) { + void setDescription(String description) { this.description = description; } - public int getFollowers() { + int getFollowers() { return followers; } - public void setFollowers(int followers) { + void setFollowers(int followers) { this.followers = followers; } - - @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("***** User Details *****\n"); - stringBuilder.append("id=" + this.getUserId() + "\n"); - stringBuilder.append("cover url=" + this.getCoverUrl() + "\n"); - stringBuilder.append("fullname=" + this.getFullName() + "\n"); - stringBuilder.append("email=" + this.getEmail() + "\n"); - stringBuilder.append("description=" + this.getDescription() + "\n"); - stringBuilder.append("followers=" + this.getFollowers() + "\n"); - stringBuilder.append("*******************************"); - - return stringBuilder.toString(); - } } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/UserComponent.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserComponent.java similarity index 57% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/UserComponent.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserComponent.java index ef4872f5..ac67f0b8 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/components/UserComponent.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserComponent.java @@ -13,22 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.components; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.ActivityModule; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.UserModule; -import com.fernandocejas.android10.sample.presentation.view.fragment.UserDetailsFragment; -import com.fernandocejas.android10.sample.presentation.view.fragment.UserListFragment; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; +import com.fernandocejas.android10.sample.app.core.di.components.ActivityComponent; +import com.fernandocejas.android10.sample.app.core.di.components.ApplicationComponent; +import com.fernandocejas.android10.sample.app.core.di.modules.ActivityModule; import dagger.Component; /** - * A scope {@link com.fernandocejas.android10.sample.presentation.internal.di.PerActivity} component. + * A scope {@link PerActivity} component. * Injects user specific Fragments. */ @PerActivity @Component(dependencies = ApplicationComponent.class, modules = {ActivityModule.class, UserModule.class}) -public interface UserComponent extends ActivityComponent { +interface UserComponent extends ActivityComponent { void inject(UserListFragment userListFragment); void inject(UserDetailsFragment userDetailsFragment); } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/UserDataRepository.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataRepository.java similarity index 78% rename from data/src/main/java/com/fernandocejas/android10/sample/data/repository/UserDataRepository.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataRepository.java index 35112eb6..2196fa85 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/UserDataRepository.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataRepository.java @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.entity.mapper.UserEntityDataMapper; -import com.fernandocejas.android10.sample.data.repository.datasource.UserDataStore; -import com.fernandocejas.android10.sample.data.repository.datasource.UserDataStoreFactory; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; @@ -41,7 +36,7 @@ public class UserDataRepository implements UserRepository { * @param userEntityDataMapper {@link UserEntityDataMapper}. */ @Inject - public UserDataRepository(UserDataStoreFactory dataStoreFactory, + UserDataRepository(UserDataStoreFactory dataStoreFactory, UserEntityDataMapper userEntityDataMapper) { this.userDataStoreFactory = dataStoreFactory; this.userEntityDataMapper = userEntityDataMapper; diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStore.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStore.java similarity index 82% rename from data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStore.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStore.java index 744bae1e..8f066f60 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStore.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStore.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.entity.UserEntity; import java.util.List; import rx.Observable; /** * Interface that represents a data store from where data is retrieved. */ -public interface UserDataStore { +interface UserDataStore { /** * Get an {@link rx.Observable} which will emit a List of {@link UserEntity}. */ diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactory.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactory.java similarity index 69% rename from data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactory.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactory.java index 90c979e2..945aeebe 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactory.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactory.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.support.annotation.NonNull; -import com.fernandocejas.android10.sample.data.cache.UserCache; -import com.fernandocejas.android10.sample.data.entity.mapper.UserEntityJsonMapper; -import com.fernandocejas.android10.sample.data.net.RestApi; -import com.fernandocejas.android10.sample.data.net.RestApiImpl; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; +import com.fernandocejas.android10.sample.app.data.RestApi; +import com.fernandocejas.android10.sample.app.data.RestApiImpl; import javax.inject.Inject; import javax.inject.Singleton; @@ -34,7 +33,7 @@ public class UserDataStoreFactory { private final UserCache userCache; @Inject - public UserDataStoreFactory(@NonNull Context context, @NonNull UserCache userCache) { + UserDataStoreFactory(@NonNull Context context, @NonNull UserCache userCache) { this.context = context.getApplicationContext(); this.userCache = userCache; } @@ -42,7 +41,7 @@ public UserDataStoreFactory(@NonNull Context context, @NonNull UserCache userCac /** * Create {@link UserDataStore} from a user id. */ - public UserDataStore create(int userId) { + UserDataStore create(int userId) { UserDataStore userDataStore; if (!this.userCache.isExpired() && this.userCache.isCached(userId)) { @@ -57,9 +56,9 @@ public UserDataStore create(int userId) { /** * Create {@link UserDataStore} to retrieve data from the Cloud. */ - public UserDataStore createCloudDataStore() { - UserEntityJsonMapper userEntityJsonMapper = new UserEntityJsonMapper(); - RestApi restApi = new RestApiImpl(this.context, userEntityJsonMapper); + UserDataStore createCloudDataStore() { + final UserEntityJsonMapper userEntityJsonMapper = new UserEntityJsonMapper(); + final RestApi restApi = new RestApiImpl(this.context, userEntityJsonMapper); return new CloudUserDataStore(restApi, this.userCache); } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserDetailsActivity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsActivity.java similarity index 78% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserDetailsActivity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsActivity.java index fb2ae486..f1a276e2 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserDetailsActivity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsActivity.java @@ -3,18 +3,15 @@ * * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.activity; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Window; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.internal.di.HasComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.components.DaggerUserComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.components.UserComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.UserModule; -import com.fernandocejas.android10.sample.presentation.view.fragment.UserDetailsFragment; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.core.di.HasComponent; +import com.fernandocejas.android10.sample.app.view.activity.BaseActivity; /** * Activity that shows details of a certain user. diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserDetailsFragment.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsFragment.java similarity index 86% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserDetailsFragment.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsFragment.java index e5c51334..2e302124 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserDetailsFragment.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsFragment.java @@ -2,7 +2,7 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.fragment; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.os.Bundle; @@ -15,12 +15,9 @@ import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.internal.di.components.UserComponent; -import com.fernandocejas.android10.sample.presentation.model.UserModel; -import com.fernandocejas.android10.sample.presentation.presenter.UserDetailsPresenter; -import com.fernandocejas.android10.sample.presentation.view.UserDetailsView; -import com.fernandocejas.android10.sample.presentation.view.component.AutoLoadImageView; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.view.component.AutoLoadImageView; +import com.fernandocejas.android10.sample.app.view.fragment.BaseFragment; import javax.inject.Inject; /** diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserDetailsPresenter.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenter.java similarity index 76% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserDetailsPresenter.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenter.java index e10967c0..76abdb2e 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserDetailsPresenter.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenter.java @@ -13,19 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.presenter; +package com.fernandocejas.android10.sample.app.users; import android.support.annotation.NonNull; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.domain.exception.DefaultErrorBundle; -import com.fernandocejas.android10.sample.domain.exception.ErrorBundle; -import com.fernandocejas.android10.sample.domain.interactor.DefaultSubscriber; -import com.fernandocejas.android10.sample.domain.interactor.UseCase; -import com.fernandocejas.android10.sample.presentation.exception.ErrorMessageFactory; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; -import com.fernandocejas.android10.sample.presentation.mapper.UserModelDataMapper; -import com.fernandocejas.android10.sample.presentation.model.UserModel; -import com.fernandocejas.android10.sample.presentation.view.UserDetailsView; +import com.fernandocejas.android10.sample.app.presenter.Presenter; +import com.fernandocejas.android10.sample.app.exception.DefaultErrorBundle; +import com.fernandocejas.android10.sample.app.exception.ErrorBundle; +import com.fernandocejas.android10.sample.app.interactor.DefaultSubscriber; +import com.fernandocejas.android10.sample.app.interactor.UseCase; +import com.fernandocejas.android10.sample.app.exception.ErrorMessageFactory; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; import com.fernandocejas.frodo.annotation.RxLogSubscriber; import javax.inject.Inject; import javax.inject.Named; @@ -35,7 +32,7 @@ * layer. */ @PerActivity -public class UserDetailsPresenter implements Presenter { +class UserDetailsPresenter implements Presenter { private UserDetailsView viewDetailsView; @@ -43,7 +40,7 @@ public class UserDetailsPresenter implements Presenter { private final UserModelDataMapper userModelDataMapper; @Inject - public UserDetailsPresenter(@Named("userDetails") UseCase getUserDetailsUseCase, + UserDetailsPresenter(@Named("userDetails") UseCase getUserDetailsUseCase, UserModelDataMapper userModelDataMapper) { this.getUserDetailsUseCase = getUserDetailsUseCase; this.userModelDataMapper = userModelDataMapper; @@ -65,7 +62,7 @@ public void setView(@NonNull UserDetailsView view) { /** * Initializes the presenter by start retrieving user details. */ - public void initialize() { + void initialize() { this.loadUserDetails(); } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserDetailsView.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsView.java similarity index 68% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserDetailsView.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsView.java index a4f72f9f..20d942fd 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserDetailsView.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserDetailsView.java @@ -2,15 +2,15 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.presentation.model.UserModel; +import com.fernandocejas.android10.sample.app.view.component.LoadDataView; /** * Interface representing a View in a model view presenter (MVP) pattern. * In this case is used as a view representing a user profile. */ -public interface UserDetailsView extends LoadDataView { +interface UserDetailsView extends LoadDataView { /** * Render a user in the UI. * diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/UserEntity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntity.java similarity index 55% rename from data/src/main/java/com/fernandocejas/android10/sample/data/entity/UserEntity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntity.java index 8d8fb1fc..f581170e 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/UserEntity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.entity; +package com.fernandocejas.android10.sample.app.users; import com.google.gson.annotations.SerializedName; @@ -52,58 +52,27 @@ public void setUserId(int userId) { this.userId = userId; } - public String getCoverUrl() { + String getCoverUrl() { return coverUrl; } - public void setCoverUrl(String coverUrl) { - this.coverUrl = coverUrl; - } - public String getFullname() { return fullname; } - public void setFullname(String fullname) { + void setFullname(String fullname) { this.fullname = fullname; } - public String getDescription() { + String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - public int getFollowers() { return followers; } - public void setFollowers(int followers) { - this.followers = followers; - } - - public String getEmail() { + String getEmail() { return email; } - - public void setEmail(String email) { - this.email = email; - } - - @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("***** User Entity Details *****\n"); - stringBuilder.append("id=" + this.getUserId() + "\n"); - stringBuilder.append("cover url=" + this.getCoverUrl() + "\n"); - stringBuilder.append("fullname=" + this.getFullname() + "\n"); - stringBuilder.append("email=" + this.getEmail() + "\n"); - stringBuilder.append("description=" + this.getDescription() + "\n"); - stringBuilder.append("followers=" + this.getFollowers() + "\n"); - stringBuilder.append("*******************************"); - - return stringBuilder.toString(); - } } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapper.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapper.java similarity index 78% rename from data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapper.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapper.java index 1ecbdcdc..1c72b48b 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapper.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapper.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.entity.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.domain.User; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -31,7 +29,7 @@ public class UserEntityDataMapper { @Inject - public UserEntityDataMapper() {} + UserEntityDataMapper() {} /** * Transform a {@link UserEntity} into an {@link User}. @@ -39,7 +37,7 @@ public UserEntityDataMapper() {} * @param userEntity Object to be transformed. * @return {@link User} if valid {@link UserEntity} otherwise null. */ - public User transform(UserEntity userEntity) { + User transform(UserEntity userEntity) { User user = null; if (userEntity != null) { user = new User(userEntity.getUserId()); @@ -59,11 +57,10 @@ public User transform(UserEntity userEntity) { * @param userEntityCollection Object Collection to be transformed. * @return {@link User} if valid {@link UserEntity} otherwise null. */ - public List transform(Collection userEntityCollection) { - List userList = new ArrayList<>(20); - User user; + List transform(Collection userEntityCollection) { + final List userList = new ArrayList<>(20); for (UserEntity userEntity : userEntityCollection) { - user = transform(userEntity); + final User user = transform(userEntity); if (user != null) { userList.add(user); } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapper.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapper.java similarity index 69% rename from data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapper.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapper.java index 8e8dca90..d835b301 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapper.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapper.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.entity.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.entity.UserEntity; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; @@ -31,7 +30,7 @@ public class UserEntityJsonMapper { private final Gson gson; @Inject - public UserEntityJsonMapper() { + UserEntityJsonMapper() { this.gson = new Gson(); } @@ -43,14 +42,8 @@ public UserEntityJsonMapper() { * @throws com.google.gson.JsonSyntaxException if the json string is not a valid json structure. */ public UserEntity transformUserEntity(String userJsonResponse) throws JsonSyntaxException { - try { - Type userEntityType = new TypeToken() {}.getType(); - UserEntity userEntity = this.gson.fromJson(userJsonResponse, userEntityType); - - return userEntity; - } catch (JsonSyntaxException jsonException) { - throw jsonException; - } + final Type userEntityType = new TypeToken() {}.getType(); + return this.gson.fromJson(userJsonResponse, userEntityType); } /** @@ -62,15 +55,7 @@ public UserEntity transformUserEntity(String userJsonResponse) throws JsonSyntax */ public List transformUserEntityCollection(String userListJsonResponse) throws JsonSyntaxException { - - List userEntityCollection; - try { - Type listOfUserEntityType = new TypeToken>() {}.getType(); - userEntityCollection = this.gson.fromJson(userListJsonResponse, listOfUserEntityType); - - return userEntityCollection; - } catch (JsonSyntaxException jsonException) { - throw jsonException; - } + final Type listOfUserEntityType = new TypeToken>() {}.getType(); + return this.gson.fromJson(userListJsonResponse, listOfUserEntityType); } } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserListActivity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListActivity.java similarity index 71% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserListActivity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListActivity.java index fb1bdea8..bc26f709 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/UserListActivity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListActivity.java @@ -3,18 +3,15 @@ * * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.activity; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Window; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.internal.di.HasComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.components.DaggerUserComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.components.UserComponent; -import com.fernandocejas.android10.sample.presentation.model.UserModel; -import com.fernandocejas.android10.sample.presentation.view.fragment.UserListFragment; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.core.di.HasComponent; +import com.fernandocejas.android10.sample.app.view.activity.BaseActivity; /** * Activity that shows a list of Users. diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserListFragment.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListFragment.java similarity index 81% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserListFragment.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListFragment.java index 6da47c9a..3596a254 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserListFragment.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListFragment.java @@ -3,7 +3,7 @@ * * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.fragment; +package com.fernandocejas.android10.sample.app.users; import android.app.Activity; import android.content.Context; @@ -17,13 +17,8 @@ import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.internal.di.components.UserComponent; -import com.fernandocejas.android10.sample.presentation.model.UserModel; -import com.fernandocejas.android10.sample.presentation.presenter.UserListPresenter; -import com.fernandocejas.android10.sample.presentation.view.UserListView; -import com.fernandocejas.android10.sample.presentation.view.adapter.UsersAdapter; -import com.fernandocejas.android10.sample.presentation.view.adapter.UsersLayoutManager; +import com.fernandocejas.android10.sample.app.R; +import com.fernandocejas.android10.sample.app.view.fragment.BaseFragment; import java.util.Collection; import javax.inject.Inject; @@ -162,12 +157,9 @@ private void loadUserList() { UserListFragment.this.loadUserList(); } - private UsersAdapter.OnItemClickListener onItemClickListener = - new UsersAdapter.OnItemClickListener() { - @Override public void onUserItemClicked(UserModel userModel) { - if (UserListFragment.this.userListPresenter != null && userModel != null) { - UserListFragment.this.userListPresenter.onUserClicked(userModel); - } - } - }; + private UsersAdapter.OnItemClickListener onItemClickListener = userModel -> { + if (UserListFragment.this.userListPresenter != null && userModel != null) { + UserListFragment.this.userListPresenter.onUserClicked(userModel); + } + }; } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserListPresenter.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListPresenter.java similarity index 77% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserListPresenter.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListPresenter.java index 72cf4b51..e98a612d 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserListPresenter.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListPresenter.java @@ -13,19 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.presenter; +package com.fernandocejas.android10.sample.app.users; import android.support.annotation.NonNull; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.domain.exception.DefaultErrorBundle; -import com.fernandocejas.android10.sample.domain.exception.ErrorBundle; -import com.fernandocejas.android10.sample.domain.interactor.DefaultSubscriber; -import com.fernandocejas.android10.sample.domain.interactor.UseCase; -import com.fernandocejas.android10.sample.presentation.exception.ErrorMessageFactory; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; -import com.fernandocejas.android10.sample.presentation.mapper.UserModelDataMapper; -import com.fernandocejas.android10.sample.presentation.model.UserModel; -import com.fernandocejas.android10.sample.presentation.view.UserListView; +import com.fernandocejas.android10.sample.app.presenter.Presenter; +import com.fernandocejas.android10.sample.app.exception.DefaultErrorBundle; +import com.fernandocejas.android10.sample.app.exception.ErrorBundle; +import com.fernandocejas.android10.sample.app.interactor.DefaultSubscriber; +import com.fernandocejas.android10.sample.app.interactor.UseCase; +import com.fernandocejas.android10.sample.app.exception.ErrorMessageFactory; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; import java.util.Collection; import java.util.List; import javax.inject.Inject; @@ -44,7 +41,7 @@ public class UserListPresenter implements Presenter { private final UserModelDataMapper userModelDataMapper; @Inject - public UserListPresenter(@Named("userList") UseCase getUserListUserCase, + UserListPresenter(@Named("userList") UseCase getUserListUserCase, UserModelDataMapper userModelDataMapper) { this.getUserListUseCase = getUserListUserCase; this.userModelDataMapper = userModelDataMapper; @@ -66,7 +63,7 @@ public void setView(@NonNull UserListView view) { /** * Initializes the presenter by start retrieving the user list. */ - public void initialize() { + void initialize() { this.loadUserList(); } @@ -79,7 +76,7 @@ private void loadUserList() { this.getUserList(); } - public void onUserClicked(UserModel userModel) { + void onUserClicked(UserModel userModel) { this.viewListView.viewUser(userModel); } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserListView.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListView.java similarity index 78% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserListView.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListView.java index 6a850775..aa05f776 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/UserListView.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserListView.java @@ -2,16 +2,16 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.presentation.model.UserModel; +import com.fernandocejas.android10.sample.app.view.component.LoadDataView; import java.util.Collection; /** * Interface representing a View in a model view presenter (MVP) pattern. * In this case is used as a view representing a list of {@link UserModel}. */ -public interface UserListView extends LoadDataView { +interface UserListView extends LoadDataView { /** * Render a user list in the UI. * diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/model/UserModel.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModel.java similarity index 54% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/model/UserModel.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModel.java index d13ae2d4..a0373e6c 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/model/UserModel.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModel.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.model; +package com.fernandocejas.android10.sample.app.users; /** * Class that represents a user in the presentation layer. @@ -36,58 +36,43 @@ public int getUserId() { return userId; } - public String getCoverUrl() { + String getCoverUrl() { return coverUrl; } - public void setCoverUrl(String coverUrl) { + void setCoverUrl(String coverUrl) { this.coverUrl = coverUrl; } - public String getFullName() { + String getFullName() { return fullName; } - public void setFullName(String fullName) { + void setFullName(String fullName) { this.fullName = fullName; } - public String getEmail() { + String getEmail() { return email; } - public void setEmail(String email) { + void setEmail(String email) { this.email = email; } - public String getDescription() { + String getDescription() { return description; } - public void setDescription(String description) { + void setDescription(String description) { this.description = description; } - public int getFollowers() { + int getFollowers() { return followers; } - public void setFollowers(int followers) { + void setFollowers(int followers) { this.followers = followers; } - - @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("***** User Model Details *****\n"); - stringBuilder.append("id=" + this.getUserId() + "\n"); - stringBuilder.append("cover url=" + this.getCoverUrl() + "\n"); - stringBuilder.append("fullname=" + this.getFullName() + "\n"); - stringBuilder.append("email=" + this.getEmail() + "\n"); - stringBuilder.append("description=" + this.getDescription() + "\n"); - stringBuilder.append("followers=" + this.getFollowers() + "\n"); - stringBuilder.append("*******************************"); - - return stringBuilder.toString(); - } } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/mapper/UserModelDataMapper.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapper.java similarity index 79% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/mapper/UserModelDataMapper.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapper.java index 3c64bac3..5ae55aa8 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/mapper/UserModelDataMapper.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapper.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; -import com.fernandocejas.android10.sample.presentation.model.UserModel; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -28,10 +26,10 @@ * presentation layer. */ @PerActivity -public class UserModelDataMapper { +class UserModelDataMapper { @Inject - public UserModelDataMapper() {} + UserModelDataMapper() {} /** * Transform a {@link User} into an {@link UserModel}. @@ -39,11 +37,11 @@ public UserModelDataMapper() {} * @param user Object to be transformed. * @return {@link UserModel}. */ - public UserModel transform(User user) { + UserModel transform(User user) { if (user == null) { throw new IllegalArgumentException("Cannot transform a null value"); } - UserModel userModel = new UserModel(user.getUserId()); + final UserModel userModel = new UserModel(user.getUserId()); userModel.setCoverUrl(user.getCoverUrl()); userModel.setFullName(user.getFullName()); userModel.setEmail(user.getEmail()); @@ -59,7 +57,7 @@ public UserModel transform(User user) { * @param usersCollection Objects to be transformed. * @return List of {@link UserModel}. */ - public Collection transform(Collection usersCollection) { + Collection transform(Collection usersCollection) { Collection userModelsCollection; if (usersCollection != null && !usersCollection.isEmpty()) { diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/UserModule.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModule.java similarity index 64% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/UserModule.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModule.java index 3f12d332..c901bc3e 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/internal/di/modules/UserModule.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserModule.java @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.presentation.internal.di.modules; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.interactor.GetUserDetails; -import com.fernandocejas.android10.sample.domain.interactor.GetUserList; -import com.fernandocejas.android10.sample.domain.interactor.UseCase; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; -import com.fernandocejas.android10.sample.presentation.internal.di.PerActivity; +import com.fernandocejas.android10.sample.app.core.di.PerActivity; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.interactor.UseCase; import dagger.Module; import dagger.Provides; import javax.inject.Named; @@ -30,13 +27,13 @@ * Dagger module that provides user related collaborators. */ @Module -public class UserModule { +class UserModule { private int userId = -1; - public UserModule() {} + UserModule() {} - public UserModule(int userId) { + UserModule(int userId) { this.userId = userId; } @@ -50,4 +47,4 @@ public UserModule(int userId) { PostExecutionThread postExecutionThread) { return new GetUserDetails(userId, userRepository, threadExecutor, postExecutionThread); } -} \ No newline at end of file +} diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/UserNotFoundException.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserNotFoundException.java similarity index 67% rename from data/src/main/java/com/fernandocejas/android10/sample/data/exception/UserNotFoundException.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserNotFoundException.java index 8667eaa4..0233682d 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/exception/UserNotFoundException.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserNotFoundException.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,26 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.exception; +package com.fernandocejas.android10.sample.app.users; /** * Exception throw by the application when a User search can't return a valid result. */ public class UserNotFoundException extends Exception { - public UserNotFoundException() { super(); } - - public UserNotFoundException(final String message) { - super(message); - } - - public UserNotFoundException(final String message, final Throwable cause) { - super(message, cause); - } - - public UserNotFoundException(final Throwable cause) { - super(cause); - } } diff --git a/domain/src/main/java/com/fernandocejas/android10/sample/domain/repository/UserRepository.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserRepository.java similarity index 90% rename from domain/src/main/java/com/fernandocejas/android10/sample/domain/repository/UserRepository.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UserRepository.java index 69c40a03..edb43466 100644 --- a/domain/src/main/java/com/fernandocejas/android10/sample/domain/repository/UserRepository.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UserRepository.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.repository; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.User; import java.util.List; import rx.Observable; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersAdapter.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersAdapter.java similarity index 72% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersAdapter.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersAdapter.java index 110a1002..10b47666 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersAdapter.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersAdapter.java @@ -2,7 +2,7 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.adapter; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.support.v7.widget.RecyclerView; @@ -12,8 +12,7 @@ import android.widget.TextView; import butterknife.Bind; import butterknife.ButterKnife; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.model.UserModel; +import com.fernandocejas.android10.sample.app.R; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -22,9 +21,9 @@ /** * Adaptar that manages a collection of {@link UserModel}. */ -public class UsersAdapter extends RecyclerView.Adapter { +class UsersAdapter extends RecyclerView.Adapter { - public interface OnItemClickListener { + interface OnItemClickListener { void onUserItemClicked(UserModel userModel); } @@ -34,7 +33,7 @@ public interface OnItemClickListener { private OnItemClickListener onItemClickListener; @Inject - public UsersAdapter(Context context) { + UsersAdapter(Context context) { this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.usersCollection = Collections.emptyList(); @@ -52,11 +51,9 @@ public UsersAdapter(Context context) { @Override public void onBindViewHolder(UserViewHolder holder, final int position) { final UserModel userModel = this.usersCollection.get(position); holder.textViewTitle.setText(userModel.getFullName()); - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override public void onClick(View v) { - if (UsersAdapter.this.onItemClickListener != null) { - UsersAdapter.this.onItemClickListener.onUserItemClicked(userModel); - } + holder.itemView.setOnClickListener(v -> { + if (UsersAdapter.this.onItemClickListener != null) { + UsersAdapter.this.onItemClickListener.onUserItemClicked(userModel); } }); } @@ -65,13 +62,13 @@ public UsersAdapter(Context context) { return position; } - public void setUsersCollection(Collection usersCollection) { + void setUsersCollection(Collection usersCollection) { this.validateUsersCollection(usersCollection); this.usersCollection = (List) usersCollection; this.notifyDataSetChanged(); } - public void setOnItemClickListener (OnItemClickListener onItemClickListener) { + void setOnItemClickListener (OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; } @@ -84,7 +81,7 @@ private void validateUsersCollection(Collection usersCollection) { static class UserViewHolder extends RecyclerView.ViewHolder { @Bind(R.id.title) TextView textViewTitle; - public UserViewHolder(View itemView) { + UserViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersLayoutManager.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersLayoutManager.java similarity index 64% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersLayoutManager.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersLayoutManager.java index a7facf5b..6b8c1292 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/adapter/UsersLayoutManager.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/UsersLayoutManager.java @@ -2,7 +2,7 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.adapter; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; import android.support.v7.widget.LinearLayoutManager; @@ -10,8 +10,8 @@ /** * Layout manager to position items inside a {@link android.support.v7.widget.RecyclerView}. */ -public class UsersLayoutManager extends LinearLayoutManager { - public UsersLayoutManager(Context context) { +class UsersLayoutManager extends LinearLayoutManager { + UsersLayoutManager(Context context) { super(context); } } diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCache.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCache.java similarity index 92% rename from data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCache.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCache.java index 302cb760..61fb3143 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCache.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCache.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache; +package com.fernandocejas.android10.sample.app.users.cache; -import com.fernandocejas.android10.sample.data.entity.UserEntity; +import com.fernandocejas.android10.sample.app.users.UserEntity; import rx.Observable; /** diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCacheImpl.java b/app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCacheImpl.java similarity index 76% rename from data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCacheImpl.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCacheImpl.java index 32367fb4..5ab81405 100644 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/cache/UserCacheImpl.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/users/cache/UserCacheImpl.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache; +package com.fernandocejas.android10.sample.app.users.cache; import android.content.Context; -import com.fernandocejas.android10.sample.data.cache.serializer.JsonSerializer; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.data.exception.UserNotFoundException; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.data.FileManager; +import com.fernandocejas.android10.sample.app.data.Serializer; +import com.fernandocejas.android10.sample.app.users.UserEntity; +import com.fernandocejas.android10.sample.app.users.UserNotFoundException; import java.io.File; import javax.inject.Inject; import javax.inject.Singleton; @@ -39,7 +40,7 @@ public class UserCacheImpl implements UserCache { private final Context context; private final File cacheDir; - private final JsonSerializer serializer; + private final Serializer serializer; private final FileManager fileManager; private final ThreadExecutor threadExecutor; @@ -47,27 +48,27 @@ public class UserCacheImpl implements UserCache { * Constructor of the class {@link UserCacheImpl}. * * @param context A - * @param userCacheSerializer {@link JsonSerializer} for object serialization. + * @param serializer {@link Serializer} for object serialization. * @param fileManager {@link FileManager} for saving serialized objects to the file system. */ - @Inject - public UserCacheImpl(Context context, JsonSerializer userCacheSerializer, - FileManager fileManager, ThreadExecutor executor) { - if (context == null || userCacheSerializer == null || fileManager == null || executor == null) { + @Inject UserCacheImpl(Context context, Serializer serializer, FileManager fileManager, + ThreadExecutor executor) { + if (context == null || serializer == null || fileManager == null || executor == null) { throw new IllegalArgumentException("Invalid null parameter"); } this.context = context.getApplicationContext(); this.cacheDir = this.context.getCacheDir(); - this.serializer = userCacheSerializer; + this.serializer = serializer; this.fileManager = fileManager; this.threadExecutor = executor; } @Override public Observable get(final int userId) { return Observable.create(subscriber -> { - File userEntityFile = UserCacheImpl.this.buildFile(userId); - String fileContent = UserCacheImpl.this.fileManager.readFileContent(userEntityFile); - UserEntity userEntity = UserCacheImpl.this.serializer.deserialize(fileContent); + final File userEntityFile = UserCacheImpl.this.buildFile(userId); + final String fileContent = UserCacheImpl.this.fileManager.readFileContent(userEntityFile); + final UserEntity userEntity = + UserCacheImpl.this.serializer.deserialize(fileContent, UserEntity.class); if (userEntity != null) { subscriber.onNext(userEntity); @@ -80,19 +81,18 @@ public UserCacheImpl(Context context, JsonSerializer userCacheSerializer, @Override public void put(UserEntity userEntity) { if (userEntity != null) { - File userEntityFile = this.buildFile(userEntity.getUserId()); + final File userEntityFile = this.buildFile(userEntity.getUserId()); if (!isCached(userEntity.getUserId())) { - String jsonString = this.serializer.serialize(userEntity); - this.executeAsynchronously(new CacheWriter(this.fileManager, userEntityFile, - jsonString)); + final String jsonString = this.serializer.serialize(userEntity, UserEntity.class); + this.executeAsynchronously(new CacheWriter(this.fileManager, userEntityFile, jsonString)); setLastCacheUpdateTimeMillis(); } } } @Override public boolean isCached(int userId) { - File userEntitiyFile = this.buildFile(userId); - return this.fileManager.exists(userEntitiyFile); + final File userEntityFile = this.buildFile(userId); + return this.fileManager.exists(userEntityFile); } @Override public boolean isExpired() { @@ -119,7 +119,7 @@ public UserCacheImpl(Context context, JsonSerializer userCacheSerializer, * @return A valid file. */ private File buildFile(int userId) { - StringBuilder fileNameBuilder = new StringBuilder(); + final StringBuilder fileNameBuilder = new StringBuilder(); fileNameBuilder.append(this.cacheDir.getPath()); fileNameBuilder.append(File.separator); fileNameBuilder.append(DEFAULT_FILE_NAME); @@ -132,7 +132,7 @@ private File buildFile(int userId) { * Set in millis, the last time the cache was accessed. */ private void setLastCacheUpdateTimeMillis() { - long currentMillis = System.currentTimeMillis(); + final long currentMillis = System.currentTimeMillis(); this.fileManager.writeToPreferences(this.context, SETTINGS_FILE_NAME, SETTINGS_KEY_LAST_CACHE_UPDATE, currentMillis); } diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/BaseActivity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/BaseActivity.java similarity index 61% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/BaseActivity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/BaseActivity.java index 23ad8b5e..5b18e491 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/BaseActivity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/BaseActivity.java @@ -1,13 +1,13 @@ -package com.fernandocejas.android10.sample.presentation.view.activity; +package com.fernandocejas.android10.sample.app.view.activity; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; -import com.fernandocejas.android10.sample.presentation.AndroidApplication; -import com.fernandocejas.android10.sample.presentation.internal.di.components.ApplicationComponent; -import com.fernandocejas.android10.sample.presentation.internal.di.modules.ActivityModule; -import com.fernandocejas.android10.sample.presentation.navigation.Navigator; +import com.fernandocejas.android10.sample.app.AndroidApplication; +import com.fernandocejas.android10.sample.app.core.di.components.ApplicationComponent; +import com.fernandocejas.android10.sample.app.core.di.modules.ActivityModule; +import com.fernandocejas.android10.sample.app.navigation.Navigator; import javax.inject.Inject; /** @@ -15,7 +15,7 @@ */ public abstract class BaseActivity extends Activity { - @Inject Navigator navigator; + @Inject protected Navigator navigator; @Override protected void onCreate(Bundle savedInstanceState) { @@ -30,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) { * @param fragment The fragment to be added. */ protected void addFragment(int containerViewId, Fragment fragment) { - FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction(); + final FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction(); fragmentTransaction.add(containerViewId, fragment); fragmentTransaction.commit(); } @@ -38,7 +38,7 @@ protected void addFragment(int containerViewId, Fragment fragment) { /** * Get the Main Application component for dependency injection. * - * @return {@link com.fernandocejas.android10.sample.presentation.internal.di.components.ApplicationComponent} + * @return {@link com.fernandocejas.android10.sample.app.core.di.components.ApplicationComponent} */ protected ApplicationComponent getApplicationComponent() { return ((AndroidApplication) getApplication()).getApplicationComponent(); @@ -47,7 +47,7 @@ protected ApplicationComponent getApplicationComponent() { /** * Get an Activity module for dependency injection. * - * @return {@link com.fernandocejas.android10.sample.presentation.internal.di.modules.ActivityModule} + * @return {@link com.fernandocejas.android10.sample.app.core.di.modules.ActivityModule} */ protected ActivityModule getActivityModule() { return new ActivityModule(this); diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/MainActivity.java b/app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/MainActivity.java similarity index 83% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/MainActivity.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/MainActivity.java index 9f1530b9..62648c5f 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/activity/MainActivity.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/view/activity/MainActivity.java @@ -1,11 +1,11 @@ -package com.fernandocejas.android10.sample.presentation.view.activity; +package com.fernandocejas.android10.sample.app.view.activity; import android.os.Bundle; import android.widget.Button; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; -import com.fernandocejas.android10.sample.presentation.R; +import com.fernandocejas.android10.sample.app.R; /** * Main application screen. This is the app entry point. diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/component/AutoLoadImageView.java b/app/src/main/java/com/fernandocejas/android10/sample/app/view/component/AutoLoadImageView.java similarity index 84% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/component/AutoLoadImageView.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/view/component/AutoLoadImageView.java index c45e8d6c..8679c4ce 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/component/AutoLoadImageView.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/view/component/AutoLoadImageView.java @@ -3,7 +3,7 @@ * * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.component; +package com.fernandocejas.android10.sample.app.view.component; import android.app.Activity; import android.content.Context; @@ -17,10 +17,8 @@ import android.util.Log; import android.widget.ImageView; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -83,25 +81,6 @@ public void setImageUrl(final String imageUrl) { } } - /** - * Set a place holder used for loading when an image is being downloaded from the internet. - * - * @param resourceId The resource id to use as a place holder. - */ - public void setImagePlaceHolder(int resourceId) { - this.imagePlaceHolderResId = resourceId; - this.loadImagePlaceHolder(); - } - - /** - * Invalidate the internal cache by evicting all cached elements. - */ - public void invalidateImageCache() { - if (this.cache != null) { - this.cache.evictAll(); - } - } - /** * Loads and image from the internet (and cache it) or from the internal cache. * @@ -140,11 +119,7 @@ private void loadImageFromUrl(final String imageUrl) { * @param bitmap The image to load. */ private void loadBitmap(final Bitmap bitmap) { - ((Activity) getContext()).runOnUiThread(new Runnable() { - @Override public void run() { - AutoLoadImageView.this.setImageBitmap(bitmap); - } - }); + ((Activity) getContext()).runOnUiThread(() -> AutoLoadImageView.this.setImageBitmap(bitmap)); } /** @@ -152,12 +127,8 @@ private void loadBitmap(final Bitmap bitmap) { */ private void loadImagePlaceHolder() { if (this.imagePlaceHolderResId != -1) { - ((Activity) getContext()).runOnUiThread(new Runnable() { - @Override public void run() { - AutoLoadImageView.this.setImageResource( - AutoLoadImageView.this.imagePlaceHolderResId); - } - }); + ((Activity) getContext()).runOnUiThread(() -> AutoLoadImageView.this.setImageResource( + AutoLoadImageView.this.imagePlaceHolderResId)); } } @@ -195,9 +166,9 @@ private void cacheBitmap(Bitmap bitmap, String fileName) { private boolean isThereInternetConnection() { boolean isConnected; - ConnectivityManager connectivityManager = + final ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); + final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting()); return isConnected; @@ -238,14 +209,12 @@ interface Callback { */ void download(String imageUrl, Callback callback) { try { - URLConnection conn = new URL(imageUrl).openConnection(); + final URLConnection conn = new URL(imageUrl).openConnection(); conn.connect(); - Bitmap bitmap = BitmapFactory.decodeStream(conn.getInputStream()); + final Bitmap bitmap = BitmapFactory.decodeStream(conn.getInputStream()); if (callback != null) { callback.onImageDownloaded(bitmap); } - } catch (MalformedURLException e) { - reportError(callback); } catch (IOException e) { reportError(callback); } @@ -305,25 +274,12 @@ synchronized void put(Bitmap bitmap, String fileName) { bitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); - } catch (FileNotFoundException e) { - Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } } - /** - * Invalidate and expire the cache. - */ - void evictAll() { - if (cacheDir.exists()) { - for (File file : cacheDir.listFiles()) { - file.delete(); - } - } - } - /** * Creates a file name from an image url * diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/LoadDataView.java b/app/src/main/java/com/fernandocejas/android10/sample/app/view/component/LoadDataView.java similarity index 92% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/LoadDataView.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/view/component/LoadDataView.java index ebcfe095..98d26a2e 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/LoadDataView.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/view/component/LoadDataView.java @@ -2,7 +2,7 @@ * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view; +package com.fernandocejas.android10.sample.app.view.component; import android.content.Context; diff --git a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/BaseFragment.java b/app/src/main/java/com/fernandocejas/android10/sample/app/view/fragment/BaseFragment.java similarity index 84% rename from presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/BaseFragment.java rename to app/src/main/java/com/fernandocejas/android10/sample/app/view/fragment/BaseFragment.java index a312d134..a2c6ad57 100644 --- a/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/BaseFragment.java +++ b/app/src/main/java/com/fernandocejas/android10/sample/app/view/fragment/BaseFragment.java @@ -3,11 +3,11 @@ * * @author Fernando Cejas (the android10 coder) */ -package com.fernandocejas.android10.sample.presentation.view.fragment; +package com.fernandocejas.android10.sample.app.view.fragment; import android.app.Fragment; import android.widget.Toast; -import com.fernandocejas.android10.sample.presentation.internal.di.HasComponent; +import com.fernandocejas.android10.sample.app.core.di.HasComponent; /** * Base {@link android.app.Fragment} class for every fragment in this application. diff --git a/presentation/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from presentation/src/main/res/drawable-hdpi/ic_launcher.png rename to app/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/presentation/src/main/res/drawable-hdpi/logo.png b/app/src/main/res/drawable-hdpi/logo.png similarity index 100% rename from presentation/src/main/res/drawable-hdpi/logo.png rename to app/src/main/res/drawable-hdpi/logo.png diff --git a/presentation/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from presentation/src/main/res/drawable-mdpi/ic_launcher.png rename to app/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/presentation/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png similarity index 100% rename from presentation/src/main/res/drawable-xhdpi/ic_launcher.png rename to app/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/presentation/src/main/res/drawable-xxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxhdpi/ic_launcher.png similarity index 100% rename from presentation/src/main/res/drawable-xxhdpi/ic_launcher.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/presentation/src/main/res/drawable/selector_item_user.xml b/app/src/main/res/drawable/selector_item_user.xml similarity index 100% rename from presentation/src/main/res/drawable/selector_item_user.xml rename to app/src/main/res/drawable/selector_item_user.xml diff --git a/presentation/src/main/res/layout/activity_layout.xml b/app/src/main/res/layout/activity_layout.xml similarity index 100% rename from presentation/src/main/res/layout/activity_layout.xml rename to app/src/main/res/layout/activity_layout.xml diff --git a/presentation/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml similarity index 100% rename from presentation/src/main/res/layout/activity_main.xml rename to app/src/main/res/layout/activity_main.xml diff --git a/presentation/src/main/res/layout/fragment_user_details.xml b/app/src/main/res/layout/fragment_user_details.xml similarity index 100% rename from presentation/src/main/res/layout/fragment_user_details.xml rename to app/src/main/res/layout/fragment_user_details.xml diff --git a/presentation/src/main/res/layout/fragment_user_list.xml b/app/src/main/res/layout/fragment_user_list.xml similarity index 100% rename from presentation/src/main/res/layout/fragment_user_list.xml rename to app/src/main/res/layout/fragment_user_list.xml diff --git a/presentation/src/main/res/layout/row_user.xml b/app/src/main/res/layout/row_user.xml similarity index 100% rename from presentation/src/main/res/layout/row_user.xml rename to app/src/main/res/layout/row_user.xml diff --git a/presentation/src/main/res/layout/view_progress.xml b/app/src/main/res/layout/view_progress.xml similarity index 100% rename from presentation/src/main/res/layout/view_progress.xml rename to app/src/main/res/layout/view_progress.xml diff --git a/presentation/src/main/res/layout/view_retry.xml b/app/src/main/res/layout/view_retry.xml similarity index 100% rename from presentation/src/main/res/layout/view_retry.xml rename to app/src/main/res/layout/view_retry.xml diff --git a/presentation/src/main/res/layout/view_user_details.xml b/app/src/main/res/layout/view_user_details.xml similarity index 95% rename from presentation/src/main/res/layout/view_user_details.xml rename to app/src/main/res/layout/view_user_details.xml index 9416c346..856af605 100644 --- a/presentation/src/main/res/layout/view_user_details.xml +++ b/app/src/main/res/layout/view_user_details.xml @@ -5,7 +5,7 @@ android:orientation="vertical" > - { + MockitoAnnotations.initMocks(ApplicationTestCase.this); + return base; + }; + + public static Context context() { + return RuntimeEnvironment.application; + } +} diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializerTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/data/SerializerTest.java similarity index 73% rename from data/src/test/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializerTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/data/SerializerTest.java index da15891a..d16c52f5 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/cache/serializer/JsonSerializerTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/data/SerializerTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache.serializer; +package com.fernandocejas.android10.sample.app.data; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.entity.UserEntity; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; +import com.fernandocejas.android10.sample.app.users.UserEntity; import org.junit.Before; import org.junit.Test; @@ -24,7 +24,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -public class JsonSerializerTest extends ApplicationTestCase { +public class SerializerTest extends ApplicationTestCase { private static final String JSON_RESPONSE = "{\n" + " \"id\": 1,\n" @@ -35,18 +35,18 @@ public class JsonSerializerTest extends ApplicationTestCase { + " \"email\": \"jcooper@babbleset.edu\"\n" + "}"; - private JsonSerializer jsonSerializer; + private Serializer serializer; @Before public void setUp() { - jsonSerializer = new JsonSerializer(); + serializer = new Serializer(); } @Test public void testSerializeHappyCase() { - UserEntity userEntityOne = jsonSerializer.deserialize(JSON_RESPONSE); - String jsonString = jsonSerializer.serialize(userEntityOne); - UserEntity userEntityTwo = jsonSerializer.deserialize(jsonString); + final UserEntity userEntityOne = serializer.deserialize(JSON_RESPONSE, UserEntity.class); + final String jsonString = serializer.serialize(userEntityOne, UserEntity.class); + final UserEntity userEntityTwo = serializer.deserialize(jsonString, UserEntity.class); assertThat(userEntityOne.getUserId(), is(userEntityTwo.getUserId())); assertThat(userEntityOne.getFullname(), is(equalTo(userEntityTwo.getFullname()))); @@ -54,8 +54,8 @@ public void testSerializeHappyCase() { } @Test - public void testDesearializeHappyCase() { - UserEntity userEntity = jsonSerializer.deserialize(JSON_RESPONSE); + public void testDeserializeHappyCase() { + final UserEntity userEntity = serializer.deserialize(JSON_RESPONSE, UserEntity.class); assertThat(userEntity.getUserId(), is(1)); assertThat(userEntity.getFullname(), is("Simon Hill")); diff --git a/domain/src/test/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundleTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundleTest.java similarity index 86% rename from domain/src/test/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundleTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundleTest.java index 1ba00434..d7aa5e10 100644 --- a/domain/src/test/java/com/fernandocejas/android10/sample/domain/exception/DefaultErrorBundleTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/exception/DefaultErrorBundleTest.java @@ -13,15 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.exception; +package com.fernandocejas.android10.sample.app.exception; 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 static org.mockito.Mockito.verify; +@RunWith(MockitoJUnitRunner.class) public class DefaultErrorBundleTest { private DefaultErrorBundle defaultErrorBundle; @@ -30,7 +32,6 @@ public class DefaultErrorBundleTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); defaultErrorBundle = new DefaultErrorBundle(mockException); } @@ -40,4 +41,4 @@ public void testGetErrorMessageInteraction() { verify(mockException).getMessage(); } -} \ No newline at end of file +} diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundleTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundleTest.java similarity index 80% rename from data/src/test/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundleTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundleTest.java index 277f7ad7..5b99fbd4 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/exception/RepositoryErrorBundleTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/exception/RepositoryErrorBundleTest.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.exception; +package com.fernandocejas.android10.sample.app.exception; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; 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 static org.mockito.Mockito.verify; -public class RepositoryErrorBundleTest extends ApplicationTestCase { +@RunWith(MockitoJUnitRunner.class) +public class RepositoryErrorBundleTest { private RepositoryErrorBundle repositoryErrorBundle; @@ -32,11 +33,11 @@ public class RepositoryErrorBundleTest extends ApplicationTestCase { @Before public void setUp() { - MockitoAnnotations.initMocks(this); repositoryErrorBundle = new RepositoryErrorBundle(mockException); } @Test + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void testGetErrorMessageInteraction() { repositoryErrorBundle.getErrorMessage(); diff --git a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/UseCaseTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/interactor/UseCaseTest.java similarity index 86% rename from domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/UseCaseTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/interactor/UseCaseTest.java index e8d20444..bcfa00aa 100644 --- a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/UseCaseTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/interactor/UseCaseTest.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.interactor; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; 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 rx.Observable; import rx.Subscriber; import rx.observers.TestSubscriber; @@ -30,6 +31,7 @@ import static org.hamcrest.core.Is.is; import static org.mockito.BDDMockito.given; +@RunWith(MockitoJUnitRunner.class) public class UseCaseTest { private UseCaseTestClass useCase; @@ -39,7 +41,6 @@ public class UseCaseTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); this.useCase = new UseCaseTestClass(mockThreadExecutor, mockPostExecutionThread); } @@ -67,7 +68,7 @@ public void testSubscriptionWhenExecutingUseCase() { private static class UseCaseTestClass extends UseCase { - protected UseCaseTestClass( + UseCaseTestClass( ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) { super(threadExecutor, postExecutionThread); @@ -81,4 +82,4 @@ protected UseCaseTestClass( super.execute(UseCaseSubscriber); } } -} \ No newline at end of file +} diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStoreTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStoreTest.java similarity index 77% rename from data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStoreTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStoreTest.java index b54e58e1..ff8c3862 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/CloudUserDataStoreTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/CloudUserDataStoreTest.java @@ -13,22 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.cache.UserCache; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.data.net.RestApi; +import com.fernandocejas.android10.sample.app.data.RestApi; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; 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 rx.Observable; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; -public class CloudUserDataStoreTest extends ApplicationTestCase { +@RunWith(MockitoJUnitRunner.class) +public class CloudUserDataStoreTest { private static final int FAKE_USER_ID = 765; @@ -39,7 +39,6 @@ public class CloudUserDataStoreTest extends ApplicationTestCase { @Before public void setUp() { - MockitoAnnotations.initMocks(this); cloudUserDataStore = new CloudUserDataStore(mockRestApi, mockUserCache); } diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStoreTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStoreTest.java similarity index 80% rename from data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStoreTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStoreTest.java index 6c7bca5d..372b9718 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStoreTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/DiskUserDataStoreTest.java @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.cache.UserCache; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; import static org.mockito.Mockito.verify; -public class DiskUserDataStoreTest extends ApplicationTestCase { +@RunWith(MockitoJUnitRunner.class) +public class DiskUserDataStoreTest { private static final int FAKE_USER_ID = 11; @@ -38,7 +39,6 @@ public class DiskUserDataStoreTest extends ApplicationTestCase { @Before public void setUp() { - MockitoAnnotations.initMocks(this); diskUserDataStore = new DiskUserDataStore(mockUserCache); } diff --git a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetailsTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserDetailsTest.java similarity index 81% rename from domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetailsTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserDetailsTest.java index 8e730cb2..0cbe97f6 100644 --- a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserDetailsTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserDetailsTest.java @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; 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 static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; +@RunWith(MockitoJUnitRunner.class) public class GetUserDetailsTest { private static final int FAKE_USER_ID = 123; @@ -39,7 +40,6 @@ public class GetUserDetailsTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); getUserDetails = new GetUserDetails(FAKE_USER_ID, mockUserRepository, mockThreadExecutor, mockPostExecutionThread); } diff --git a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserListTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserListTest.java similarity index 80% rename from domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserListTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserListTest.java index 0e1565ff..8bdd1cb4 100644 --- a/domain/src/test/java/com/fernandocejas/android10/sample/domain/interactor/GetUserListTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/GetUserListTest.java @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain.interactor; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread; -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import com.fernandocejas.android10.sample.domain.repository.UserRepository; +import com.fernandocejas.android10.sample.app.core.executor.PostExecutionThread; +import com.fernandocejas.android10.sample.app.core.executor.ThreadExecutor; 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 static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; +@RunWith(MockitoJUnitRunner.class) public class GetUserListTest { private GetUserList getUserList; @@ -37,7 +38,6 @@ public class GetUserListTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); getUserList = new GetUserList(mockUserRepository, mockThreadExecutor, mockPostExecutionThread); } diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/UserDataRepositoryTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataRepositoryTest.java similarity index 79% rename from data/src/test/java/com/fernandocejas/android10/sample/data/repository/UserDataRepositoryTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataRepositoryTest.java index 70752055..91ebf66e 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/UserDataRepositoryTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataRepositoryTest.java @@ -13,29 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.data.entity.mapper.UserEntityDataMapper; -import com.fernandocejas.android10.sample.data.repository.datasource.UserDataStore; -import com.fernandocejas.android10.sample.data.repository.datasource.UserDataStoreFactory; -import com.fernandocejas.android10.sample.domain.User; import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; import rx.Observable; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.verify; -public class UserDataRepositoryTest extends ApplicationTestCase { +@RunWith(MockitoJUnitRunner.class) +public class UserDataRepositoryTest { private static final int FAKE_USER_ID = 123; @@ -52,7 +48,6 @@ public class UserDataRepositoryTest extends ApplicationTestCase { @Before public void setUp() { - MockitoAnnotations.initMocks(this); userDataRepository = new UserDataRepository(mockUserDataStoreFactory, mockUserEntityDataMapper); diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactoryTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactoryTest.java similarity index 81% rename from data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactoryTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactoryTest.java index b8c644a4..09412ea4 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/repository/datasource/UserDataStoreFactoryTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDataStoreFactoryTest.java @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.repository.datasource; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.cache.UserCache; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; +import com.fernandocejas.android10.sample.app.users.cache.UserCache; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RuntimeEnvironment; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -36,14 +34,11 @@ public class UserDataStoreFactoryTest extends ApplicationTestCase { private UserDataStoreFactory userDataStoreFactory; - @Mock - private UserCache mockUserCache; + @Mock private UserCache mockUserCache; @Before public void setUp() { - MockitoAnnotations.initMocks(this); - userDataStoreFactory = - new UserDataStoreFactory(RuntimeEnvironment.application, mockUserCache); + userDataStoreFactory = new UserDataStoreFactory(context(), mockUserCache); } @Test diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserDetailsPresenterTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenterTest.java similarity index 58% rename from presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserDetailsPresenterTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenterTest.java index c4009696..b5406375 100644 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserDetailsPresenterTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserDetailsPresenterTest.java @@ -13,45 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.test.presenter; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; -import android.test.AndroidTestCase; -import com.fernandocejas.android10.sample.domain.interactor.GetUserDetails; -import com.fernandocejas.android10.sample.presentation.mapper.UserModelDataMapper; -import com.fernandocejas.android10.sample.presentation.presenter.UserDetailsPresenter; -import com.fernandocejas.android10.sample.presentation.view.UserDetailsView; +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 rx.Subscriber; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; -public class UserDetailsPresenterTest extends AndroidTestCase { - - private static final int FAKE_USER_ID = 123; +@RunWith(MockitoJUnitRunner.class) +public class UserDetailsPresenterTest { private UserDetailsPresenter userDetailsPresenter; - @Mock - private Context mockContext; - @Mock - private UserDetailsView mockUserDetailsView; - @Mock - private GetUserDetails mockGetUserDetails; - @Mock - private UserModelDataMapper mockUserModelDataMapper; + @Mock private Context mockContext; + @Mock private UserDetailsView mockUserDetailsView; + @Mock private GetUserDetails mockGetUserDetails; + @Mock private UserModelDataMapper mockUserModelDataMapper; - @Override protected void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - userDetailsPresenter = new UserDetailsPresenter(mockGetUserDetails, - mockUserModelDataMapper); + @Before + public void setUp() throws Exception { + userDetailsPresenter = new UserDetailsPresenter(mockGetUserDetails, mockUserModelDataMapper); userDetailsPresenter.setView(mockUserDetailsView); } + @Test public void testUserDetailsPresenterInitialize() { given(mockUserDetailsView.context()).willReturn(mockContext); diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapperTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapperTest.java similarity index 90% rename from data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapperTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapperTest.java index 19a4db56..ea69f6e8 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityDataMapperTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityDataMapperTest.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.entity.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.entity.UserEntity; -import com.fernandocejas.android10.sample.domain.User; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; import java.util.ArrayList; import java.util.Collection; import java.util.List; diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapperTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapperTest.java similarity index 93% rename from data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapperTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapperTest.java index f834f52d..afce2a1e 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/entity/mapper/UserEntityJsonMapperTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserEntityJsonMapperTest.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.entity.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; -import com.fernandocejas.android10.sample.data.entity.UserEntity; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; +import com.fernandocejas.android10.sample.app.users.UserEntity; +import com.fernandocejas.android10.sample.app.users.UserEntityJsonMapper; import com.google.gson.JsonSyntaxException; import java.util.Collection; import org.junit.Before; diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserListPresenterTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserListPresenterTest.java similarity index 59% rename from presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserListPresenterTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserListPresenterTest.java index f8a98c8e..66b3b4da 100644 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/presenter/UserListPresenterTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserListPresenterTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,42 +13,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.test.presenter; +package com.fernandocejas.android10.sample.app.users; import android.content.Context; -import android.test.AndroidTestCase; -import com.fernandocejas.android10.sample.domain.interactor.GetUserList; -import com.fernandocejas.android10.sample.presentation.mapper.UserModelDataMapper; -import com.fernandocejas.android10.sample.presentation.presenter.UserListPresenter; -import com.fernandocejas.android10.sample.presentation.view.UserListView; +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 rx.Subscriber; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; -public class UserListPresenterTest extends AndroidTestCase { +@RunWith(MockitoJUnitRunner.class) +public class UserListPresenterTest { private UserListPresenter userListPresenter; - @Mock - private Context mockContext; - @Mock - private UserListView mockUserListView; - @Mock - private GetUserList mockGetUserList; - @Mock - private UserModelDataMapper mockUserModelDataMapper; - - @Override protected void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); + @Mock private Context mockContext; + @Mock private UserListView mockUserListView; + @Mock private GetUserList mockGetUserList; + @Mock private UserModelDataMapper mockUserModelDataMapper; + + @Before public void setUp() throws Exception { userListPresenter = new UserListPresenter(mockGetUserList, mockUserModelDataMapper); userListPresenter.setView(mockUserListView); } + @Test public void testUserListPresenterInitialize() { given(mockUserListView.context()).willReturn(mockContext); diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/mapper/UserModelDataMapperTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapperTest.java similarity index 81% rename from presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/mapper/UserModelDataMapperTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapperTest.java index 50a1e33b..ed266b63 100644 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/mapper/UserModelDataMapperTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserModelDataMapperTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,33 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.test.mapper; +package com.fernandocejas.android10.sample.app.users; -import com.fernandocejas.android10.sample.domain.User; -import com.fernandocejas.android10.sample.presentation.mapper.UserModelDataMapper; -import com.fernandocejas.android10.sample.presentation.model.UserModel; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; -public class UserModelDataMapperTest extends TestCase { +public class UserModelDataMapperTest extends ApplicationTestCase { private static final int FAKE_USER_ID = 123; private static final String FAKE_FULLNAME = "Tony Stark"; private UserModelDataMapper userModelDataMapper; - @Override protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { userModelDataMapper = new UserModelDataMapper(); } + @Test public void testTransformUser() { User user = createFakeUser(); UserModel userModel = userModelDataMapper.transform(user); @@ -49,6 +49,7 @@ public void testTransformUser() { assertThat(userModel.getFullName(), is(FAKE_FULLNAME)); } + @Test public void testTransformUserCollection() { User mockUserOne = mock(User.class); User mockUserTwo = mock(User.class); diff --git a/domain/src/test/java/com/fernandocejas/android10/sample/domain/UserTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserTest.java similarity index 95% rename from domain/src/test/java/com/fernandocejas/android10/sample/domain/UserTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/UserTest.java index ea45784a..9f3bb6e3 100644 --- a/domain/src/test/java/com/fernandocejas/android10/sample/domain/UserTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/UserTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.domain; +package com.fernandocejas.android10.sample.app.users; import org.junit.Before; import org.junit.Test; diff --git a/data/src/test/java/com/fernandocejas/android10/sample/data/cache/FileManagerTest.java b/app/src/test/java/com/fernandocejas/android10/sample/app/users/cache/FileManagerTest.java similarity index 91% rename from data/src/test/java/com/fernandocejas/android10/sample/data/cache/FileManagerTest.java rename to app/src/test/java/com/fernandocejas/android10/sample/app/users/cache/FileManagerTest.java index f71f8a8f..79ca2f0b 100644 --- a/data/src/test/java/com/fernandocejas/android10/sample/data/cache/FileManagerTest.java +++ b/app/src/test/java/com/fernandocejas/android10/sample/app/users/cache/FileManagerTest.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.fernandocejas.android10.sample.data.cache; +package com.fernandocejas.android10.sample.app.users.cache; -import com.fernandocejas.android10.sample.data.ApplicationTestCase; +import com.fernandocejas.android10.sample.app.ApplicationTestCase; +import com.fernandocejas.android10.sample.app.data.FileManager; import java.io.File; import org.junit.After; import org.junit.Before; diff --git a/build.gradle b/build.gradle index 5fd4dd6e..cbb3a496 100644 --- a/build.gradle +++ b/build.gradle @@ -15,32 +15,19 @@ buildscript { allprojects { ext { - androidApplicationId = 'com.fernanependocejas.android10.sample.presentation' + androidApplicationId = 'com.fernanependocejas.android10.sample.app' androidVersionCode = 1 androidVersionName = "1.0" testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" - testApplicationId = 'com.fernandocejas.android10.sample.presentation.test' + testApplicationId = 'com.fernandocejas.android10.sample.app.test' } } -task wrapper(type: Wrapper) { - description 'Creates the gradle wrapper.' - gradleVersion '2.12' +task runUnitTests(dependsOn: [':app:cleanTestDebugUnitTest', ':app:testDebugUnitTest']) { + description 'Run application unit tests.' } -task runDomainUnitTests(dependsOn: [':domain:test']) { - description 'Run unit tests for the domain layer.' -} - -task runDataUnitTests(dependsOn: [':data:cleanTestDebugUnitTest', ':data:testDebugUnitTest']) { - description 'Run unit tests for the data layer.' -} - -task runUnitTests(dependsOn: ['runDomainUnitTests', 'runDataUnitTests']) { - description 'Run unit tests for both domain and data layers.' -} - -task runAcceptanceTests(dependsOn: [':presentation:connectedAndroidTest']) { +task runAcceptanceTests(dependsOn: [':app:connectedAndroidTest']) { description 'Run application acceptance tests.' } diff --git a/data/build.gradle b/data/build.gradle deleted file mode 100644 index 1ee552e2..00000000 --- a/data/build.gradle +++ /dev/null @@ -1,68 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'me.tatarka:gradle-retrolambda:3.2.3' - } -} - -apply plugin: 'com.android.library' -apply plugin: 'com.neenbedankt.android-apt' -apply plugin: 'com.fernandocejas.frodo' -apply plugin: 'me.tatarka.retrolambda' - -android { - defaultPublishConfig "debug" - - def globalConfiguration = rootProject.extensions.getByName("ext") - - compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion") - buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion") - - defaultConfig { - minSdkVersion globalConfiguration.getAt("androidMinSdkVersion") - targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion") - versionCode globalConfiguration.getAt("androidVersionCode") - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - packagingOptions { - exclude 'LICENSE.txt' - exclude 'META-INF/DEPENDENCIES' - exclude 'META-INF/ASL2.0' - exclude 'META-INF/NOTICE' - exclude 'META-INF/LICENSE' - } - - lintOptions { - quiet true - abortOnError false - ignoreWarnings true - disable 'InvalidPackage' // Some libraries have issues with this - disable 'OldTargetApi' // Due to Robolectric that modifies the manifest when running tests - } -} - -dependencies { - def dataDependencies = rootProject.ext.dataDependencies - def testDependencies = rootProject.ext.dataTestDependencies - - compile project(':domain') - provided dataDependencies.javaxAnnotation - compile dataDependencies.javaxInject - compile dataDependencies.okHttp - compile dataDependencies.gson - compile dataDependencies.rxJava - compile dataDependencies.rxAndroid - compile dataDependencies.androidAnnotations - - testCompile testDependencies.junit - testCompile testDependencies.assertj - testCompile testDependencies.mockito - testCompile testDependencies.robolectric -} diff --git a/data/src/main/AndroidManifest.xml b/data/src/main/AndroidManifest.xml deleted file mode 100644 index bc8ea89b..00000000 --- a/data/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - diff --git a/data/src/main/java/com/fernandocejas/android10/sample/data/executor/JobExecutor.java b/data/src/main/java/com/fernandocejas/android10/sample/data/executor/JobExecutor.java deleted file mode 100644 index c82177d0..00000000 --- a/data/src/main/java/com/fernandocejas/android10/sample/data/executor/JobExecutor.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (C) 2015 Fernando Cejas Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fernandocejas.android10.sample.data.executor; - -import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; -import javax.inject.Singleton; - -/** - * Decorated {@link java.util.concurrent.ThreadPoolExecutor} - */ -@Singleton -public class JobExecutor implements ThreadExecutor { - - private static final int INITIAL_POOL_SIZE = 3; - private static final int MAX_POOL_SIZE = 5; - - // Sets the amount of time an idle thread waits before terminating - private static final int KEEP_ALIVE_TIME = 10; - - // Sets the Time Unit to seconds - private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS; - - private final BlockingQueue workQueue; - - private final ThreadPoolExecutor threadPoolExecutor; - - private final ThreadFactory threadFactory; - - @Inject - public JobExecutor() { - this.workQueue = new LinkedBlockingQueue<>(); - this.threadFactory = new JobThreadFactory(); - this.threadPoolExecutor = new ThreadPoolExecutor(INITIAL_POOL_SIZE, MAX_POOL_SIZE, - KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, this.workQueue, this.threadFactory); - } - - @Override public void execute(Runnable runnable) { - if (runnable == null) { - throw new IllegalArgumentException("Runnable to execute cannot be null"); - } - this.threadPoolExecutor.execute(runnable); - } - - private static class JobThreadFactory implements ThreadFactory { - private static final String THREAD_NAME = "android_"; - private int counter = 0; - - @Override public Thread newThread(Runnable runnable) { - return new Thread(runnable, THREAD_NAME + counter++); - } - } -} diff --git a/domain/build.gradle b/domain/build.gradle deleted file mode 100644 index 84ecd764..00000000 --- a/domain/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'java' - -//noinspection GroovyUnusedAssignment -sourceCompatibility = 1.7 -//noinspection GroovyUnusedAssignment -targetCompatibility = 1.7 - -configurations { - provided -} - -sourceSets { - main { - compileClasspath += configurations.provided - } -} - -dependencies { - def domainDependencies = rootProject.ext.domainDependencies - def domainTestDependencies = rootProject.ext.domainTestDependencies - - provided domainDependencies.javaxAnnotation - - compile domainDependencies.javaxInject - compile domainDependencies.rxJava - - testCompile domainTestDependencies.junit - testCompile domainTestDependencies.mockito -} \ No newline at end of file diff --git a/presentation/.gitignore b/presentation/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/presentation/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/presentation/proguard-rules.pro b/presentation/proguard-rules.pro deleted file mode 100644 index 205387b5..00000000 --- a/presentation/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/fcejas/Software/SDKs/android-sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/exception/ErrorMessageFactoryTest.java b/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/exception/ErrorMessageFactoryTest.java deleted file mode 100644 index 75781101..00000000 --- a/presentation/src/androidTest/java/com/fernandocejas/android10/sample/test/exception/ErrorMessageFactoryTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2015 Fernando Cejas Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.fernandocejas.android10.sample.test.exception; - -import android.test.AndroidTestCase; -import com.fernandocejas.android10.sample.data.exception.NetworkConnectionException; -import com.fernandocejas.android10.sample.data.exception.UserNotFoundException; -import com.fernandocejas.android10.sample.presentation.R; -import com.fernandocejas.android10.sample.presentation.exception.ErrorMessageFactory; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class ErrorMessageFactoryTest extends AndroidTestCase { - - @Override protected void setUp() throws Exception { - super.setUp(); - } - - public void testNetworkConnectionErrorMessage() { - String expectedMessage = getContext().getString(R.string.exception_message_no_connection); - String actualMessage = ErrorMessageFactory.create(getContext(), - new NetworkConnectionException()); - - assertThat(actualMessage, is(equalTo(expectedMessage))); - } - - public void testUserNotFoundErrorMessage() { - String expectedMessage = getContext().getString(R.string.exception_message_user_not_found); - String actualMessage = ErrorMessageFactory.create(getContext(), new UserNotFoundException()); - - assertThat(actualMessage, is(equalTo(expectedMessage))); - } -} diff --git a/settings.gradle b/settings.gradle index c5e0ddae..e7b4def4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1 @@ -include ':presentation' -include ':domain' -include ':data' +include ':app'