|
| 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