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(...)
Note that we might change the signature of this function with the next version which will cause a binary backward compatibility break (see #292 for more information)
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")
}
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
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
Note that we might change the signature of this function with the next version which will cause a binary backward compatibility break (see #292 for more information)
expect(listOf(4)) toContainExactly {
toBeLessThan(5)
toBeGreaterThan(3)
}
fails {
expect(listOf("A", "B")) toContainExactly {
toEqual("A")
}
}
fails {
// cast only necessary if Kotlin verison < 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
}
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(...)
Note that we might change the signature of this function with the next version which will cause a binary backward compatibility break (see #292 for more information)
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) } // this assertion is not checked
)
}
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