forked from getodk/collect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef62803
commit 63a7a4b
Showing
6 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
androidshared/src/test/java/org/odk/collect/androidshared/system/UriExtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.odk.collect.androidshared.system | ||
|
||
import android.app.Application | ||
import androidx.core.net.toUri | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.odk.collect.shared.TempFiles | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class UriExtTest { | ||
private val context = ApplicationProvider.getApplicationContext<Application>() | ||
|
||
@Test | ||
fun `copyToFile copies the source file to the target file`() { | ||
val sourceFile = TempFiles.createTempFile().also { | ||
it.writeText("blah") | ||
} | ||
val sourceFileUri = sourceFile.toUri() | ||
val targetFile = TempFiles.createTempFile() | ||
|
||
sourceFileUri.copyToFile(context, targetFile) | ||
assertThat(targetFile.readText(), equalTo(sourceFile.readText())) | ||
} | ||
|
||
@Test | ||
fun `getFileExtension returns file extension`() { | ||
val file = TempFiles.createTempFile(".jpg") | ||
val fileUri = file.toUri() | ||
|
||
assertThat(fileUri.getFileExtension(context), equalTo(".jpg")) | ||
} | ||
|
||
@Test | ||
fun `getFileName returns file name`() { | ||
val file = TempFiles.createTempFile() | ||
val fileUri = file.toUri() | ||
|
||
assertThat(fileUri.getFileName(context), equalTo(file.name)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters