doc / ch.tutteli.atrium.api.infix.en_GB / toContainExactly

toContainExactly

infix fun <E, T : Iterable<E>> Expect<T>.toContainExactly(expected: E): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only the expected value.

It is a shortcut for toContain o inGiven order and only value expected

expect(listOf("A")) toContainExactly "A"

fails {
    expect(listOf("A")) toContainExactly "D"
}

Return
an Expect for the subject of this expectation.

Since
0.17.0

infix fun <E, T : Iterable<E>> Expect<T>.toContainExactly(values: Values<E>): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only the expected values in the defined order.

It is a shortcut for toContain o inGiven order and only the values(...)

expect(listOf(1, 2, 2, 4)) toContainExactly values(1, 2, 2, 4)

fails {
    expect(listOf("A", "B")) toContainExactly values("A", "B", "C")
}

fails {
    expect(listOf("A", "B")) toContainExactly values("B", "A")
}

fails {
    expect(listOf("A", "B")) toContainExactly values(
        "C",
        "B",
        // optional
        reportOptionsInOrderOnly = { // allows configuring reporting, e.g.
            showOnlyFailing() // would not show the successful `B`
            showOnlyFailingIfMoreExpectedElementsThan(10)
        }
    )
}

Parameters

values - The values which are expected to be contained within the Iterable -- use the function values(t, ...) to create a Values.

Return
an Expect for the subject of this expectation.

Since
0.17.0

@JvmName("toContainExactlyValuesWithReportingOption") infix fun <E, T : Iterable<E>> Expect<T>.toContainExactly(values: WithInOrderOnlyReportingOptions<Values<E>>): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only the expected values in the defined order.

It is a shortcut for toContain o inGiven order and only the values(..., reportOptionsInOrderOnly = {... })

expect(listOf(1, 2, 2, 4)) toContainExactly values(1, 2, 2, 4)

fails {
    expect(listOf("A", "B")) toContainExactly values("A", "B", "C")
}

fails {
    expect(listOf("A", "B")) toContainExactly values("B", "A")
}

fails {
    expect(listOf("A", "B")) toContainExactly values(
        "C",
        "B",
        // optional
        reportOptionsInOrderOnly = { // allows configuring reporting, e.g.
            showOnlyFailing() // would not show the successful `B`
            showOnlyFailingIfMoreExpectedElementsThan(10)
        }
    )
}

Parameters

values - The values which are expected to be contained within the IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function values(t, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped Values.

Return
an Expect for the subject of this expectation.

Since
0.18.0

infix fun <E : Any, T : Iterable<E?>> Expect<T>.toContainExactly(assertionCreatorOrNull: (Expect<E>.() -> Unit)?): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only an entry holding the assertions created by assertionCreatorOrNull or only one entry which is null in case assertionCreatorOrNull is defined as null.

It is a shortcut for toContain o inGiven order and only entry assertionCreatorOrNull

expect(listOf(4)) toContainExactly {
    toBeLessThan(5)
    toBeGreaterThan(3)
}

fails {
    expect(listOf("A", "B")) toContainExactly {
        toEqual("A")
    }
}

fails {
    // cast only necessary if Kotlin version < 1.4 due to a bug in Kotlin
    expect(listOf(null, "B")) toContainExactly (null as (Expect<String>.() -> Unit)?)
    // Kotlin > 1.4 would be
    // expect(listOf(null, "B")) toContainExactly null
}

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.

Return
an Expect for the subject of this expectation.

Since
0.17.0

infix fun <E : Any, T : Iterable<E?>> Expect<T>.toContainExactly(entries: Entries<E>): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only an entry holding the assertions created by entries.assertionCreatorOrNull or null in case entries.assertionCreatorOrNull is defined as null and likewise an additional entry for each entries.otherAssertionCreatorsOrNulls (if given) whereas the entries have to appear in the defined order.

It is a shortcut for toContain o inGiven order and only the entries(...)

expect(listOf(3, 5, null)) toContainExactly entries(
    { toEqual(3) },
    { toBeLessThan(11) },
    null
)

fails {
    expect(listOf(3, 5, 7)) toContainExactly entries(
        { toBeGreaterThan(2) },
        { toBeLessThan(11) }
    )
}

fails {
    expect(listOf(3, 5)) toContainExactly entries(
        { toEqual(1) },       // fails
        { toBeLessThan(11) }, // succeeds
        // optional
        reportOptionsInOrderOnly = { // allows configuring reporting, e.g.
            showOnlyFailing() // would not show the successful `toBeLessThan(11)`
            showOnlyFailingIfMoreExpectedElementsThan(10)
        }
    )
}

Parameters

entries - The entries which are expected to be contained within the Iterable -- use the function entries(t, ...) to create an Entries.

Return
an Expect for the subject of this expectation.

Since
0.17.0

@JvmName("toContainExactlyEntriesWithReportingOption") infix fun <E : Any, T : Iterable<E?>> Expect<T>.toContainExactly(entries: WithInOrderOnlyReportingOptions<Entries<E>>): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only an entry holding the assertions created by entries.t.assertionCreatorOrNull or null in case entries.t.assertionCreatorOrNull is defined as null and likewise an additional entry for each entries.t.otherAssertionCreatorsOrNulls (if given) whereas the entries have to appear in the defined order.

It is a shortcut for toContain o inGiven order and only the entries(..., reportOptionsInOrderOnly = { ... })

expect(listOf(3, 5, null)) toContainExactly entries(
    { toEqual(3) },
    { toBeLessThan(11) },
    null
)

fails {
    expect(listOf(3, 5, 7)) toContainExactly entries(
        { toBeGreaterThan(2) },
        { toBeLessThan(11) }
    )
}

fails {
    expect(listOf(3, 5)) toContainExactly entries(
        { toEqual(1) },       // fails
        { toBeLessThan(11) }, // succeeds
        // optional
        reportOptionsInOrderOnly = { // allows configuring reporting, e.g.
            showOnlyFailing() // would not show the successful `toBeLessThan(11)`
            showOnlyFailingIfMoreExpectedElementsThan(10)
        }
    )
}

Parameters

entries - The entries which are expected to be contained within the Iterable plus a lambda configuring the InOrderOnlyReportingOptions -- use the function entries(t, ..., reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped Entries.

Return
an Expect for the subject of this expectation.

Since
0.18.0

@JvmName("toContainExactlyElementsOfWithReportingOption") inline infix fun <reified E, T : Iterable<E>> Expect<T>.toContainExactly(elementsOf: WithInOrderOnlyReportingOptions<IterableLike>): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only an entry holding the assertions created by entries.t.assertionCreatorOrNull or null in case entries.t.assertionCreatorOrNull is defined as null and likewise an additional entry for each entries.t.otherAssertionCreatorsOrNulls (if given) whereas the entries have to appear in the defined order.

It is a shortcut for toContain o inGiven order and only the elementsOf(..., reportOptionsInOrderOnly = { ... })

expect(listOf(3, 5, null)) toContainExactly entries(
    { toEqual(3) },
    { toBeLessThan(11) },
    null
)

fails {
    expect(listOf(3, 5, 7)) toContainExactly entries(
        { toBeGreaterThan(2) },
        { toBeLessThan(11) }
    )
}

fails {
    expect(listOf(3, 5)) toContainExactly entries(
        { toEqual(1) },       // fails
        { toBeLessThan(11) }, // succeeds
        // optional
        reportOptionsInOrderOnly = { // allows configuring reporting, e.g.
            showOnlyFailing() // would not show the successful `toBeLessThan(11)`
            showOnlyFailingIfMoreExpectedElementsThan(10)
        }
    )
}

Parameters

elementsOf - The IterableLike whose elements are expected to be contained within this IterableLike plus a lambda configuring the InOrderOnlyReportingOptions -- use the function elementsOf(iterableLike, reportOptionsInOrderOnly = { ... }) to create a WithInOrderOnlyReportingOptions with a wrapped IterableLike.

Return
an Expect for the subject of this expectation.

Since
0.18.0