entries

fun <E : Any, T : IterableLike> IterableLikeContains.CheckerStep<out E?, T, InAnyOrderSearchBehaviour>.entries(assertionCreatorOrNull: Expect<E>.() -> Unit?, vararg otherAssertionCreatorsOrNulls: Expect<E>.() -> Unit?): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain an entry for assertionCreatorOrNull as well as for the otherAssertionCreatorsOrNulls where it does not matter in which order they appear -- an entry is contained if it either holds all assertions assertionCreatorOrNull creates or needs to be null in case assertionCreatorOrNull is defined as null.

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

assertionCreatorOrNull

The identification lambda which creates the assertions which the entry we are looking for has to hold; or in other words, the function which defines whether an entry is the one we are looking for or not. In case it is defined as null, then an entry is identified if it is null as well.

otherAssertionCreatorsOrNulls

Additional identification lambdas which each identify (separately) an entry which we are looking for (see assertionCreatorOrNull for more information).


fun <E : Any, T : IterableLike> IterableLikeContains.EntryPointStep<out E?, T, InAnyOrderOnlySearchBehaviour>.entries(assertionCreatorOrNull: Expect<E>.() -> Unit?, vararg otherAssertionCreatorsOrNulls: Expect<E>.() -> Unit?, report: InAnyOrderOnlyReportingOptions.() -> Unit = {}): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only an entry for assertionCreatorOrNull as well as for the otherAssertionCreatorsOrNulls where it does not matter in which order they appear -- an entry is contained if it either holds all assertions assertionCreatorOrNull creates or needs to be null in case assertionCreatorOrNull is defined as null.

Notice, that a first-wins strategy applies which means your assertion creator lambdas -- which kind of serve as identification lambdas -- should be ordered in such a way that the most specific identification lambda appears first, not that a less specific lambda wins. For instance, given a setOf(1, 2) you should not search for entries({ isGreaterThan(0) }, { toEqual(1) }) but for entries({ toEqual(1) }, { isGreaterThan(0) }) otherwise isGreaterThan(0) matches 1 before toEqual(1) would match it. As a consequence toEqual(1) could only match the entry which is left -- in this case 2 -- and of course this would fail.

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

assertionCreatorOrNull

The identification lambda which creates the assertions which the entry we are looking for has to hold; or in other words, the function which defines whether an entry is the one we are looking for or not. In case it is defined as null, then an entry is identified if it is null as well.

otherAssertionCreatorsOrNulls

Additional identification lambdas which each identify (separately) an entry which we are looking for (see assertionCreatorOrNull for more information).

report

The lambda configuring the InAnyOrderOnlyReportingOptions -- it is optional where the default InAnyOrderOnlyReportingOptions apply if not specified. since 0.18.0


fun <E : Any, T : IterableLike> IterableLikeContains.EntryPointStep<out E?, T, InOrderOnlySearchBehaviour>.entries(assertionCreatorOrNull: Expect<E>.() -> Unit?, vararg otherAssertionCreatorsOrNulls: Expect<E>.() -> Unit?, report: InOrderOnlyReportingOptions.() -> Unit = {}): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only an entry for assertionCreatorOrNull as well as for the otherAssertionCreatorsOrNulls in the specified order -- an entry is contained if it either holds all assertions assertionCreatorOrNull creates or needs to be null in case assertionCreatorOrNull is defined as null.

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

assertionCreatorOrNull

The identification lambda which creates the assertions which the entry we are looking for has to hold; or in other words, the function which defines whether an entry is the one we are looking for or not. In case it is defined as null, then an entry is identified if it is null as well.

otherAssertionCreatorsOrNulls

Additional identification lambdas which each identify (separately) an entry which we are looking for (see assertionCreatorOrNull for more information).

report

The lambda configuring the InOrderOnlyReportingOptions -- it is optional where the default InOrderOnlyReportingOptions apply if not specified. since 0.17.0


fun <K, V, T : MapLike> MapLikeContains.EntryPointStep<K, V, T, InAnyOrderSearchBehaviour>.entries(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain the given keyValuePair as well as the otherPairs where it does not matter in which order they appear.

Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1) and keyValuePair is defined as 'a' to 1 and one of the otherPairs is defined as 'a' to 1 as well, then both match, even though they match the same entry.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Samples

expect(mapOf(1 to "a", 2 to "b")).toContain.inAnyOrder.entries(
    2 to "b"
)

fails { // because the value ("b") of key 1 (which exists in the subject) is not "b"
    expect(mapOf(1 to "a", 2 to "b")).toContain.inAnyOrder.entries(1 to "b")
}

