@@ -10,7 +10,7 @@ class FileUtilsTest {
1010 @Test
1111 fun deleteFile () {
1212 val file = File .createTempFile(" testfile" , " " )
13- writeToFile( file, " Hello, World" )
13+ file.writeText( " Hello, World" )
1414
1515 assertEquals(true , file.exists())
1616 assertEquals(true , FileUtils .deleteFile(file))
@@ -23,40 +23,22 @@ class FileUtilsTest {
2323
2424 assertEquals(
2525 " 907d14fb3af2b0d4f18c2d46abe8aedce17367bd" ,
26- fileUtilsWrapper.getSHA1(toInputStream( " Hello, World" ))
26+ fileUtilsWrapper.getSHA1(" Hello, World" .byteInputStream( ))
2727 )
2828
2929 assertEquals(
3030 " 8b971da6347bd126872ea2f4f8d394e70c74073a" ,
31- fileUtilsWrapper.getSHA1(toInputStream( " apps-android-commons" ))
31+ fileUtilsWrapper.getSHA1(" apps-android-commons" .byteInputStream( ))
3232 )
3333
3434 assertEquals(
3535 " e9d30f5a3a82792b9d79c258366bd53207ceaeb3" ,
36- fileUtilsWrapper.getSHA1(toInputStream( " domdomegg was here" ))
36+ fileUtilsWrapper.getSHA1(" domdomegg was here" .byteInputStream( ))
3737 )
3838
3939 assertEquals(
4040 " 96e733a3e59261c0621ba99be5bd10bb21abe53e" ,
41- fileUtilsWrapper.getSHA1(toInputStream( " iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" ))
41+ fileUtilsWrapper.getSHA1(" iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" .byteInputStream( ))
4242 )
4343 }
44-
45- private fun writeToFile (file : File , s : String ) {
46- val buf = BufferedOutputStream (FileOutputStream (file))
47- buf.write(s.toByteArray())
48- buf.close()
49- }
50-
51- private fun getString (file : File ): String {
52- val bytes = ByteArray (file.length().toInt())
53- val buf = BufferedInputStream (FileInputStream (file))
54- buf.read(bytes, 0 , bytes.size)
55- buf.close()
56- return String (bytes)
57- }
58-
59- private fun toInputStream (str : String ) : InputStream {
60- return ByteArrayInputStream (str.toByteArray(Charsets .UTF_8 ))
61- }
6244}
0 commit comments