Browse Source

Fix tests after Kotlin merge (probably)

inorichi 9 years ago
parent
commit
7a467d43df

+ 3 - 3
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);
     }
 

+ 0 - 15
app/src/test/java/eu/kanade/tachiyomi/CustomBuildConfig.java

@@ -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;
-}

+ 21 - 0
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;
+    }
+}

+ 1 - 0
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 {
 

+ 4 - 4
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;

+ 4 - 4
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;

+ 28 - 0
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);
+    }
+
+}