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

first

val <K, T : Pair<K, *>> Expect<T>.first: Expect<K>

Creates an Expect for the property Pair.first of the subject of the assertion, so that further fluent calls are assertions about it.

val pair = 1 to "one"

expect(pair)
    .first           // subject is now of type Int (actually 1)
    .isLessThan(2)   // subject is still of type Int (still 1)
    .isGreaterThan(0)

fails {
    expect(pair)
        .first
        .isGreaterThan(2) // fails
        .isLessThan(0)    // not reported because `isGreaterThan(2)` already fails
                          // use `first { ... }` if you want that all assertions are evaluated
}.message {
    contains("is greater than: 2")
    containsNot("is less than: 0")
}

Return
The newly created Expect for the extracted feature.

fun <K, V, T : Pair<K, V>> Expect<T>.first(assertionCreator: Expect<K>.() -> Unit): Expect<T>

Expects that the property Pair.first of the subject of the assertion holds all assertions the given assertionCreator creates for it and returns an Expect for the current subject of the assertion.

val pair = 1 to "one"

expect(pair)
    .first { // subject inside this block is of type Int (actually 1)
        isLessThan(2)
    } // subject here is back to type Pair<Int, String>
    .first {
        isGreaterThan(0)
    }

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

    expect(pair)
        .first {
            isGreaterThan(2) // fails
            isLessThan(0)    // still evaluated even though `isGreaterThan(2)` already fails
                             // use `.first.` if you want a fail fast behaviour
        }
}.messageContains(
    "is greater than: 2",
    "is less than: 0"
)

Exceptions

AssertionError - Might throw an AssertionError if the assertion made is not correct.

Return
An Expect for the current subject of the assertion.