Added tests for Utils class.
This commit is contained in:
parent
7bf291ac26
commit
8b0108ba96
1 changed files with 28 additions and 7 deletions
|
@ -37,35 +37,38 @@ import java.io.File
|
|||
import java.nio.file.Files
|
||||
import java.util.Properties
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverPluginSpec : Spek({
|
||||
object UtilsSpec : Spek({
|
||||
describe("a config and version") {
|
||||
val version by memoized { Version() }
|
||||
val config by memoized { SemverConfig() }
|
||||
val configFile = File("test.properties")
|
||||
lateinit var props: Properties
|
||||
|
||||
before {
|
||||
config.properties = configFile.name
|
||||
}
|
||||
|
||||
describe("test save properties") {
|
||||
describe("save properties") {
|
||||
it("should save properties") {
|
||||
Utils.saveProperties(config, version)
|
||||
assertTrue(configFile.exists())
|
||||
}
|
||||
}
|
||||
describe("validate the properties file") {
|
||||
it("verion should be the same") {
|
||||
val props = Properties().apply {
|
||||
it("load the properties") {
|
||||
props = Properties().apply {
|
||||
Files.newInputStream(configFile.toPath()).use { nis ->
|
||||
load(nis)
|
||||
}
|
||||
configFile.delete()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
describe("validate the properties file") {
|
||||
it("version should be the same") {
|
||||
assertEquals(props.getProperty(config.majorKey), version.major, "Major")
|
||||
assertEquals(props.getProperty(config.minorKey), version.minor, "Minor")
|
||||
assertEquals(props.getProperty(config.patchKey), version.patch, "Patch")
|
||||
|
@ -76,5 +79,23 @@ object SemverPluginSpec : Spek({
|
|||
assertNull(props.getProperty(config.separatorKey), "Separator")
|
||||
}
|
||||
}
|
||||
describe("setting system properties") {
|
||||
val newVersion = arrayOf(
|
||||
Pair(config.majorKey, "2"),
|
||||
Pair(config.minorKey, "1"),
|
||||
Pair(config.patchKey, "1"),
|
||||
Pair(config.preReleaseKey, "beta"),
|
||||
Pair(config.buildMetaKey, "007"))
|
||||
it("should have none of our properties") {
|
||||
assertFalse(Utils.hasEnv(setOf(config.majorKey, config.minorKey, config.patchKey, config.preReleaseKey,
|
||||
config.buildMetaKey)))
|
||||
}
|
||||
it("version should match system properties") {
|
||||
newVersion.forEach {
|
||||
System.getProperties().setProperty(it.first, it.second)
|
||||
assertEquals(Utils.loadProperty(props, it.first, ""), it.second)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue