Skip to content

Commit 778f2d5

Browse files
committed
Use kotlin.io.path extensions in UnifiedPropertiesLoaderTest
Replace java.io.File API with kotlin.io.path extensions and Java NIO as suggested in code review. Uses Files.createDirectories() for parent directory creation since kotlin.io.path.createParentDirectories() is not available in the current Kotlin stdlib version. All tests pass with this implementation. Signed-off-by: Kim Tae Eun <snowykte0426@naver.com>
1 parent 12be202 commit 778f2d5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

modules/mockk-core/src/jvmTest/kotlin/io/mockk/core/config/UnifiedPropertiesLoaderTest.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ package io.mockk.core.config
33
import kotlin.test.Test
44
import kotlin.test.assertTrue
55
import kotlin.test.assertEquals
6-
import java.io.File
6+
import java.nio.file.Files
7+
import java.nio.file.Path
8+
import kotlin.io.path.Path
9+
import kotlin.io.path.writeText
10+
import kotlin.io.path.deleteExisting
711

812
class UnifiedPropertiesLoaderTest {
913
private val loader = UnifiedPropertiesLoader
@@ -39,15 +43,16 @@ class UnifiedPropertiesLoaderTest {
3943
deleteFromClasspath(UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE)
4044
deleteFromClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE)
4145
}
42-
4346
private fun writeToClasspath(path: String, content: String) {
44-
val file = File(this::class.java.getResource("/")!!.toURI()).resolve(path.removePrefix("/"))
45-
file.parentFile?.mkdirs()
46-
file.writeText(content)
47+
getRoot().resolve(path.removePrefix("/")).run {
48+
parent?.let { Files.createDirectories(it) }
49+
writeText(content)
50+
}
4751
}
4852

4953
private fun deleteFromClasspath(path: String) {
50-
val file = File(this::class.java.getResource("/")!!.toURI()).resolve(path.removePrefix("/"))
51-
file.delete()
54+
getRoot().resolve(path.removePrefix("/")).deleteExisting()
5255
}
56+
57+
private fun getRoot(): Path = Path.of(this::class.java.getResource("/")!!.toURI())
5358
}

0 commit comments

Comments
 (0)