size

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

Expects that the property Collection.size 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(listOf(1, 2, 3))
    .size { // subject inside this expectation-group is of type Int (actually 3)
        toBeGreaterThan(1)
    } // subject here is back to type List<Int, String>
    .size {
        toBeLessThan(4)
    }

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

    expect(listOf(1, 2, 3))
        .size {
            toBeLessThan(1)    // fails
            toBeGreaterThan(4) // still evaluated even though `toBeLessThan` already fails,
            //                    use `.size.` if you want a fail fast behaviour
        }
}

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

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

Since

0.15.0

Samples

expect(mapOf(1 to "a", 2 to "b"))
    .size { // subject inside this expectation-group is of type Int (actually 2)
        toEqual(2)
    } // subject here is back to type Map<Int, String>

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", 2 to "b"))
        .size {               // subject inside this expectation-group is of type Int (containing 2)
            toEqual(5)        // fails because 5 is not equal to 2
            toBeLessThan(1)   // fails because 2 is not less than 1
            //                   use `.size.` if you want a fail fast behaviour
        }
}

Creates an Expect for the property Collection.size 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(listOf(1, 2, 3))
    .size               // subject is now of type Int (actually 3)
    .toBeGreaterThan(1) // subject is still of type Int (still 3)
    .toBeLessThan(4)

fails {
    expect(listOf(1, 2, 3))
        .size
        .toBeLessThan(1)    // fails
        .toBeGreaterThan(4) // not evaluated/reported because `toBeLessThan` already fails
    //                         use `.size { ... }` if you want that all assertions are evaluated
}

val <T : Map<*, *>> Expect<T>.size: Expect<Int>(source)

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

Return

The newly created Expect for the extracted feature.

Since

0.15.0

Samples

expect(mapOf(1 to "a", 2 to "b"))
    .size // subject is now of type Int (actually 2)
    .toEqual(2)

fails {
    expect(mapOf(1 to "a", 2 to "b"))
        .size                // subject is now of type Int (actually 2)
        .toBeGreaterThan(5)  // fails because 2 is not greater than 5
        .notToEqual(2)       // not evaluated/reported even though `toBeGreaterThan` already fails
    //                          use `.size { ... }` if you want that all expectations are evaluated
}