@@ -49,8 +49,8 @@ class TemplatedUrlTest : ShouldSpec({
4949 templatedUrl.set("param", "value")
5050
5151 templatedUrl.resolve(
52- mapOf("host" to "example .com", "path" to "api/resource ", "param" to "value ")
53- ) shouldBe URI ("wss://example .com/api/resource ? param=value ")
52+ mapOf("host" to "example2 .com", "path" to "api/resource2 ", "param" to "value2 ")
53+ ) shouldBe URI ("wss://example2 .com/api/resource2 ? param=value2 ")
5454 }
5555
5656 should("resolve with a new key-value pair without saving it") {
@@ -75,13 +75,32 @@ class TemplatedUrlTest : ShouldSpec({
7575 templatedUrl.resolve()
7676 }
7777 }
78+
79+ should("fail to resolve when some requiredKeys are not set") {
80+ val template = " https://{{host}}/{{path}}?optional={{optional}}"
81+ val templatedUrl = TemplatedUrl (template, requiredKeys = setOf("host", "path"))
82+
83+ templatedUrl.set("host", "example.com")
84+
85+ shouldThrow<IllegalArgumentException > {
86+ templatedUrl.resolve()
87+ }
88+ }
89+
7890 should("throw an exception when the URI is invalid") {
7991 val templatedUrl = TemplatedUrl ("https://example.com/{{}}")
8092
8193 shouldThrow<URISyntaxException > {
8294 templatedUrl.resolve()
8395 }
8496 }
97+ should("throw an exception when the values lead to an invalid URI ") {
98+ val templatedUrl = TemplatedUrl ("https://example.com/{{path}}")
99+
100+ shouldThrow<URISyntaxException > {
101+ templatedUrl.resolve("path", "}")
102+ }
103+ }
85104
86105 should("handle keys that appear multiple times") {
87106 val template = " https://{{host}}/{{path}}/{{path}}"
@@ -91,5 +110,12 @@ class TemplatedUrlTest : ShouldSpec({
91110
92111 templatedUrl.resolve() shouldBe URI ("https://example.com/resource/resource")
93112 }
113+ should("not modify the map passed as a constructor parameter") {
114+ val m = mutableMapOf("key1" to "value1", "key2" to "value2")
115+ val templatedUrl = TemplatedUrl ("https://example.com/{{key1}}/{{key2}}", m)
116+ templatedUrl.set("key1", "newValue1")
117+ templatedUrl.set("key2", "newValue2")
118+ m shouldBe mapOf("key1" to "value1", "key2" to "value2")
119+ }
94120 }
95121})
0 commit comments