key

fun <K, V, T : Map.Entry<K, V>> Expect<T>.key(assertionCreator: Expect<K>.() -> Unit): Expect<T>(source)

Expects that the property Map.Entry.key 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

val entry = mapOf(1 to "a").entries.first()

expect(entry).key {  // subject inside this expectation-group is of type Int (actually 1)
    toEqual(1)
} // subject here is back to type Map.Entry<Int, String>

fails {
    expect(entry).key {  // subject inside this expectation-group is of type Int (actually 1)
        toEqual(2)       // fails
        toBeLessThan(0)  // still evaluated even though `toEqual` already fails,
        //                  use `.key.` if you want a fail fast behaviour
    }
}

val <K, T : Map.Entry<K, *>> Expect<T>.key: Expect<K>(source)

Creates an Expect for the property Map.Entry.key 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

val entry = mapOf(1 to "a").entries.first()

expect(entry)
    .key          // subject here is of type Int (actually 1)
    .toEqual(1)

fails {
    expect(entry)
        .key             // subject here is of type Int (actually 1)
        .toEqual(2)      // fails
        .toBeLessThan(0) // not evaluated/reported because `toEqual` already fails
    //                      use `.key { ... }` if you want that all assertions are evaluated
}