values

Finishes the specification of the sophisticated to contain expectation where the expected value as well as the otherExpected values shall be searched, using a non-disjoint search.

Notice that a runtime check applies which assures that only CharSequence, Number and Char are passed. This function expects CharSequenceOrNumberOrChar (which is a typealias for Any) for your convenience, so that you can mix String and Int for instance.

By non-disjoint is meant that "aa" in "aaaa" is found three times and not only two times. Also notice, that it does not search for unique matches. Meaning, if the input of the search is "a" and expected is defined as "a" and one otherExpected is defined as "a" as well, then both match, even though they match the same sequence in the input of the search. Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.

Meaning you might want to use: toContain.exactly(2).value("a") instead of: toContain.atLeast(1).values("a", "a")

Return

an Expect for the subject of this expectation.

Parameters

expected

The value which is expected to be contained within the input of the search.

otherExpected

Additional values which are expected to be contained within the input of the search.

Throws

Samples

// `values` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)

expect("ABC").toContain.exactly(1).values("A", "B", "C")
expect("AAABC").toContain.atMost(3).values("A", "B", "C")
expect("ABBBCD").toContain.atLeast(1).values("A", "B", "C", "D")

fails {
    expect("AAAAAABBBB").toContain.atMost(3).values("A", "B")
}
fails {
    expect("AAABBBB").toContain.exactly(3).values("A", "B")
}
fails {
    expect("AAAAAABBBB").toContain.atLeast(3).values("A", "B", "C")
}

Finishes the specification of the sophisticated to contain expectation where the expected value as well as the otherExpected values shall be searched (ignoring case), using a non-disjoint search.

Notice that a runtime check applies which assures that only CharSequence, Number and Char are passed. This function expects CharSequenceOrNumberOrChar (which is a typealias for Any) for your convenience, so that you can mix String and Int for instance.

By non-disjoint is meant that "aa" in "aaaa" is found three times and not only two times. Also notice, that it does not search for unique matches. Meaning, if the input of the search is "a" and expected is defined as "a" and one otherExpected is defined as "a" as well, then both match, even though they match the same sequence in the input of the search. Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.

Meaning you might want to use: toContain.ignoringCase.exactly(2).value("a") instead of: toContain.ignoringCase.atLeast(1).values("a", "a")

Return

an Expect for the subject of this expectation.

Parameters

expected

The value which is expected to be contained within the input of the search.

otherExpected

Additional values which are expected to be contained within the input of the search.

Throws

Samples

// `values` is a final step in the CharSequence.toContain expectation-building process and can be used with
// various checkers (see CharSequenceToContainCheckerSamples)

expect("ABc").toContain.ignoringCase.exactly(1).values("A", "b", "C")
expect("AaaBC").toContain.ignoringCase.atMost(3).values("A", "B", "c")
expect("ABBBcD").toContain.ignoringCase.atLeast(1).values("a", "b", "C", "d")

fails {
    expect("AAAAAABBBB").toContain.ignoringCase.atMost(3).values("a", "b")
}
fails {
    expect("AAABBBB").toContain.ignoringCase.exactly(3).values("A", "b")
}
fails {
    expect("AAAAAABBBB").toContain.ignoringCase.atLeast(3).values("a", "b", "C")
}

Finishes the specification of the sophisticated to contain expectation where the expected value as well as the otherExpected values shall be searched (ignoring case), using a non-disjoint search where each need to be contained at least once.

Delegates to atLeast(1).values(expected, otherExpected)

Notice that a runtime check applies which assures that only CharSequence, Number and Char are passed. This function expects CharSequenceOrNumberOrChar (which is a typealias for Any) for your convenience, so that you can mix String and Int for instance.

By non-disjoint is meant that "aa" in "aaaa" is found three times and not only two times. Also notice, that it does not search for unique matches. Meaning, if the input of the search is "a" and expected is defined as "a" and one otherExpected is defined as "a" as well, then both match, even though they match the same sequence in the input of the search.

Return

an Expect for the subject of this expectation.

Parameters

expected

The value which is expected to be contained within the input of the search.

otherExpected

Additional values which are expected to be contained within the input of the search.

Throws

Samples

expect("AbC").toContain.ignoringCase.values("A", "B", "c")

fails {
    expect("aabaabbb").toContain.ignoringCase.values("A", "B", "C")
}

Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain the expected value as well as the otherExpected values where it does not matter in which order they appear.

Notice, that it does not search for unique matches. Meaning, if the iterable is setOf('a', 'b') and expected is defined as 'a' and one otherExpected is defined as 'a' as well, then both match, even though they match the same entry. Use an option such as atLeast, atMost and exactly to control the number of occurrences you expect.

Meaning you might want to use: contains.inAnyOrder.exactly(2).values('a') instead of: contains.inAnyOrder.atLeast(1).values('a', 'a')

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

expected

The object which is expected to be contained within this IterableLike.

otherExpected

Additional objects which are expected to be contained within this IterableLike.


Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected value as well as the otherExpected values where it does not matter in which order.

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

expected

The value which is expected to be contained within the subject (an IterableLike).

otherExpected

Additional values which are expected to be contained within IterableLike.

report

The lambda configuring the InAnyOrderOnlyReportingOptions -- it is optional where the default InAnyOrderOnlyReportingOptions apply if not specified. since 0.18.0


Finishes the specification of the sophisticated to contain expectation where the subject (an IterableLike) needs to contain only the expected value as well as the otherExpected values in the specified order.

Return

an Expect for the subject of this expectation.

Since

0.14.0 -- API existed for Iterable but not for IterableLike.

Parameters

expected

The value which is expected to be contained within the subject (an IterableLike).

otherExpected

Additional values which are expected to be contained within IterableLike.

report

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


fun <K, V, T : Map<out K, V>> Expect<T>.values(assertionCreator: Expect<Collection<V>>.() -> Unit): Expect<T>(source)

Expects that the property Map.keys of the subject of this expectation holds all assertions the given assertionCreator creates for it and returns an Expect for the current subject of this expectation.

Return

an Expect for the subject of this expectation.

Samples

expect(mapOf(1 to "a"))
    .values { // subject inside this expectation-group is of type Collection<String> (containing "a")
        toContain("a")
    }

fails {
    // all expectations are evaluated inside an expectation-group block; for more details:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group

    expect(mapOf(1 to "a"))
        .values { // subject inside this expectation-group is of type Collection<String> (containing <"a">)
            toEqual(setOf("b"))  // fails because "a" is not equal to "b"
            toContain("c")       // still evaluated because we use an expectation-group block
            //                      use `.values.` if you want a fail fast behaviour
        }
}

val <V, T : Map<*, V>> Expect<T>.values: Expect<Collection<V>>(source)

Creates an Expect for the property Map.values of the subject of this expectation, so that further fluent calls are assertions about it.

Return

The newly created Expect for the extracted feature.

Samples

expect(mapOf(1 to "a"))
    .values // subject is now of type Collection<String> (containing "a")
    .toContain("a")

fails {
    expect(mapOf(1 to "a"))
        .values          // subject is now of type Collection<String> (containing "a")
        .toContain("b")  // fails because "a" is not equal to "b"
        .toHaveSize(5)   // not evaluated/reported even though `toContain` already fails
    //                      use `.values { ... }` if you want that all expectations are evaluated
}