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

toContainExactly

fun <E, T : Iterable<E>> Expect<T>.toContainExactly(expected: E, vararg otherExpected: E, report: InOrderOnlyReportingOptions.() -> Unit = {}): Expect<T> (source)

Expects that the subject of this expectation (an Iterable) contains only the expected value and the otherExpected values (if given) in the defined order.

It is a shortcut for toContain.inOrder.only.values(expected, *otherExpected, report = { ... })

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

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

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

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

Parameters

expected - The first expected value.

otherExpected - The other expected values in the given order.

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

Return
an Expect for the subject of this expectation.

Since
0.17.0

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.inOrder.only.entry(assertionCreatorOrNull)

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

expect(listOf(null)).toContainExactly(null)

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

fails {
    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

fun <E : Any, T : Iterable<E?>> Expect<T>.toContainExactly(assertionCreatorOrNull: (Expect<E>.() -> Unit)?, vararg otherAssertionCreatorsOrNulls: (Expect<E>.() -> Unit)?, report: InOrderOnlyReportingOptions.() -> Unit = {}): Expect<T> (source)

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

It is a shortcut for toContain.inOrder.only.entries(assertionCreatorOrNull, *otherAssertionCreatorsOrNulls)

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

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

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

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.

Return
an Expect for the subject of this expectation.

Since
0.17.0