key
infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.key(assertionCreator: Expect<K>.() -> Unit): Expect<T>(source)
Expects that the property Map.Entry.key of the subject of this
expectation holds all assertions the given assertionCreator creates for it and returns an Expect for the current subject of this
expectation.
Return
an Expect for the subject of this
expectation.
Samples
val entry = mapOf(1 to "a").entries.first()
expect(entry).key { // subject inside this expectation-group is of type Int (actually 1)
this toEqual 1
} // subject here is back to type Map.Entry<Int, String>
fails { // because 1 is not equal to 2
expect(entry).key { // subject inside this expectation-group is of type Int (actually 1)
this toEqual 2
}
}
Helper function to create an KeyWithCreator based on the given key and assertionCreator.
Samples
expect(mapOf(1 to "a")) getExisting key(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "a"
}
fails {
expect(mapOf(1 to "a")) getExisting key(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "b" // fails because "a" is not equal to "b"
}
}
fails {
// all expectations are evaluated inside an expectation-group block; for more details:
// https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group
expect(mapOf(1 to "a")) getExisting key(2) { // fails because key 2 does not exist
this toEqual "a" // still evaluated because we use an expectation-group block
// use `.getExisting(key).` if you want a fail fast behaviour
}
}
Creates an Expect for the property Map.Entry.key of the subject of this
expectation, so that further fluent calls are assertions about it.
Return
The newly created Expect for the extracted feature.
Samples
val entry = mapOf(1 to "a").entries.first()
expect(entry).key toEqual 1
// | | subject here is type of Int (actually 1)
// | subject here is of type Map.Entry<Int, String>
fails { // because 1 is not equal to 2
expect(entry).key toEqual 2
// | | subject here is type of Int (actually 1)
// | subject here is of type Map.Entry<Int, String>
}