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

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

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

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

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(...)

Return

an Expect for the subject of this expectation.

Since

0.17.0

Parameters

values

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

Samples

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

@JvmName(name = "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 = {... })

Return

an Expect for the subject of this expectation.

Since

0.18.0

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.

Samples

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

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

Return

an Expect for the subject of this expectation.

Since

0.17.0

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.

Samples

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

fails {
    expect(listOf("A", "B")) toContainExactly {
        it 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
}

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(...)

Return

an Expect for the subject of this expectation.

Since

0.17.0

Parameters

entries

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

Samples

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

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

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

@JvmName(name = "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 = { ... })

Return

an Expect for the subject of this expectation.

Since

0.18.0

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.

Samples

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

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

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

@JvmName(name = "toContainExactlyElementsOfWithReportingOption")
infix inline fun <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 = { ... })

Return

an Expect for the subject of this expectation.

Since

0.18.0

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.

Samples

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

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

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