mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Moved tests over to Kotlin. (#1428)
This commit is contained in:
parent
6b2dd8c1df
commit
22772c851e
29 changed files with 1453 additions and 1679 deletions
33
app/src/test/kotlin/fr/free/nrw/commons/FileUtilsTest.kt
Normal file
33
app/src/test/kotlin/fr/free/nrw/commons/FileUtilsTest.kt
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import fr.free.nrw.commons.upload.FileUtils
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.io.*
|
||||
|
||||
class FileUtilsTest {
|
||||
@Test
|
||||
fun copiedFileIsIdenticalToSource() {
|
||||
val source = File.createTempFile("temp", "")
|
||||
val dest = File.createTempFile("temp", "")
|
||||
writeToFile(source, "Hello, World")
|
||||
|
||||
FileUtils.copy(FileInputStream(source), FileOutputStream(dest))
|
||||
|
||||
assertEquals(getString(source), getString(dest))
|
||||
}
|
||||
|
||||
private fun writeToFile(file: File, s: String) {
|
||||
val buf = BufferedOutputStream(FileOutputStream(file))
|
||||
buf.write(s.toByteArray())
|
||||
buf.close()
|
||||
}
|
||||
|
||||
private fun getString(file: File): String {
|
||||
val bytes = ByteArray(file.length().toInt())
|
||||
val buf = BufferedInputStream(FileInputStream(file))
|
||||
buf.read(bytes, 0, bytes.size)
|
||||
buf.close()
|
||||
return String(bytes)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue