errorCode

fun <T : SQLException> Expect<T>.errorCode(assertionCreator: Expect<Int>.() -> Unit): Expect<T>(source)

Expects that the result of calling getErrorCode() on 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

1.3.0

Samples

val exception = SQLException("Test exception", "42000", 1001)

expect(exception)
    .sqlState                      // subject is now of type String
    .toEqual("42000")

fails {
    expect(exception)
        .sqlState                  // subject is now of type String
        .toEqual("00000")          // fails
        .toContain("42")           // not evaluated/reported because `toEqual` already fails
    //                                use `.sqlState { ... }` if you want all assertions evaluated
}

Creates an Expect for the result of calling getErrorCode() on the subject of this expectation, so that further fluent calls are assertions about it.

Return

The newly created Expect for the extracted feature.

Since

1.3.0

Samples

val exception = SQLException("Test exception", "42000", 1001)

expect(exception)
    .errorCode                     // subject is now of type Int
    .toEqual(1001)

fails {
    expect(exception)
        .errorCode                 // subject is now of type Int
        .toEqual(9999)             // fails
        .toBeGreaterThan(1000)     // not evaluated/reported because `toEqual` already fails
    //                                `.errorCode { ... }` if you want all assertions evaluated
}