fun <K, V, T : Map<out K, V>> Expect<T>.getExisting(key: K): Expect<V>
(source)
Expects that the subject of this
expectation (a Map) contains the given key,
creates an Expect for the corresponding value and returns the newly created assertion container,
so that further fluent calls are assertions about it.
expect(mapOf(1 to "a"))
.getExisting(1) // subject is of type String (actually "a")
.toBe("a")
fails {
expect(mapOf(1 to "a"))
.getExisting(1) // subject is of type String (actually "a")
.toBe("b") // fails because "a" is not equal to "b"
}
fails {
expect(mapOf(1 to "a"))
.getExisting(2) // subject is of type String, but assertion fails because key 2 does not exist
.toBe("a")
}
Return
The newly created Expect for the extracted feature.
fun <K, V, T : Map<out K, V>> Expect<T>.getExisting(key: K, assertionCreator: Expect<V>.() -> Unit): Expect<T>
(source)
Expects that the subject of this
expectation (a Map) contains the given key and that
the corresponding value holds all assertions the given assertionCreator creates for it.
expect(mapOf(1 to "a"))
.getExisting(1, { // subject inside this block is of type String (actually "a")
toBe("a")
})
fails {
expect(mapOf(1 to "a"))
.getExisting(1, { // subject inside this block is of type String (actually "a")
toBe("b") // fails because "a" is not equal to "b"
})
}
fails {
expect(mapOf(1 to "a"))
.getExisting(2, { // subject is of type String, but assertion fails because key 2 does not exist
toBe("a")
})
}
Return
an Expect for the subject of this
expectation.