Skip to content

Commit

Permalink
Improved the OpeningFilesFromStorageTest, EncodedUrlTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Sep 30, 2024
1 parent 1553e37 commit fe60f58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
} catch (ignore: Exception) {
fail("Could not open file from file manager. Original exception = $ignore")
} finally {
deleteAllFilesInDirectory(File(sharedPreferenceUtil.prefStorage))
deleteZimFileFromDownloadsFolder(uri!!)
}
}
Expand All @@ -149,6 +150,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
} catch (ignore: Exception) {
fail("Could not open file from file manager. Original exception = $ignore")
} finally {
deleteAllFilesInDirectory(File(sharedPreferenceUtil.prefStorage))
deleteZimFileFromDownloadsFolder(uri!!)
}
}
Expand Down Expand Up @@ -272,6 +274,18 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
return uri
}

private fun deleteAllFilesInDirectory(directory: File) {
if (directory.isDirectory) {
directory.listFiles()?.forEach { file ->
if (file.isDirectory) {
// Recursively delete files in subdirectories
deleteAllFilesInDirectory(file)
}
file.delete()
}
}
}

@After
fun release() {
Intents.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.junit.Before
import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.DarkModeConfig
import org.kiwix.kiwixmobile.core.extensions.deleteFile
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
Expand Down Expand Up @@ -161,7 +162,9 @@ class EncodedUrlTest : BaseActivityTest() {
)
}
// dispose the ZimFileReader
zimFileReader.dispose()
zimFileReader.dispose().also {
zimFile.deleteFile()
}
}

data class EncodedUrl(val url: String, val expectedUrl: String)
Expand Down

0 comments on commit fe60f58

Please sign in to comment.