toContainOnly

infix fun <K, V, T : Map<out K, V>> Expect<T>.toContainOnly(keyValuePair: Pair<K, V>): Expect<T>(source)

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")
}

infix fun <K, V, T : Map<out K, V>> Expect<T>.toContainOnly(pairs: Pairs<K, V>): Expect<T>(source)

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

pairs

The key-value Pairs expected to be contained within this Map -- use the function pairs(x to y, ...) to create a Pairs.

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")
}

infix inline fun <K, V : Any, T : Map<out K, V?>> Expect<T>.toContainOnly(keyValue: KeyWithValueCreator<K, V>): Expect<T>(source)

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

keyValue

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

infix inline fun <K, V : Any, T : Map<out K, V?>> Expect<T>.toContainOnly(keyValues: KeyValues<K, V>): Expect<T>(source)

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

keyValues

The KeyWithValueCreators -- use the function keyValues(keyValue(key1) { ... }, keyValue(key2) { ... }, ...) to create a KeyValues.

Samples

expect(mapOf(1 to "a", 2 to "b")) toContainOnly entries(
    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 entries(
        keyValue(1) { // subject inside this expectation-group is of type String (actually "a")
            this toEqual "a"
        }
    )
}