mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
correct injection and mockk usage
This commit is contained in:
parent
1262bcee48
commit
b132d1c615
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
|
||||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||||
import org.kiwix.kiwixmobile.core.extensions.toast
|
import org.kiwix.kiwixmobile.core.extensions.toast
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||||
@ -28,7 +27,7 @@ import org.kiwix.kiwixmobile.core.utils.DialogShower
|
|||||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteZim
|
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteZim
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
||||||
import org.kiwix.kiwixmobile.kiwixActivityComponent
|
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DeleteFiles(private val booksOnDiskListItem: List<BookOnDisk>) :
|
class DeleteFiles(private val booksOnDiskListItem: List<BookOnDisk>) :
|
||||||
@ -39,7 +38,7 @@ class DeleteFiles(private val booksOnDiskListItem: List<BookOnDisk>) :
|
|||||||
@Inject lateinit var zimReaderContainer: ZimReaderContainer
|
@Inject lateinit var zimReaderContainer: ZimReaderContainer
|
||||||
|
|
||||||
override fun invokeWith(activity: Activity) {
|
override fun invokeWith(activity: Activity) {
|
||||||
(activity as BaseActivity).kiwixActivityComponent.inject(this)
|
(activity as ZimManageActivity).cachedComponent.inject(this)
|
||||||
booksOnDiskListItem.forEach {
|
booksOnDiskListItem.forEach {
|
||||||
dialogShower.show(DeleteZim(it), {
|
dialogShower.show(DeleteZim(it), {
|
||||||
if (deleteSpecificZimFile(it)) {
|
if (deleteSpecificZimFile(it)) {
|
||||||
|
@ -47,7 +47,7 @@ class LanguageDelegateTest {
|
|||||||
fun `creates HeaderViewHolder`() {
|
fun `creates HeaderViewHolder`() {
|
||||||
val parent = mockk<ViewGroup>()
|
val parent = mockk<ViewGroup>()
|
||||||
mockkObject(ViewGroupExtensions)
|
mockkObject(ViewGroupExtensions)
|
||||||
every { parent.inflate(R.layout.header_date, false) } returns mockk(relaxed = true)
|
every { parent.inflate(R.layout.header_date, false) } returns mockk()
|
||||||
assertThat(HeaderDelegate().createViewHolder(parent))
|
assertThat(HeaderDelegate().createViewHolder(parent))
|
||||||
.isInstanceOf(HeaderViewHolder::class.java)
|
.isInstanceOf(HeaderViewHolder::class.java)
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ class LanguageDelegateTest {
|
|||||||
fun `creates LanguageViewHolder`() {
|
fun `creates LanguageViewHolder`() {
|
||||||
val parent = mockk<ViewGroup>()
|
val parent = mockk<ViewGroup>()
|
||||||
mockkObject(ViewGroupExtensions)
|
mockkObject(ViewGroupExtensions)
|
||||||
every { parent.inflate(R.layout.item_language, false) } returns mockk(relaxed = true)
|
every { parent.inflate(R.layout.item_language, false) } returns mockk()
|
||||||
val clickAction = mockk<(LanguageItem) -> Unit>()
|
val clickAction = mockk<(LanguageItem) -> Unit>()
|
||||||
assertThat(LanguageItemDelegate(clickAction).createViewHolder(parent))
|
assertThat(LanguageItemDelegate(clickAction).createViewHolder(parent))
|
||||||
.isInstanceOf(LanguageViewHolder::class.java)
|
.isInstanceOf(LanguageViewHolder::class.java)
|
||||||
|
@ -33,8 +33,8 @@ class SaveLanguagesAndFinishTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `invoke saves and finishes`() {
|
fun `invoke saves and finishes`() {
|
||||||
setScheduler(Schedulers.trampoline())
|
setScheduler(Schedulers.trampoline())
|
||||||
val languageDao = mockk<NewLanguagesDao>(relaxUnitFun = true)
|
val languageDao = mockk<NewLanguagesDao>()
|
||||||
val activity = mockk<Activity>(relaxUnitFun = true)
|
val activity = mockk<Activity>()
|
||||||
val languages = listOf<Language>()
|
val languages = listOf<Language>()
|
||||||
SaveLanguagesAndFinish(languages, languageDao).invokeWith(activity)
|
SaveLanguagesAndFinish(languages, languageDao).invokeWith(activity)
|
||||||
verify {
|
verify {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user