Address unit test compilation errors

They don't actually run since they broke a long time ago (AndroidX + Roboelectric issues?), but it addresses the annoying red squigglies in Android Studio at least.
This commit is contained in:
arkon 2021-01-24 22:33:09 -05:00
parent 5f7e34b6a1
commit 0ecfef3f70
3 changed files with 32 additions and 30 deletions

View file

@ -3,7 +3,10 @@ package eu.kanade.tachiyomi.ui.reader
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.SeekBar import android.widget.SeekBar
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.core.graphics.* import androidx.core.graphics.alpha
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog

View file

@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.database.models.TrackImpl import eu.kanade.tachiyomi.data.database.models.TrackImpl
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -31,7 +32,6 @@ import org.mockito.Mockito.mock
import org.robolectric.RuntimeEnvironment import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config import org.robolectric.annotation.Config
import rx.Observable import rx.Observable
import rx.observers.TestSubscriber
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.InjektModule import uy.kohesive.injekt.api.InjektModule
import uy.kohesive.injekt.api.InjektRegistrar import uy.kohesive.injekt.api.InjektRegistrar
@ -211,11 +211,8 @@ class BackupTest {
networkManga.description = "This is a description" networkManga.description = "This is a description"
`when`(source.fetchMangaDetails(jsonManga)).thenReturn(Observable.just(networkManga)) `when`(source.fetchMangaDetails(jsonManga)).thenReturn(Observable.just(networkManga))
val obs = legacyBackupManager.fetchManga(source, jsonManga) runBlocking {
val testSubscriber = TestSubscriber<Manga>() legacyBackupManager.fetchManga(source, jsonManga)
obs.subscribe(testSubscriber)
testSubscriber.assertNoErrors()
// Check if restore successful // Check if restore successful
val dbCats = legacyBackupManager.databaseHelper.getFavoriteMangas().executeAsBlocking() val dbCats = legacyBackupManager.databaseHelper.getFavoriteMangas().executeAsBlocking()
@ -223,6 +220,7 @@ class BackupTest {
assertThat(dbCats[0].viewer).isEqualTo(3) assertThat(dbCats[0].viewer).isEqualTo(3)
assertThat(dbCats[0].description).isEqualTo("This is a description") assertThat(dbCats[0].description).isEqualTo("This is a description")
} }
}
/** /**
* Test if chapter restore is successful * Test if chapter restore is successful
@ -254,17 +252,14 @@ class BackupTest {
(1..10).mapTo(chaptersRemote) { getSingleChapter("Chapter $it") } (1..10).mapTo(chaptersRemote) { getSingleChapter("Chapter $it") }
`when`(source.fetchChapterList(manga)).thenReturn(Observable.just(chaptersRemote)) `when`(source.fetchChapterList(manga)).thenReturn(Observable.just(chaptersRemote))
// Call restoreChapterFetchObservable runBlocking {
val obs = legacyBackupManager.restoreChapters(source, manga, restoredChapters) legacyBackupManager.restoreChapters(source, manga, restoredChapters)
val testSubscriber = TestSubscriber<Pair<List<Chapter>, List<Chapter>>>()
obs.subscribe(testSubscriber)
testSubscriber.assertNoErrors()
val dbCats = legacyBackupManager.databaseHelper.getChapters(manga).executeAsBlocking() val dbCats = legacyBackupManager.databaseHelper.getChapters(manga).executeAsBlocking()
assertThat(dbCats).hasSize(10) assertThat(dbCats).hasSize(10)
assertThat(dbCats[0].read).isEqualTo(true) assertThat(dbCats[0].read).isEqualTo(true)
} }
}
/** /**
* Test to check if history restore works * Test to check if history restore works

View file

@ -9,8 +9,8 @@ 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.LibraryManga import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -76,10 +76,12 @@ class LibraryUpdateServiceTest {
`when`(source.fetchChapterList(manga)).thenReturn(Observable.just(sourceChapters)) `when`(source.fetchChapterList(manga)).thenReturn(Observable.just(sourceChapters))
service.updateManga(manga).subscribe() runBlocking {
service.updateManga(manga)
assertThat(service.db.getChapters(manga).executeAsBlocking()).hasSize(2) assertThat(service.db.getChapters(manga).executeAsBlocking()).hasSize(2)
} }
}
@Test @Test
fun testContinuesUpdatingWhenAMangaFails() { fun testContinuesUpdatingWhenAMangaFails() {
@ -92,18 +94,20 @@ class LibraryUpdateServiceTest {
// One of the updates will fail // One of the updates will fail
`when`(source.fetchChapterList(favManga[0])).thenReturn(Observable.just(chapters)) `when`(source.fetchChapterList(favManga[0])).thenReturn(Observable.just(chapters))
`when`(source.fetchChapterList(favManga[1])).thenReturn(Observable.error<List<SChapter>>(Exception())) `when`(source.fetchChapterList(favManga[1])).thenReturn(Observable.error(Exception()))
`when`(source.fetchChapterList(favManga[2])).thenReturn(Observable.just(chapters3)) `when`(source.fetchChapterList(favManga[2])).thenReturn(Observable.just(chapters3))
val intent = Intent() val intent = Intent()
val target = LibraryUpdateService.Target.CHAPTERS val target = LibraryUpdateService.Target.CHAPTERS
service.updateChapterList(service.getMangaToUpdate(intent, target)).subscribe() runBlocking {
service.updateChapterList(service.getMangaToUpdate(intent, target))
// There are 3 network attempts and 2 insertions (1 request failed) // There are 3 network attempts and 2 insertions (1 request failed)
assertThat(service.db.getChapters(favManga[0]).executeAsBlocking()).hasSize(2) assertThat(service.db.getChapters(favManga[0]).executeAsBlocking()).hasSize(2)
assertThat(service.db.getChapters(favManga[1]).executeAsBlocking()).hasSize(0) assertThat(service.db.getChapters(favManga[1]).executeAsBlocking()).hasSize(0)
assertThat(service.db.getChapters(favManga[2]).executeAsBlocking()).hasSize(2) assertThat(service.db.getChapters(favManga[2]).executeAsBlocking()).hasSize(2)
} }
}
private fun createChapters(vararg urls: String): List<Chapter> { private fun createChapters(vararg urls: String): List<Chapter> {
val list = mutableListOf<Chapter>() val list = mutableListOf<Chapter>()