entry
Helper function to create an Entry based on the given assertionCreatorOrNull.
Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain an entry which either holds all assertions assertionCreatorOrNull creates or needs to be null in case assertionCreatorOrNull is defined as null.
Delegates to the entries(assertionCreatorOrNull)
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
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("A", "B")) toContain o inAny order exactly 1 entry {
it toEqual "A"
}
expect(listOf("A", null, null)) toContain o inAny order exactly 2 entry null // null is identified
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 entry {
it toEqual "A"
}
expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 entry {
it toEqual "A"
}
fails { // because the count of "A" is not 2
expect(listOf("A", "B")) toContain o inAny order exactly 2 entry {
it toEqual "A"
}
}
fails { // because all elements are not null
expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 entry null
}
fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "A", "B")) toContain o inAny order exactly 1 entry {
/* do nothing */
}
}
fails { // because the count of "A" is less than 3
expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 entry {
it toEqual "A"
}
}
fails { // because the count of "B" is more than 2
expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 entry {
it toEqual "B"
}
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only one entry which holds all assertions created by the given assertionCreatorOrNull or is null in case assertionCreatorOrNull is defined as null.
Delegates to the entries(assertionCreatorOrNull)
Return
an Expect for the subject of this expectation.
Parameters
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("A")) toContain o inAny order but only entry {
toEqual("A")
}
expect(listOf(null)) toContain o inAny order but only entry(null)
fails { // because the List does not contain "A"
expect(listOf("B")) toContain o inAny order but only entry {
toEqual("A")
}
}
fails { // because the List does not contain null
expect(listOf("A")) toContain o inAny order but only entry(null)
}
fails { // because the List contains multiple elements
expect(listOf("A", "A")) toContain o inAny order but only entry {
toEqual("A")
}
}
fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "C")) toContain o inAny order but only entry {
/* do nothing */
}
}Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only one entry which holds all assertions created by the given assertionCreatorOrNull or is null in case assertionCreatorOrNull is defined as null.
Delegates to the entries(assertionCreatorOrNull).
Return
an Expect for the subject of this expectation.
Since
0.14.0 -- API existed for Iterable but not for IterableLike.
Parameters
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("A")) toContain o inGiven order and only entry {
it toEqual "A"
}
expect(listOf(null)) toContain o inGiven order and only entry null
fails { // because the List does not contain "A"
expect(listOf("B")) toContain o inGiven order and only entry {
it toEqual "A"
}
}
fails { // because the List does not contain null
expect(listOf("A")) toContain o inGiven order and only entry null
}
fails { // because the List contains multiple elements
expect(listOf("A", "A")) toContain o inGiven order and only entry {
it toEqual "A"
}
}
fails { // because assertionCreatorOrNull is non-null and has no expectation
expect(listOf("A", "B", "C")) toContain o inGiven order and only entry {
/* do nothing */
}
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain the given keyValuePair.
Delegates to the pairs(keyValuePair).
Return
an Expect for the subject of this expectation
Since
0.15.0
Samples
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order entry (2 to "b")
fails { // because the value "b" of key 2 (which exists in the subject) is not equal to "c"
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order entry (2 to "c")
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain an entry with a key as defined by keyValue's KeyWithValueCreator.key and a corresponding value which either holds all assertions keyValue's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null.
Delegates to the keyValues(keyValue).
Return
an Expect for the subject of this expectation
Since
0.15.0
Parameters
The KeyWithValueCreator whose key is expected to be contained within this MapLike and where the corresponding value holds all assertions the KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null -- use the function keyValue(x) { ... } to create a KeyWithValueCreator.
Samples
expect(mapOf(1 to "apple", 2 to "banana")) toContain o inAny order entry (
keyValue(2) { this 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 o inAny order entry (
keyValue(1) { this toStartWith "b" }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain exactly one entry where key and value have to equal the given keyValuePair.
Delegates to the pairs(keyValuePair).
Return
an Expect for the subject of this expectation.
Since
0.15.0
Samples
expect(mapOf(1 to "a")) toContain o inAny order but only entry (1 to "a")
fails { // because subject has additional entries
expect(mapOf(1 to "a", 2 to "b")) toContain o inAny order but only entry (2 to "c")
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain exactly one entry with a key as defined by keyValue's KeyWithValueCreator.key and a corresponding value which either holds all assertions keyValue's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null.
Delegates to the keyValues(keyValue).
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
The KeyWithValueCreator whose key is expected to be contained within this MapLike and where the corresponding value holds all assertions the KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null -- use the function keyValue(x) { ... } to create a KeyWithValueCreator.
Samples
expect(mapOf(1 to "apple")) toContain o inAny order but only entry(
keyValue(1) { this toStartWith "a" }
)
fails { // because subject has additional entries
expect(mapOf(1 to "apple", 2 to "banana")) toContain o inAny order but only entry(
keyValue(1) { this toStartWith "a" }
)
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain exactly one entry where key and value have to equal the given keyValuePair.
Delegates to the pairs(keyValuePair).
Return
an Expect for the subject of this expectation.
Since
0.15.0
Samples
expect(mapOf(1 to "a")) toContain o inGiven order and only entry (1 to "a")
fails { // because the entry 1="a" (which exists in the subject) is not the only entry
expect(mapOf(1 to "a", 2 to "b")) toContain o inGiven order and only entry (1 to "a")
}Finishes the specification of the sophisticated to contain expectation where the subject (a MapLike) needs to contain exactly one entry with a key as defined by keyValue's KeyWithValueCreator.key and a corresponding value which either holds all assertions keyValue's KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null.
Delegates to the entries(keyValue).
Return
an Expect for the subject of this expectation.
Since
0.15.0
Parameters
The KeyWithValueCreator whose key is expected to be contained within this MapLike and where the corresponding value holds all assertions the KeyWithValueCreator.valueAssertionCreatorOrNull creates or needs to be null in case KeyWithValueCreator.valueAssertionCreatorOrNull is defined as null -- use the function keyValue(x) { ... } to create a KeyWithValueCreator.
Samples
expect(mapOf(1 to "apple")) toContain o inGiven order and only entry(
keyValue(1) { this toStartWith "a" }
)
fails { // because the entry 2="b" (which exists in the subject) is not the only entry
expect(mapOf(1 to "apple", 2 to "banana")) toContain o inGiven order and only entry(
keyValue(2) { this toStartWith "b" }
)
}