Fix tests
This commit is contained in:
parent
5132f4850f
commit
0d41c60a38
8 changed files with 40 additions and 46 deletions
|
@ -113,7 +113,7 @@ dependencies {
|
|||
compile 'com.jakewharton:disklrucache:2.0.2'
|
||||
compile 'org.jsoup:jsoup:1.8.3'
|
||||
compile 'io.reactivex:rxandroid:1.1.0'
|
||||
compile 'io.reactivex:rxjava:1.1.1'
|
||||
compile 'io.reactivex:rxjava:1.1.2'
|
||||
compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
|
||||
compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
|
||||
compile "com.squareup.retrofit2:adapter-rxjava:$RETROFIT_VERSION"
|
||||
|
@ -123,7 +123,7 @@ dependencies {
|
|||
compile 'info.android15.nucleus:nucleus:2.0.5'
|
||||
compile 'com.github.bumptech.glide:glide:3.7.0'
|
||||
compile 'com.jakewharton.timber:timber:4.1.1'
|
||||
compile 'ch.acra:acra:4.8.3'
|
||||
compile 'ch.acra:acra:4.8.5'
|
||||
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
||||
compile 'eu.davidea:flexible-adapter:4.2.0'
|
||||
compile 'com.nononsenseapps:filepicker:2.5.2'
|
||||
|
@ -142,7 +142,7 @@ dependencies {
|
|||
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.assertj:assertj-core:2.3.0'
|
||||
testCompile 'org.assertj:assertj-core:1.7.1'
|
||||
testCompile "org.mockito:mockito-core:$MOCKITO_VERSION"
|
||||
testCompile('org.robolectric:robolectric:3.0') {
|
||||
exclude group: 'commons-logging', module: 'commons-logging'
|
||||
|
|
|
@ -19,7 +19,7 @@ import eu.kanade.tachiyomi.util.ChapterRecognition
|
|||
import rx.Observable
|
||||
import java.util.*
|
||||
|
||||
class DatabaseHelper(context: Context) {
|
||||
open class DatabaseHelper(context: Context) {
|
||||
|
||||
val db = DefaultStorIOSQLite.builder()
|
||||
.sqliteOpenHelper(DbOpenHelper(context))
|
||||
|
@ -58,7 +58,7 @@ class DatabaseHelper(context: Context) {
|
|||
.withGetResolver(LibraryMangaGetResolver.INSTANCE)
|
||||
.prepare()
|
||||
|
||||
fun getFavoriteMangas() = db.get()
|
||||
open fun getFavoriteMangas() = db.get()
|
||||
.listOfObjects(Manga::class.java)
|
||||
.withQuery(Query.builder()
|
||||
.table(MangaTable.TABLE)
|
||||
|
@ -178,7 +178,7 @@ class DatabaseHelper(context: Context) {
|
|||
fun insertChapters(chapters: List<Chapter>) = db.put().objects(chapters).prepare()
|
||||
|
||||
// Add new chapters or delete if the source deletes them
|
||||
fun insertOrRemoveChapters(manga: Manga, sourceChapters: List<Chapter>, source: Source): Observable<Pair<Int, Int>> {
|
||||
open fun insertOrRemoveChapters(manga: Manga, sourceChapters: List<Chapter>, source: Source): Observable<Pair<Int, Int>> {
|
||||
val dbChapters = getChapters(manga).executeAsBlocking()
|
||||
|
||||
val newChapters = Observable.from(sourceChapters)
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Build;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricGradleTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
|
@ -17,10 +16,10 @@ import eu.kanade.tachiyomi.data.database.models.Category;
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@RunWith(CustomRobolectricGradleTestRunner.class)
|
||||
public class CategoryTest {
|
||||
|
||||
DatabaseHelper db;
|
||||
|
|
|
@ -4,7 +4,7 @@ import eu.kanade.tachiyomi.injection.component.DaggerAppComponent
|
|||
import eu.kanade.tachiyomi.injection.module.AppModule
|
||||
import eu.kanade.tachiyomi.injection.module.TestDataModule
|
||||
|
||||
class TestApp : App() {
|
||||
open class TestApp : App() {
|
||||
|
||||
override fun prepareAppComponent(): DaggerAppComponent.Builder {
|
||||
return DaggerAppComponent.builder()
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -132,9 +131,9 @@ public class LibraryUpdateAlarmTest {
|
|||
long shouldRunAt = SystemClock.elapsedRealtime() + (hours * 60 * 60 * 1000);
|
||||
|
||||
// Margin error of 3 seconds
|
||||
Offset<Long> offset = Offset.offset(3 * 1000L);
|
||||
|
||||
assertThat(alarmManager.getNextScheduledAlarm().triggerAtTime).isCloseTo(shouldRunAt, offset);
|
||||
assertThat(alarmManager.getNextScheduledAlarm().triggerAtTime)
|
||||
.isGreaterThan(shouldRunAt - 3000)
|
||||
.isLessThan(shouldRunAt + 3000);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import rx.Observable;
|
|||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyListOf;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
@ -88,7 +89,7 @@ public class LibraryUpdateServiceTest {
|
|||
|
||||
// One of the updates will fail
|
||||
when(source.pullChaptersFromNetwork("manga1")).thenReturn(Observable.just(chapters));
|
||||
when(source.pullChaptersFromNetwork("manga2")).thenReturn(Observable.error(new Exception()));
|
||||
when(source.pullChaptersFromNetwork("manga2")).thenReturn(Observable.<List<Chapter>>error(new Exception()));
|
||||
when(source.pullChaptersFromNetwork("manga3")).thenReturn(Observable.just(chapters3));
|
||||
|
||||
when(service.db.insertOrRemoveChapters(manga1, chapters, source)).thenReturn(Observable.just(Pair.create(2, 0)));
|
||||
|
@ -97,9 +98,9 @@ public class LibraryUpdateServiceTest {
|
|||
service.updateLibrary().subscribe();
|
||||
|
||||
// There are 3 network attempts and 2 insertions (1 request failed)
|
||||
verify(source, times(3)).pullChaptersFromNetwork(any());
|
||||
verify(service.db, times(2)).insertOrRemoveChapters(any(), any(), any());
|
||||
verify(service.db, never()).insertOrRemoveChapters(eq(manga2), any(), any());
|
||||
verify(source, times(3)).pullChaptersFromNetwork((String)any());
|
||||
verify(service.db, times(2)).insertOrRemoveChapters((Manga)any(), anyListOf(Chapter.class), (Source)any());
|
||||
verify(service.db, never()).insertOrRemoveChapters(eq(manga2), anyListOf(Chapter.class), (Source)any());
|
||||
}
|
||||
|
||||
private List<Chapter> createChapters(String... urls) {
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package eu.kanade.tachiyomi.injection.module
|
||||
|
||||
import android.app.Application
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import org.mockito.Mockito
|
||||
|
||||
class TestDataModule : DataModule() {
|
||||
|
||||
override fun provideDatabaseHelper(app: Application): DatabaseHelper {
|
||||
return Mockito.mock(DatabaseHelper::class.java, Mockito.RETURNS_DEEP_STUBS)
|
||||
}
|
||||
|
||||
override fun provideNetworkHelper(app: Application): NetworkHelper {
|
||||
return Mockito.mock(NetworkHelper::class.java)
|
||||
}
|
||||
|
||||
override fun provideSourceManager(app: Application): SourceManager {
|
||||
return Mockito.mock(SourceManager::class.java, Mockito.RETURNS_DEEP_STUBS)
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue