cause

Expects that the property Throwable.cause of the subject is a ExpectedThrowableT or a subtype thereof, creates an Expect of the ExpectedThrowableT type for it and returns it.

Return

The newly created Expect for the property Throwable.cause of the subject of this expectation.

Since

0.10.0

Samples

expect(IllegalStateException(IndexOutOfBoundsException("abc")))
    .cause<IndexOutOfBoundsException>() // subject is now of type IndexOutOfBoundsException
    .messageToContain("b")

fails {
    expect(IllegalStateException(IndexOutOfBoundsException("abc")))
        .cause<IllegalStateException>() // fails
        .messageToContain("d")          // not evaluated/reported because `cause` already fails
    //                                     use `.cause<...> { ... }` if you want that all assertions are evaluated

}

Expects that the property Throwable.cause of the subject is a ExpectedThrowableT or a subtype thereof and holds all assertions the given assertionCreator creates for it.

Notice, in contrast to other expectation functions which expect an assertionCreator, this function returns not Expect of the initial type, which was some type T , but an Expect of the specified type ExpectedThrowableT.

Return

an Expect for the subject of this expectation.

Since

0.10.0

Samples

expect(IllegalStateException(IndexOutOfBoundsException("abc"))).cause<IndexOutOfBoundsException> { // subject is now of type IndexOutOfBoundsException
    messageToContain("b")
}

fails { // because wrong type expected (IllegalStateException instead of IndexOutOfBoundsException), but since we use an expectation-group...
    expect(IllegalStateException(IndexOutOfBoundsException("abc"))).cause<IllegalStateException> {
        messageToContain("b") // ... reporting mentions that subject's message was expected `to contain: "b"`
    }
}

fails {
    // because you forgot to define an expectation in the expectation-group block
    // use `.cause<...>()` if this is all you expect
    expect(IllegalStateException(IndexOutOfBoundsException("abc"))).cause<IllegalStateException> { }
}