Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app/src/test/kotlin/com/wire/android/util/FileHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import android.os.Environment
import androidx.core.content.FileProvider
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockkStatic
import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.test.runTest
import okio.Path
import okio.Path.Companion.toOkioPath
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -98,10 +100,10 @@ class FileHelperTest {
@Test
fun `given Android greater than 9, when saving file to downloads folder, then use correct order of executions`() = runTest {
// given
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
val arrangement = Arrangement()
.withUriMimeType("text/plain")
.withUriMimeType(downloadedFilePath, "text/plain")
.arrange()
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
// when
saveFileToDownloadsFolder("name", downloadedFilePath, 100L, arrangement.context)
// then
Expand All @@ -118,10 +120,10 @@ class FileHelperTest {
@Test
fun `given Android 9, when saving file to downloads folder, then use correct order of executions`() = runTest {
// given
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
val arrangement = Arrangement()
.withUriMimeType("text/plain")
.withUriMimeType(downloadedFilePath, "text/plain")
.arrange()
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
// when
saveFileToDownloadsFolder("name", downloadedFilePath, 100L, arrangement.context)
// then
Expand All @@ -138,10 +140,10 @@ class FileHelperTest {
@Test
fun `given Android 9 and null mimeType, when saving file to downloads folder, then use mimeType indicating all types`() = runTest {
// given
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
val arrangement = Arrangement()
.withUriMimeType(null)
.withUriMimeType(downloadedFilePath, null)
.arrange()
val downloadedFilePath = tempDir.newFile("filename.txt").toOkioPath()
// when
saveFileToDownloadsFolder("name", downloadedFilePath, 100L, arrangement.context)
// then
Expand All @@ -168,6 +170,7 @@ class FileHelperTest {
MockKAnnotations.init(this, relaxUnitFun = true)
mockkStatic(Environment::class)
mockkStatic(FileProvider::class)
mockkStatic(Uri::class)
mockkStatic("com.wire.android.util.FileUtilKt")
coEvery { context.packageName } returns "com.wire"
coEvery { context.contentResolver } returns contentResolver
Expand All @@ -177,11 +180,11 @@ class FileHelperTest {
coEvery { contentResolver.insert(any(), any()) } returns uri
coEvery { downloadManager.addCompletedDownload(any(), any(), any(), any(), any(), any(), any()) } returns 1L
coEvery { contentResolver.copyFile(any(), any()) } returns Unit
withUriMimeType(null)
}

fun withUriMimeType(mimeType: String?) = apply {
coEvery { uri.getMimeType(context) } returns mimeType
fun withUriMimeType(downloadedDataPath: Path, mimeType: String?) = apply {
every { Uri.parse(downloadedDataPath.toString()) } returns uri
every { uri.getMimeType(context) } returns mimeType
}

fun arrange() = this
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ junit5 = "5.11.0"
mockk = "1.14.11"
okio = "3.9.0"
turbine = "1.2.1"
robolectric = "4.14.1"
robolectric = "4.16.1"
hamcrest = "3.0"
rules = "1.7.0"
zxing = "3.5.2"
Expand Down
Loading