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
o toEqual LocalDateTime.parse("1995-07-17T00:00:00")
fails {
expect(date) asLocalDateTime // subject is now of type LocalDateTime
o toBeAfter LocalDateTime.parse("2025-07-17T00:00:00") and // fails
o toBeBefore LocalDateTime.parse("1996-07-17T00:00:00") // not evaluated/reported because `toBeAfter` already fails
// use ` asLocalDateTime { ... }` if you want all expectations evaluated
}
infix 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 as LocalDateTime.
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
it toBeAfterOrTheSamePointInTimeAs LocalDateTime.parse("1994-07-17T00:00:00")
it 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 {
it toBeAfter LocalDateTime.parse("2025-07-17T00:00:00") // fails
it toBeBefore LocalDateTime.parse("1994-07-17T00:00:00") // still evaluated even though `toBeAfter` already fails
// use ` asLocalDateTime o` if you want a fail fast behaviour
}
}