From 7da5d130b7d22b88bee5ea5d68e0688b7ea0a3f3 Mon Sep 17 00:00:00 2001 From: Veyndan Stuart Date: Sun, 1 Mar 2020 14:32:30 +0100 Subject: [PATCH] Replace functions in FileUtilsTest with ones from kotlin-stdlib (#2943) --- .../free/nrw/commons/utils/FileUtilsTest.kt | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/app/src/test/kotlin/fr/free/nrw/commons/utils/FileUtilsTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/utils/FileUtilsTest.kt index f9a4fd363..4980ec61a 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/utils/FileUtilsTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/utils/FileUtilsTest.kt @@ -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)) - } }