inline fun <K, V : Any, T : MapLike> MapLikeContains.EntryPointStep<K, out V?, T, InAnyOrderSearchBehaviour>.entries(keyValue: KeyValue<K, V>, vararg otherKeyValues: KeyValue<K, V>): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain the given keyValue as well as the otherKeyValues where it does not matter in which order they appear -- an entry is contained if it has a key as defined by keyValue's KeyValue.key and 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.

Notice, that it does not search for unique matches. Meaning, if the map is mapOf('a' to 1) and keyValue is defined as Key('a') { isGreaterThan(0) } and one of the otherKeyValues is defined as Key('a') { isLessThan(2) } , then both match, even though they match the same entry.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Samples

expect(mapOf(1 to "apple", 2 to "banana")).toContain.inAnyOrder.entries(
    KeyValue(2) { toStartWith("b") }
)

fails { // because the value ("apple") of key 1 (which exists in the subject) does not start with "b"
    expect(mapOf(1 to "apple", 2 to "banana")).toContain.inAnyOrder.entries(
        KeyValue(1) { toStartWith("b") }
    )
}

fun <K, V, T : MapLike> MapLikeContains.EntryPointStep<K, V, T, InAnyOrderOnlySearchBehaviour>.entries(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given keyValuePair as well as the otherPairs where it does not matter in which order they appear.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Samples

expect(mapOf(1 to "a", 2 to "b")).toContain.inAnyOrder.only.entries(
    2 to "b", 1 to "a"
)

fails { // because subject has additional entries
    expect(mapOf(1 to "a", 2 to "b")).toContain.inAnyOrder.only.entries(1 to "a")
}

inline fun <K, V : Any, T : MapLike> MapLikeContains.EntryPointStep<K, out V?, T, InAnyOrderOnlySearchBehaviour>.entries(keyValue: KeyValue<K, V>, vararg otherKeyValues: KeyValue<K, V>): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given keyValue as well as the otherKeyValues where it does not matter in which order they appear -- an entry is contained if it has a key as defined by keyValue's KeyValue.key and 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.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Samples

expect(mapOf(1 to "apple", 2 to "banana")).toContain.inAnyOrder.only.entries(
    KeyValue(2) { toStartWith("b") },
    KeyValue(1) { toStartWith("a") },
)

fails { // because subject has additional entries
    expect(mapOf(1 to "apple", 2 to "banana")).toContain.inAnyOrder.only.entries(
        KeyValue(1) { toStartWith("a") },
    )
}

fun <K, V, T : MapLike> MapLikeContains.EntryPointStep<K, V, T, InOrderOnlySearchBehaviour>.entries(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>, report: InOrderOnlyReportingOptions.() -> Unit = {}): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given keyValuePair as well as the otherPairs in the specified order.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Parameters

report

The lambda configuring the InOrderOnlyReportingOptions -- it is optional where the default InOrderOnlyReportingOptions apply if not specified. since 0.18.0

Samples

expect(mapOf(1 to "a", 2 to "b")).toContain.inOrder.only.entries(
    1 to "a", 2 to "b"
)

fails { // because the pair entries (which all exist in the subject) do not have the same order
    expect(mapOf(1 to "a", 2 to "b")).toContain.inOrder.only.entries(
        2 to "b",
        1 to "a",
    )
}

inline fun <K, V : Any, T : MapLike> MapLikeContains.EntryPointStep<K, out V?, T, InOrderOnlySearchBehaviour>.entries(keyValue: KeyValue<K, V>, vararg otherKeyValues: KeyValue<K, V>, noinline report: InOrderOnlyReportingOptions.() -> Unit = {}): Expect<T>(source)

Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain only the given keyValue as well as the otherKeyValues in the specified order -- an entry is contained if it has a key as defined by keyValue's KeyValue.key and 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.

Return

an Expect for the subject of this expectation.

Since

0.15.0

Parameters

report

The lambda configuring the InOrderOnlyReportingOptions -- it is optional where the default InOrderOnlyReportingOptions apply if not specified. since 0.18.0

Samples

expect(mapOf(1 to "apple", 2 to "banana")).toContain.inOrder.only.entries(
    KeyValue(1) { toStartWith("a") },
    KeyValue(2) { toStartWith("b") },
)

fails { // because the key-value entries (which all exist in the subject) do not have the same order
    expect(mapOf(1 to "apple", 2 to "banana")).toContain.inOrder.only.entries(
        KeyValue(2) { toStartWith("b") },
        KeyValue(1) { toStartWith("a") },
    )
}