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

containsOnly

fun <K, V, T : Map<out K, V>> Expect<T>.containsOnly(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>): Expect<T> (source)
Deprecated: Use toContainOnly; will be removed with 1.0.0 at the latest

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 contains.inAnyOrder.only.entries(keyValuePair, *otherPairs)

expect(mapOf(1 to "a")).containsOnly(1 to "a")

fails {
    expect(mapOf(1 to "a", 1 to "b"))
        .containsOnly(1 to "a") // fails because the map also contains Pair<1,"b">
}

Return
an Expect for the subject of this expectation.

inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.containsOnly(keyValue: KeyValue<K, V>, vararg otherKeyValues: KeyValue<K, V>): Expect<T> (source)
Deprecated: Use toContainOnly; will be removed with 1.0.0 at the latest

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 contains.inAnyOrder.only.entries(keyValue, *otherKeyValues)

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

fails {
    expect(mapOf(1 to "a", 1 to "b"))
        .containsOnly(
            KeyValue(1) {   // subject inside this block is of type String (actually "a")
                toBe("a")   // fails because the map also contains Pair<1,"b">
            }
        )
}

Return
an Expect for the subject of this expectation.