Skip to content

Commit

Permalink
Fixed FileSearchTest, StorageObserverTest, and `ZimManageViewMode…
Browse files Browse the repository at this point in the history
…lTest` test that are failing after this change.
  • Loading branch information
MohitMaliDeveloper committed Jan 17, 2024
1 parent 727885b commit 8bfb180
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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))
}
Expand All @@ -133,7 +134,7 @@ class FileSearchTest {
val unreadableFile = File.createTempFile("fileToFind", ".zim")
expectFromMediaStore(unreadableFile)
unreadableFile.delete()
fileSearch.scan()
fileSearch.scan(scanningProgressListener)
.test()
.assertValue(listOf())
}
Expand Down

0 comments on commit 8bfb180

Please sign in to comment.