From 4602f92d10652cd87c59e26d66b34840f228b0c6 Mon Sep 17 00:00:00 2001 From: Ilja Korneckis Date: Fri, 22 Oct 2021 10:33:27 +0200 Subject: [PATCH] Add samples for infix api zonedDateTimeAssertions (#1020) --- .../infix/en_GB/zonedDateTimeAssertions.kt | 16 ++ .../ZonedDateTimeExpectationSamples.kt | 145 ++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/ZonedDateTimeExpectationSamples.kt diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/zonedDateTimeAssertions.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/zonedDateTimeAssertions.kt index 17cfd9071d..3ad8f451a2 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/zonedDateTimeAssertions.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/zonedDateTimeAssertions.kt @@ -17,6 +17,8 @@ import java.time.ZonedDateTime * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.yearFeature + * * @since 0.12.0 */ val Expect.year: Expect @@ -29,6 +31,8 @@ val Expect.year: Expect * * @return an [Expect] for the subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.year + * * @since 0.12.0 */ infix fun Expect.year(assertionCreator: Expect.() -> Unit): Expect = @@ -40,6 +44,8 @@ infix fun Expect.year(assertionCreator: Expect.() -> Unit): * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.monthFeature + * * @since 0.12.0 */ val Expect.month: Expect @@ -52,6 +58,8 @@ val Expect.month: Expect * * @return an [Expect] for the subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.month + * * @since 0.12.0 */ infix fun Expect.month(assertionCreator: Expect.() -> Unit): Expect = @@ -63,6 +71,8 @@ infix fun Expect.month(assertionCreator: Expect.() -> Unit): * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayOfWeekFeature + * * @since 0.12.0 */ val Expect.dayOfWeek: Expect @@ -75,6 +85,8 @@ val Expect.dayOfWeek: Expect * * @return an [Expect] for the subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayOfWeek + * * @since 0.12.0 */ infix fun Expect.dayOfWeek(assertionCreator: Expect.() -> Unit): Expect = @@ -86,6 +98,8 @@ infix fun Expect.dayOfWeek(assertionCreator: Expect.() * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayFeature + * * @since 0.12.0 */ val Expect.day: Expect @@ -98,6 +112,8 @@ val Expect.day: Expect * * @return an [Expect] for the subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.day + * * @since 0.12.0 */ infix fun Expect.day(assertionCreator: Expect.() -> Unit): Expect = diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/ZonedDateTimeExpectationSamples.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/ZonedDateTimeExpectationSamples.kt new file mode 100644 index 0000000000..96225ed396 --- /dev/null +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/ZonedDateTimeExpectationSamples.kt @@ -0,0 +1,145 @@ +package ch.tutteli.atrium.api.infix.en_GB.samples + +import ch.tutteli.atrium.api.infix.en_GB.* +import ch.tutteli.atrium.api.verbs.internal.expect +import java.time.* +import kotlin.test.Test + +class ZonedDateTimeExpectationSamples { + + @Test + fun yearFeature() { + 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) + } + } + + @Test + fun year() { + 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 reported because notToEqual already fails + // use `.year.` if you want a fail fast behaviour + } // subject here is back to type ZonedDateTime + } + } + + @Test + fun monthFeature() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .month toEqual Month.OCTOBER.value + // | subject is now of type Int (actually Month.OCTOBER.value i.e. 10) + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .month toBeLessThan 9 toBeGreaterThan 11 + // | | | not reported because toBeLessThan already fails + // | | | use `month { ... }` if you want that all expectations are evaluated + // | | fails + // | subject is now of type Int (actually Month.OCTOBER.value i.e. 10) + } + } + + @Test + fun month() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) month { + // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10) + it toEqual Month.OCTOBER.value + it notToEqual Month.SEPTEMBER.value + } // subject here is back to type ZonedDateTime + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) month { + // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10) + it toBeLessThan 9 // fails + it toBeGreaterThan 11 // still evaluated even though toBeLessThan already fails + // use `.month` if you want a fail fast behaviour + } // subject here is back to type ZonedDateTime + } + } + + @Test + fun dayOfWeekFeature() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .dayOfWeek toEqual DayOfWeek.SATURDAY + // | subject is now of type DayOfWeek (actually SATURDAY) + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .dayOfWeek toEqual DayOfWeek.MONDAY + // | | | not reported because toEqual already fails + // | | | use `dayOfWeek { ... }` if you want that all expectations are evaluated + // | | fails + // | subject is now of type DayOfWeek (actually SATURDAY) + } + } + + @Test + fun dayOfWeek() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) dayOfWeek { + // subject inside this block is of type DayOfWeek (actually SATURDAY) + it toEqual DayOfWeek.SATURDAY + it notToEqual DayOfWeek.SUNDAY + } // subject here is back to type ZonedDateTime + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) dayOfWeek { + // subject inside this block is of type DayOfWeek (actually SATURDAY) + it toEqual DayOfWeek.MONDAY // fails + it notToEqual DayOfWeek.SATURDAY // still evaluated even though toEqual already fails + // use `.dayOfWeek.` if you want a fail fast behaviour + } // subject here is back to type ZonedDateTime + } + } + + @Test + fun dayFeature() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .day toEqual 9 + // | subject is now of type Int (actually 9) + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) + .day toEqual 5 toBeGreaterThan 10 + // | | | not reported because toEqual already fails + // | | | use `day { ... }` if you want that all expectations are evaluated + // | | fails + // | subject is now of type Int (actually 9) + } + } + + @Test + fun day() { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) day { + // subject inside this block is of type Int (actually 9) + it toEqual 9 + it toBeGreaterThan 5 + } // subject here is back to type ZonedDateTime + + fails { + expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) day { + // subject inside this block is of type Int (actually 9) + it toEqual 5 // fails + it toBeLessThan 7 // still evaluated even though toEqual already fails + // use `.day` if you want a fail fast behaviour + } // subject here is back to type ZonedDateTime + } + } +}