-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParametersTest.kt
More file actions
39 lines (37 loc) · 1.72 KB
/
ParametersTest.kt
File metadata and controls
39 lines (37 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mjs.wiremock
import com.github.tomakehurst.wiremock.extension.Parameters
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
class ParametersTest : DescribeSpec({
describe("Parameters getDoubleValue extension function") {
it("returns the default if no value is found for the key") {
val parameters = Parameters()
val default = 500.0
parameters.getDoubleValue("median", default) shouldBe default
}
it("returns the value for the key if it is Double") {
val parameters = Parameters().also { it["median"] = 1000.0 }
val median = parameters.getDoubleValue("median", 2000.0)
median.shouldBeInstanceOf<Double>()
median shouldBe 1000.0
}
it("returns the value for the key if it can be cast to Double") {
val parameters = Parameters().also { it["median"] = 1000 }
val median = parameters.getDoubleValue("median", 2000.0)
median.shouldBeInstanceOf<Double>()
median shouldBe 1000.0
}
it("returns the value for the key if a string value can be parsed as Double") {
val parameters = Parameters().also { it["median"] = "1000.0" }
val median = parameters.getDoubleValue("median", 2000.0)
median.shouldBeInstanceOf<Double>()
median shouldBe 1000.0
}
it("returns the default if a string value cannot be parsed as Double") {
val parameters = Parameters().also { it["median"] = "Not a double" }
val default = 1500.0
parameters.getDoubleValue("median", default) shouldBe default
}
}
})