doc / ch.tutteli.atrium.api.infix.en_GB / year

year

val Expect<LocalDate>.year: Expect<Int> (source)

Creates an Expect for the property LocalDate.year of the subject of this expectation, so that further fluent calls are assertions about it.

expect(LocalDate.of(2021, Month.OCTOBER, 9))
    .year toEqual 2021
//    | subject is now of type Int (actually 2021)

fails {
    expect(LocalDate.of(2021, Month.OCTOBER, 9))
        .year toEqual 2022 toBeLessThan 2000
    //    |     |            | not reported because notToEqual already fails
    //    |     |            | use `year { ... }` if you want that all expectations are evaluated
    //    |     | fails
    //    | subject is now of type Int (actually 2021)
}

Return
The newly created Expect for the extracted feature.

Since
0.12.0

val Expect<LocalDateTime>.year: Expect<Int> (source)

Creates an Expect for the property LocalDateTime.year[LocalDateTime.getYear of the subject of this expectation, so that further fluent calls are assertions about it.

expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56))
    .year toEqual 2021
//    | subject is now of type Int (actually 2021)

fails {
    expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56))
        .year toEqual 2022 toBeLessThan 2000
    //    |     |            | not reported because notToEqual already fails
    //    |     |            | use `year { ... }` if you want that all expectations are evaluated
    //    |     | fails
    //    | subject is now of type Int (actually 2021)
}

Return
The newly created Expect for the extracted feature.

Since
0.12.0

val Expect<ZonedDateTime>.year: Expect<Int> (source)

Creates an Expect for the property ZonedDateTime.year of the subject of this expectation, so that further fluent calls are assertions about it.

expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
    .year toEqual 2021
//    | subject is now of type Int (actually 2021)

fails {
    expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
        .year toEqual 2022 toBeLessThan 2000
    //    |     |            | not reported because notToEqual already fails
    //    |     |            | use `year { ... }` if you want that all expectations are evaluated
    //    |     | fails
    //    | subject is now of type Int (actually 2021)
}

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix fun Expect<LocalDate>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDate> (source)

Expects that the property LocalDate.yearof 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.

expect(LocalDate.of(2021, Month.OCTOBER, 9)) year {
    // subject inside this block is of type Int (actually 2021)
    it toEqual 2021
    it toBeGreaterThan 2020
} // subject here is back to type LocalDate


fails {
    expect(LocalDate.of(2021, Month.OCTOBER, 9)) year {
        // subject inside this block is of type Int (actually 2021)
        it notToEqual 2021
        it toBeGreaterThan 2022
        it toBeLessThan 2020
    } // subject here is back to type LocalDate
}

Return
an Expect for the subject of this expectation.

Since
0.12.0

infix fun Expect<LocalDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> (source)

Expects that the property LocalDateTime.year of 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.

expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) year {
    // subject inside this block is of type Int (actually 2021)
    it toEqual 2021
    it toBeGreaterThan 2020
} // subject here is back to type LocalDateTime

fails {
    expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) year {
        // subject inside this block is of type Int (actually 2021)
        it notToEqual 2021       // fails
        it toBeGreaterThan 2022  // not evaluated/reported because notToEqual already fails
        //                          use `.year.` if you want a fail fast behaviour
    } // subject here is back to type LocalDateTime
}

Return
an Expect for the subject of this expectation.

Since
0.12.0

infix fun Expect<ZonedDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<ZonedDateTime> (source)

Expects that the property ZonedDateTime.year of 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.

expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) year {
    // subject inside this block is of type Int (actually 2021)
    it toEqual 2021
    it toBeGreaterThan 2020
} // subject here is back to type ZonedDateTime

fails {
    expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) year {
        // subject inside this block is of type Int (actually 2021)
        it notToEqual 2021       // fails
        it toBeGreaterThan 2022  // not evaluated/reported because notToEqual already fails
        //                          use `.year.` if you want a fail fast behaviour
    } // subject here is back to type ZonedDateTime
}

Return
an Expect for the subject of this expectation.

Since
0.12.0