asLocalDateTime
Turns Expect<Date>
into Expect<LocalDateTime>
.
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)
.asLocalDateTime() // subject is now of type LocalDateTime
.toEqual(LocalDateTime.parse("1995-07-17T00:00:00"))
fails {
expect(date)
.asLocalDateTime() // subject is now of type LocalDateTime
.toBeAfter(LocalDateTime.parse("2025-07-17T00:00:00")) // fails
.toBeBefore(LocalDateTime.parse("1996-07-17T00:00:00")) // not evaluated/reported because `toBeAfter` already fails
// use `.asLocalDateTime { ... }` if you want all assertions evaluated
}
fun <T : Date> Expect<T>.asLocalDateTime(assertionCreator: Expect<LocalDateTime>.() -> 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).asLocalDateTime { // subject within this expectation-group is of type LocalDateTime
toBeAfterOrTheSamePointInTimeAs(LocalDateTime.parse("1994-07-17T00:00:00"))
toBeBeforeOrTheSamePointInTimeAs(LocalDateTime.parse("1996-07-17T00:00:00"))
} // 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).asLocalDateTime {
toBeAfter(LocalDateTime.parse("2025-07-17T00:00:00")) // fails
toBeBefore(LocalDateTime.parse("1994-07-17T00:00:00")) // still evaluated even though `toBeAfter` already fails
// use `.asLocalDateTime().` if you want a fail fast behaviour
}
}