Skip to content

Commit 92d9599

Browse files
committed
Add more tests to FileHelper
1 parent 05fbfbe commit 92d9599

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/scala/codacy/dockerApi/utils/FileHelperTest.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ class FileHelperTest extends FlatSpec with Matchers {
1818
result2 should be("filename.ext")
1919
}
2020

21+
"FileHelper" should "stripPath with no common prefix" in {
22+
val pathString: String = "filename.ext"
23+
val pathString2: String = "c/d/filename.ext"
24+
25+
val result: String = FileHelper.stripPath(pathString, "/a/b/")
26+
result should be(pathString)
27+
28+
val result2: String = FileHelper.stripPath(pathString2, "/a/b/")
29+
result2 should be(pathString2)
30+
}
31+
2132
"FileHelper" should "stripPath from Path" in {
2233
val path: java.nio.file.Path = java.nio.file.Paths.get("a/b/c/filename.ext")
2334
val pathPrefix: java.nio.file.Path = java.nio.file.Paths.get("a/b")
@@ -31,4 +42,22 @@ class FileHelperTest extends FlatSpec with Matchers {
3142
val result2: String = FileHelper.stripPath(path2, pathPrefix2)
3243
result2 should be("filename.ext")
3344
}
45+
46+
"FileHelper" should "createTmpFile" in {
47+
val fileTmp = FileHelper.createTmpFile("foo", "prefix", ".ext").toString
48+
49+
java.nio.file.Paths.get(fileTmp).getFileName.toString should startWith ("prefix")
50+
fileTmp should endWith (".ext")
51+
io.Source.fromFile(fileTmp).mkString should be("foo")
52+
}
53+
54+
"FileHelper" should "createFile" in {
55+
val pathString: String = "filename.ext"
56+
57+
val file = FileHelper.createFile(pathString, "foo").toString
58+
59+
io.Source.fromFile(file).mkString should be("foo")
60+
61+
new java.io.File(file).delete()
62+
}
3463
}

0 commit comments

Comments
 (0)