Minor cleanups

This commit is contained in:
Erik C. Thauvin 2025-05-28 20:21:17 -07:00
parent 80fac24b4d
commit c9cd086ba1
Signed by: erik
GPG key ID: 776702A6A2DA330E
6 changed files with 27 additions and 32 deletions

View file

@ -144,21 +144,8 @@ class AkismetTests {
}
private fun getKey(key: String): String {
var value = System.getenv(key) ?: ""
if (value.isBlank()) {
val localProps = File("local.properties")
localProps.apply {
if (exists()) {
FileInputStream(this).use { fis ->
Properties().apply {
load(fis)
value = getProperty(key, "")
}
}
}
}
}
return value
return System.getenv(key)?.takeUnless { it.isBlank() }
?: loadPropertyValue(key)
}
private fun getMockRequest(): HttpServletRequest {
@ -176,6 +163,16 @@ class AkismetTests {
}
return request
}
private fun loadPropertyValue(key: String): String {
return File("local.properties")
.takeIf { it.exists() }
?.let { file ->
FileInputStream(file).use { fis ->
Properties().apply { load(fis) }.getProperty(key, "")
}
}.orEmpty()
}
}
@Nested