toContainOnly
Expects that the subject of this
expectation (a Map) contains only one entry with a key as defined by keyValuePair's Pair.first and a corresponding value as defined by keyValuePair's Pair.second
Delegates to 'it toContain o inAny order but only entry keyValuePair'.
Return
an Expect for the subject of this
expectation.
Samples
expect(mapOf(1 to "a")) toContainOnly (1 to "a")
fails { // because the map contains key 2 with value "b" in addition
expect(mapOf(1 to "a", 2 to "b")) toContainOnly (1 to "a")
}
Expects the subject of this
expectation (a Map) contains only (in any order) for each key-value pair in pairs, a key as defined by that entry's Pair.first with a corresponding value as defined by entry's Pair.second.
Delegates to it toContain o inAny order but only the pairs
Return
an Expect for the subject of this
expectation.
Parameters
Samples
expect(mapOf(1 to "a", 2 to "b")) toContainOnly pairs(1 to "a", 2 to "b")
fails { // because the map contains key 2 with value "b" in addition
expect(mapOf(1 to "a", 2 to "b")) toContainOnly pairs(1 to "a")
}
Expects that the subject of this
expectation (a Map) contains only one entry with a key as defined by keyValue's KeyWithValueCreator.key with a corresponding value which either holds all assertions keyValue's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null
in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
Delegates to it toContain o inAny order but only entry keyValue
Return
an Expect for the subject of this
expectation.
Parameters
The KeyWithValueCreator whose key is expected to be contained within this Map and where the corresponding value holds all assertions the KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null
in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
-- use the function keyValue(x) { ... }
to create a KeyWithValueCreator.
Samples
expect(mapOf(1 to "a")) toContainOnly keyValue(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "a"
}
fails { // fails because the map contains key 2 with value "b" in addition
expect(
mapOf(1 to "a", 2 to "b")
) toContainOnly keyValue(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "a"
}
}
Expects that the subject of this
expectation (a Map) contains only (in any order) for each KeyWithValueCreator in keyValues, a key as defined by KeyWithValueCreator.key with a corresponding value which either holds all assertions KeyWithValueCreator's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null
in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null
Delegates to it toContain o inAny order but only the keyValues
Return
an Expect for the subject of this
expectation.
Parameters
The KeyWithValueCreators -- use the function keyValues(keyValue(key1) { ... }, keyValue(key2) { ... }, ...)
to create a KeyValues.
Samples
expect(mapOf(1 to "a", 2 to "b")) toContainOnly keyValues(
keyValue(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "a"
},
keyValue(2) { // subject inside this expectation-group is of type String (actually "b")
this toEqual "b"
}
)
fails {
expect(mapOf(1 to "a", 2 to "b")) toContainOnly keyValues(
keyValue(1) { // subject inside this expectation-group is of type String (actually "a")
this toEqual "a"
}
)
}