Skip to content

Commit 73b8fb7

Browse files
committed
test: add coverage on map helper
1 parent beb2f79 commit 73b8fb7

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

testing/src/main/kotlin/org/neo4j/connectors/kafka/testing/MapSupport.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal object MapSupport {
2323
@Suppress("UNCHECKED_CAST")
2424
fun <K, Any> MutableMap<K, Any>.nestUnder(key: K, values: Map<K, Any>): MutableMap<K, Any> {
2525
val map = this[key]
26-
if (map !is MutableMap<*, *>) {
26+
if (map !is Map<*, *>) {
2727
throw IllegalStateException("entry at key $key is not a mutable map")
2828
}
2929
(map as MutableMap<K, Any>).putAll(values)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.connectors.kafka.testing
18+
19+
import java.lang.IllegalStateException
20+
import org.junit.jupiter.api.Assertions.*
21+
import org.junit.jupiter.api.Test
22+
import org.junit.jupiter.api.assertThrows
23+
import org.neo4j.connectors.kafka.testing.MapSupport.nestUnder
24+
25+
class MapSupportTest {
26+
27+
@Test
28+
fun `nests map under specified key`() {
29+
val initialMap = mutableMapOf<String, Any>("foo" to mutableMapOf("bar" to "baz"))
30+
31+
val result = initialMap.nestUnder("foo", mapOf("fighters" to "rocks"))
32+
33+
assertEquals(mutableMapOf("foo" to mutableMapOf("bar" to "baz", "fighters" to "rocks")), result)
34+
}
35+
36+
@Test
37+
fun `fails to nest map if key's value is not a map`() {
38+
val initialMap = mutableMapOf<String, Any>("foo" to "bar")
39+
40+
val exception =
41+
assertThrows<IllegalStateException> {
42+
initialMap.nestUnder("foo", mapOf("fighters" to "rocks"))
43+
}
44+
assertEquals(exception.message, "entry at key foo is not a mutable map")
45+
}
46+
}

0 commit comments

Comments
 (0)