asLocalDate

Turns Expect<Date> into Expect<LocalDate>.

The transformation as such is not reflected in reporting.

Return

The newly created Expect for the transformed subject.

Since

1.0.0

Samples

val date = formatter.parse("1995-07-17")

expect(date)
    .asLocalDate() // subject is now of type LocalDate
    .toEqual(LocalDate.parse("1995-07-17"))

fails {
    expect(date)
        .asLocalDate()                              // subject is now of type LocalDate
        .toBeAfter(LocalDate.parse("2025-07-17"))   // fails
        .toBeBefore(LocalDate.parse("1996-07-17"))  // not evaluated/reported because `toBeAfter` already fails
    //                                                 use `.asLocalDate { ... }` if you want all assertions evaluated
}

fun <T : Date> Expect<T>.asLocalDate(assertionCreator: Expect<LocalDate>.() -> Unit): Expect<T>(source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject asDate.

The transformation as such is not reflected in reporting.

Return

an Expect for the subject of this expectation.

Since

1.0.0

Samples

val date = formatter.parse("1995-07-17")

expect(date).asLocalDate { // subject within this expectation-group is of type LocalDate
    toBeAfterOrTheSamePointInTimeAs(LocalDate.parse("1994-07-17"))
    toBeBeforeOrTheSamePointInTimeAs(LocalDate.parse("1996-07-17"))
} // subject here is back to type java.util.Date

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(date).asLocalDate {
        toBeAfter(LocalDate.parse("2025-07-17"))   // fails
        toBeBefore(LocalDate.parse("1994-07-17"))  // still evaluated even though `toBeAfter` already fails
        //                                            use `.asLocalDate().` if you want a fail fast behaviour
    }
}