mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -04:00
Fixed FileSearchTest
, StorageObserverTest
, and ZimManageViewModelTest
test that are failing after this change.
This commit is contained in:
parent
13b0ab0519
commit
57800a8da7
@ -47,6 +47,7 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.core.utils.BookUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.Language
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.MULTI
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.NORMAL
|
||||
@ -128,7 +129,11 @@ class ZimManageViewModelTest {
|
||||
every { connectivityBroadcastReceiver.action } returns "test"
|
||||
every { downloadDao.downloads() } returns downloads
|
||||
every { newBookDao.books() } returns books
|
||||
every { storageObserver.booksOnFileSystem } returns booksOnFileSystem
|
||||
every {
|
||||
storageObserver.getBooksOnFileSystem(
|
||||
any<ScanningProgressListener>()
|
||||
)
|
||||
} returns booksOnFileSystem
|
||||
every { newLanguagesDao.languages() } returns languages
|
||||
every { fat32Checker.fileSystemStates } returns fileSystemStates
|
||||
every { connectivityBroadcastReceiver.networkStates } returns networkStates
|
||||
|
@ -33,6 +33,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Factory
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileSearch
|
||||
import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener
|
||||
import org.kiwix.sharedFunctions.book
|
||||
import org.kiwix.sharedFunctions.bookOnDisk
|
||||
import org.kiwix.sharedFunctions.resetSchedulers
|
||||
@ -48,6 +49,7 @@ class StorageObserverTest {
|
||||
private val file: File = mockk()
|
||||
private val readerFactory: Factory = mockk()
|
||||
private val zimFileReader: ZimFileReader = mockk()
|
||||
private val scanningProgressListener: ScanningProgressListener = mockk()
|
||||
|
||||
private val files: PublishProcessor<List<File>> = PublishProcessor.create()
|
||||
private val downloads: PublishProcessor<List<DownloadModel>> = PublishProcessor.create()
|
||||
@ -66,7 +68,7 @@ class StorageObserverTest {
|
||||
@BeforeEach fun init() {
|
||||
clearAllMocks()
|
||||
every { sharedPreferenceUtil.prefStorage } returns "a"
|
||||
every { fileSearch.scan() } returns files
|
||||
every { fileSearch.scan(scanningProgressListener) } returns files
|
||||
every { downloadDao.downloads() } returns downloads
|
||||
every { readerFactory.create(file) } returns zimFileReader
|
||||
storageObserver = StorageObserver(downloadDao, fileSearch, readerFactory)
|
||||
@ -92,7 +94,7 @@ class StorageObserverTest {
|
||||
verify { zimFileReader.dispose() }
|
||||
}
|
||||
|
||||
private fun booksOnFileSystem() = storageObserver.booksOnFileSystem
|
||||
private fun booksOnFileSystem() = storageObserver.getBooksOnFileSystem(scanningProgressListener)
|
||||
.test()
|
||||
.also {
|
||||
downloads.offer(listOf(downloadModel))
|
||||
|
@ -47,6 +47,7 @@ class FileSearchTest {
|
||||
private val externalStorageDirectory: File = mockk()
|
||||
private val contentResolver: ContentResolver = mockk()
|
||||
private val storageDevice: StorageDevice = mockk()
|
||||
private val scanningProgressListener: ScanningProgressListener = mockk()
|
||||
|
||||
init {
|
||||
setScheduler(Schedulers.trampoline())
|
||||
@ -80,7 +81,7 @@ class FileSearchTest {
|
||||
@Test
|
||||
fun `scan of directory that doesn't exist returns nothing`() {
|
||||
every { contentResolver.query(any(), any(), any(), any(), any()) } returns null
|
||||
fileSearch.scan()
|
||||
fileSearch.scan(scanningProgressListener)
|
||||
.test()
|
||||
.assertValue(listOf())
|
||||
}
|
||||
@ -92,7 +93,7 @@ class FileSearchTest {
|
||||
File.createTempFile("willNotFind", ".txt")
|
||||
every { contentResolver.query(any(), any(), any(), any(), any()) } returns null
|
||||
every { storageDevice.name } returns zimFile.parent
|
||||
val fileList = fileSearch.scan()
|
||||
val fileList = fileSearch.scan(scanningProgressListener)
|
||||
.test()
|
||||
.values()[0]
|
||||
assertThat(fileList).containsExactlyInAnyOrder(zimFile, zimaaFile)
|
||||
@ -109,7 +110,7 @@ class FileSearchTest {
|
||||
)
|
||||
every { contentResolver.query(any(), any(), any(), any(), any()) } returns null
|
||||
every { storageDevice.name } returns zimFile.parentFile.parent
|
||||
val fileList = fileSearch.scan()
|
||||
val fileList = fileSearch.scan(scanningProgressListener)
|
||||
.test()
|
||||
.values()[0]
|
||||
assertThat(fileList).containsExactlyInAnyOrder(zimFile)
|
||||
@ -123,7 +124,7 @@ class FileSearchTest {
|
||||
fun `scan media store, if files are readable they are returned`() {
|
||||
val fileToFind = File.createTempFile("fileToFind", ".zim")
|
||||
expectFromMediaStore(fileToFind)
|
||||
fileSearch.scan()
|
||||
fileSearch.scan(scanningProgressListener)
|
||||
.test()
|
||||
.assertValue(listOf(fileToFind))
|
||||
}
|
||||
@ -133,7 +134,7 @@ class FileSearchTest {
|
||||
val unreadableFile = File.createTempFile("fileToFind", ".zim")
|
||||
expectFromMediaStore(unreadableFile)
|
||||
unreadableFile.delete()
|
||||
fileSearch.scan()
|
||||
fileSearch.scan(scanningProgressListener)
|
||||
.test()
|
||||
.assertValue(listOf())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user