Replace functions in FileUtilsTest with ones from kotlin-stdlib (#2943)

This commit is contained in:
Veyndan Stuart 2020-03-01 14:32:30 +01:00 committed by GitHub
parent e3034918e7
commit 7da5d130b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,7 @@ class FileUtilsTest {
@Test
fun deleteFile() {
val file = File.createTempFile("testfile", "")
writeToFile(file, "Hello, World")
file.writeText("Hello, World")
assertEquals(true, file.exists())
assertEquals(true, FileUtils.deleteFile(file))
@ -23,40 +23,22 @@ class FileUtilsTest {
assertEquals(
"907d14fb3af2b0d4f18c2d46abe8aedce17367bd",
fileUtilsWrapper.getSHA1(toInputStream("Hello, World"))
fileUtilsWrapper.getSHA1("Hello, World".byteInputStream())
)
assertEquals(
"8b971da6347bd126872ea2f4f8d394e70c74073a",
fileUtilsWrapper.getSHA1(toInputStream("apps-android-commons"))
fileUtilsWrapper.getSHA1("apps-android-commons".byteInputStream())
)
assertEquals(
"e9d30f5a3a82792b9d79c258366bd53207ceaeb3",
fileUtilsWrapper.getSHA1(toInputStream("domdomegg was here"))
fileUtilsWrapper.getSHA1("domdomegg was here".byteInputStream())
)
assertEquals(
"96e733a3e59261c0621ba99be5bd10bb21abe53e",
fileUtilsWrapper.getSHA1(toInputStream("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="))
fileUtilsWrapper.getSHA1("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=".byteInputStream())
)
}
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)
}
private fun toInputStream(str: String) : InputStream {
return ByteArrayInputStream(str.toByteArray(Charsets.UTF_8))
}
}