Fix tests after Kotlin merge (probably)

This commit is contained in:
inorichi 2016-02-21 23:13:22 +01:00
parent db97250db8
commit 7a467d43df
7 changed files with 61 additions and 26 deletions

View file

@ -29,7 +29,7 @@ public class DataModule {
@Provides @Provides
@Singleton @Singleton
public DatabaseHelper provideDatabaseHelper(Application app) { DatabaseHelper provideDatabaseHelper(Application app) {
return new DatabaseHelper(app); return new DatabaseHelper(app);
} }
@ -47,13 +47,13 @@ public class DataModule {
@Provides @Provides
@Singleton @Singleton
public NetworkHelper provideNetworkHelper(Application app) { NetworkHelper provideNetworkHelper(Application app) {
return new NetworkHelper(app); return new NetworkHelper(app);
} }
@Provides @Provides
@Singleton @Singleton
public SourceManager provideSourceManager(Application app) { SourceManager provideSourceManager(Application app) {
return new SourceManager(app); return new SourceManager(app);
} }

View file

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

View file

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

View file

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi;
import eu.kanade.tachiyomi.injection.component.DaggerAppComponent; import eu.kanade.tachiyomi.injection.component.DaggerAppComponent;
import eu.kanade.tachiyomi.injection.module.AppModule; import eu.kanade.tachiyomi.injection.module.AppModule;
import eu.kanade.tachiyomi.injection.module.TestDataModule;
public class TestApp extends App { public class TestApp extends App {

View file

@ -10,21 +10,21 @@ import org.assertj.core.data.Offset;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowAlarmManager; import org.robolectric.shadows.ShadowAlarmManager;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowPendingIntent; 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 eu.kanade.tachiyomi.data.preference.PreferencesHelper;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.robolectric.Shadows.shadowOf; import static org.robolectric.Shadows.shadowOf;
@Config(constants = CustomBuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(CustomRobolectricGradleTestRunner.class)
public class LibraryUpdateAlarmTest { public class LibraryUpdateAlarmTest {
ShadowApplication app; ShadowApplication app;

View file

@ -9,14 +9,14 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.database.models.Manga;
import eu.kanade.tachiyomi.data.source.base.Source; 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.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@Config(constants = CustomBuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(CustomRobolectricGradleTestRunner.class)
public class LibraryUpdateServiceTest { public class LibraryUpdateServiceTest {
ShadowApplication app; ShadowApplication app;

View file

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