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

size

val <T : Collection<*>> Expect<T>.size: Expect<Int>

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

expect(listOf(1, 2, 3))
    .size             // subject is now of type Int (actually 3)
    .isGreaterThan(1) // subject is still of type Int (still 1)
    .isLessThan(4)

fails {
    expect(listOf(1, 2, 3))
        .size
        .isLessThan(1)    // fails
        .isGreaterThan(4) // not reported because `isLessThan(1)` already fails
                          // use `size { ... }` if you want that all assertions are evaluated
}.message {
    contains("is less than: 1")
    containsNot("is greater than: 4")
}

Return
The newly created Expect for the extracted feature.

fun <E, T : Collection<E>> Expect<T>.size(assertionCreator: Expect<Int>.() -> Unit): Expect<T>

Expects that the property Collection.size 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.

expect(listOf(1, 2, 3))
    .size { // subject inside this block is of type Int (actually 3)
        isGreaterThan(1)
    } // subject here is back to type List<Int, String>
    .size {
        isLessThan(4)
    }

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(listOf(1, 2, 3))
        .size {
            isLessThan(1)    // fails
            isGreaterThan(4) // still evaluated even though `isLessThan(1)` already fails,
                             // use `.size.` if you want a fail fast behaviour
        }
}.messageContains(
    "is less than: 1",
    "is greater than: 4"
)

Exceptions

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

Return
An Expect for the current subject of the assertion.