doc / ch.tutteli.atrium.api.fluent.en_GB / toContainOnly

toContainOnly

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

Expects that the subject of this expectation (a Map) contains only (in any order) a key as defined by keyValuePair's Pair.first with a corresponding value as defined by keyValuePair's Pair.second -- optionally the same assertions are created for the otherPairs.

Delegates to toContain.inAnyOrder.only.entries(keyValuePair, *otherPairs)

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

Return
an Expect for the subject of this expectation.

Since
0.17.0

inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.toContainOnly(keyValue: KeyValue<K, V>, vararg otherKeyValues: KeyValue<K, V>): Expect<T> (source)

Expects that the subject of this expectation (a Map) contains only (in any order) a key as defined by keyValue's KeyValue.key with a corresponding value which either holds all assertions keyValue's KeyValue.valueAssertionCreatorOrNull creates or needs to be null in case KeyValue.valueAssertionCreatorOrNull is defined as null -- optionally the same assertions are created for the otherKeyValues.

Delegates to toContain.inAnyOrder.only.entries(keyValue, *otherKeyValues)

expect(mapOf(1 to "a"))
    .toContainOnly(KeyValue(1) { // subject inside this block is of type String (actually "a")
        toEqual("a")
    })

fails {
    expect(mapOf(1 to "a", 2 to "b"))
        .toContainOnly(KeyValue(1) {  // subject inside this block is of type String (actually "a")
            toEqual("a")
        })                            // fails because the map contains key 2 with value "b" in addition
}

Return
an Expect for the subject of this expectation.

Since
0.17.0