From 7a467d43df5f3e7f58ae0cf322f539853195f5be Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 21 Feb 2016 23:13:22 +0100 Subject: [PATCH] Fix tests after Kotlin merge (probably) --- .../injection/module/DataModule.java | 6 ++-- .../kanade/tachiyomi/CustomBuildConfig.java | 15 ---------- .../CustomRobolectricGradleTestRunner.java | 21 ++++++++++++++ .../java/eu/kanade/tachiyomi/TestApp.java | 1 + .../data/library/LibraryUpdateAlarmTest.java | 8 +++--- .../library/LibraryUpdateServiceTest.java | 8 +++--- .../injection/module/TestDataModule.java | 28 +++++++++++++++++++ 7 files changed, 61 insertions(+), 26 deletions(-) delete mode 100644 app/src/test/java/eu/kanade/tachiyomi/CustomBuildConfig.java create mode 100644 app/src/test/java/eu/kanade/tachiyomi/CustomRobolectricGradleTestRunner.java create mode 100644 app/src/test/java/eu/kanade/tachiyomi/injection/module/TestDataModule.java diff --git a/app/src/main/java/eu/kanade/tachiyomi/injection/module/DataModule.java b/app/src/main/java/eu/kanade/tachiyomi/injection/module/DataModule.java index d516fe584..3aa9cf97a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/injection/module/DataModule.java +++ b/app/src/main/java/eu/kanade/tachiyomi/injection/module/DataModule.java @@ -29,7 +29,7 @@ public class DataModule { @Provides @Singleton - public DatabaseHelper provideDatabaseHelper(Application app) { + DatabaseHelper provideDatabaseHelper(Application app) { return new DatabaseHelper(app); } @@ -47,13 +47,13 @@ public class DataModule { @Provides @Singleton - public NetworkHelper provideNetworkHelper(Application app) { + NetworkHelper provideNetworkHelper(Application app) { return new NetworkHelper(app); } @Provides @Singleton - public SourceManager provideSourceManager(Application app) { + SourceManager provideSourceManager(Application app) { return new SourceManager(app); } diff --git a/app/src/test/java/eu/kanade/tachiyomi/CustomBuildConfig.java b/app/src/test/java/eu/kanade/tachiyomi/CustomBuildConfig.java deleted file mode 100644 index de3ec0ad7..000000000 --- a/app/src/test/java/eu/kanade/tachiyomi/CustomBuildConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package eu.kanade.tachiyomi; - -public class CustomBuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "eu.kanade.tachiyomi"; - public static final String BUILD_TYPE = "debug"; - public static final String FLAVOR = ""; - public static final int VERSION_CODE = 4; - public static final String VERSION_NAME = "0.1.3"; - // Fields from default config. - public static final String BUILD_TIME = "2016-02-19T14:49Z"; - public static final String COMMIT_COUNT = "482"; - public static final String COMMIT_SHA = "e52c498"; - public static final boolean INCLUDE_UPDATER = true; -} diff --git a/app/src/test/java/eu/kanade/tachiyomi/CustomRobolectricGradleTestRunner.java b/app/src/test/java/eu/kanade/tachiyomi/CustomRobolectricGradleTestRunner.java new file mode 100644 index 000000000..9aa11e682 --- /dev/null +++ b/app/src/test/java/eu/kanade/tachiyomi/CustomRobolectricGradleTestRunner.java @@ -0,0 +1,21 @@ +package eu.kanade.tachiyomi; + +import org.junit.runners.model.InitializationError; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; +import org.robolectric.manifest.AndroidManifest; + +public class CustomRobolectricGradleTestRunner + extends RobolectricGradleTestRunner { + + public CustomRobolectricGradleTestRunner(Class klass) throws InitializationError { + super(klass); + } + + @Override + protected AndroidManifest getAppManifest(Config config) { + AndroidManifest androidManifest = super.getAppManifest(config); + androidManifest.setPackageName("eu.kanade.tachiyomi"); + return androidManifest; + } +} \ No newline at end of file diff --git a/app/src/test/java/eu/kanade/tachiyomi/TestApp.java b/app/src/test/java/eu/kanade/tachiyomi/TestApp.java index 451db6e41..f94649309 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/TestApp.java +++ b/app/src/test/java/eu/kanade/tachiyomi/TestApp.java @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi; import eu.kanade.tachiyomi.injection.component.DaggerAppComponent; import eu.kanade.tachiyomi.injection.module.AppModule; +import eu.kanade.tachiyomi.injection.module.TestDataModule; public class TestApp extends App { diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateAlarmTest.java b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateAlarmTest.java index 02ffadb63..f4557f0bd 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateAlarmTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateAlarmTest.java @@ -10,21 +10,21 @@ import org.assertj.core.data.Offset; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowAlarmManager; import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowPendingIntent; -import eu.kanade.tachiyomi.CustomBuildConfig; +import eu.kanade.tachiyomi.BuildConfig; +import eu.kanade.tachiyomi.CustomRobolectricGradleTestRunner; import eu.kanade.tachiyomi.data.preference.PreferencesHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.spy; import static org.robolectric.Shadows.shadowOf; -@Config(constants = CustomBuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) -@RunWith(RobolectricGradleTestRunner.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) +@RunWith(CustomRobolectricGradleTestRunner.class) public class LibraryUpdateAlarmTest { ShadowApplication app; diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.java b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.java index 720652237..81d99654b 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/data/library/LibraryUpdateServiceTest.java @@ -9,14 +9,14 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import java.util.ArrayList; import java.util.List; -import eu.kanade.tachiyomi.CustomBuildConfig; +import eu.kanade.tachiyomi.BuildConfig; +import eu.kanade.tachiyomi.CustomRobolectricGradleTestRunner; import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.source.base.Source; @@ -31,8 +31,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@Config(constants = CustomBuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) -@RunWith(RobolectricGradleTestRunner.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) +@RunWith(CustomRobolectricGradleTestRunner.class) public class LibraryUpdateServiceTest { ShadowApplication app; diff --git a/app/src/test/java/eu/kanade/tachiyomi/injection/module/TestDataModule.java b/app/src/test/java/eu/kanade/tachiyomi/injection/module/TestDataModule.java new file mode 100644 index 000000000..0188d4e52 --- /dev/null +++ b/app/src/test/java/eu/kanade/tachiyomi/injection/module/TestDataModule.java @@ -0,0 +1,28 @@ +package eu.kanade.tachiyomi.injection.module; + +import android.app.Application; + +import org.mockito.Mockito; + +import eu.kanade.tachiyomi.data.database.DatabaseHelper; +import eu.kanade.tachiyomi.data.network.NetworkHelper; +import eu.kanade.tachiyomi.data.source.SourceManager; + +public class TestDataModule extends DataModule { + + @Override + DatabaseHelper provideDatabaseHelper(Application app) { + return Mockito.mock(DatabaseHelper.class, Mockito.RETURNS_DEEP_STUBS); + } + + @Override + NetworkHelper provideNetworkHelper(Application app) { + return Mockito.mock(NetworkHelper.class); + } + + @Override + SourceManager provideSourceManager(Application app) { + return Mockito.mock(SourceManager.class, Mockito.RETURNS_DEEP_STUBS); + } + +}