diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/localDateTimeAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/localDateTimeAssertions.kt index 8b502c1d31..b94b6277d7 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/localDateTimeAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/localDateTimeAssertions.kt @@ -17,6 +17,8 @@ import java.time.LocalDateTime * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.yearFeature + * * @since 0.9.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.fluent.en_GB.samples.LocalDateTimeExpectationSamples.year + * * @since 0.9.0 */ fun Expect.year(assertionCreator: Expect.() -> Unit): Expect = @@ -40,6 +44,8 @@ fun Expect.year(assertionCreator: Expect.() -> Unit): Expect * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.monthFeature + * * @since 0.9.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.fluent.en_GB.samples.LocalDateTimeExpectationSamples.month + * * @since 0.9.0 */ fun Expect.month(assertionCreator: Expect.() -> Unit): Expect = @@ -63,6 +71,8 @@ fun Expect.month(assertionCreator: Expect.() -> Unit): Expec * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayOfWeekFeature + * * @since 0.9.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.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayOfWeek + * * @since 0.9.0 */ fun Expect.dayOfWeek(assertionCreator: Expect.() -> Unit): Expect = @@ -86,6 +98,8 @@ fun Expect.dayOfWeek(assertionCreator: Expect.() -> Un * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayFeature + * * @since 0.9.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.fluent.en_GB.samples.LocalDateTimeExpectationSamples.day + * * @since 0.9.0 */ fun Expect.day(assertionCreator: Expect.() -> Unit): Expect = diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/LocalDateTimeExpectationSamples.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/LocalDateTimeExpectationSamples.kt new file mode 100644 index 0000000000..bec80390de --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/LocalDateTimeExpectationSamples.kt @@ -0,0 +1,140 @@ +package ch.tutteli.atrium.api.fluent.en_GB.samples + +import ch.tutteli.atrium.api.fluent.en_GB.* +import ch.tutteli.atrium.api.verbs.internal.expect +import java.time.DayOfWeek +import java.time.LocalDateTime +import java.time.Month +import kotlin.test.Test + +class LocalDateTimeExpectationSamples { + + @Test + fun yearFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .year.toEqual(2021) + // | subject is now of type Int + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .year.notToEqual(2021) + // | subject is now of type Int + } + } + + @Test + fun year() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .year { + // subject inside this block is of type Int (actually 2021) + toEqual(2021) + 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) + notToEqual(2021) + toBeGreaterThan(2022) + toBeLessThan(2020) + } // subject here is back to type LocalDateTime + } + } + + @Test + fun monthFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month.toEqual(Month.OCTOBER.value) + // | subject is now of type Int + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month.toEqual(Month.SEPTEMBER.value) + // | subject is now of type Int + } + } + + @Test + fun month() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month { + // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10) + toEqual(Month.OCTOBER.value) + notToEqual(Month.SEPTEMBER.value) + } // subject here is back to type LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month { + // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10) + toEqual(Month.SEPTEMBER.value) + notToEqual(Month.OCTOBER.value) + } // subject here is back to type LocalDateTime + } + } + + @Test + fun dayOfWeekFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek.toEqual(DayOfWeek.SATURDAY) + // | subject is now of type DayOfWeek + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek.toEqual(DayOfWeek.MONDAY) + // | subject is now of type DayOfWeek + } + } + + @Test + fun dayOfWeek() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek { + // subject inside this block is of type DayOfWeek (actually SATURDAY) + toEqual(DayOfWeek.SATURDAY) + notToEqual(DayOfWeek.SUNDAY) + } // subject here is back to type LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek { + // subject inside this block is of type DayOfWeek (actually SATURDAY) + toEqual(DayOfWeek.MONDAY) + notToEqual(DayOfWeek.SATURDAY) + } // subject here is back to type LocalDateTime + } + } + + @Test + fun dayFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .day.toEqual(9) + // | subject is now of type Int + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .day.toEqual(5) + // | subject is now of type Int + } + } + + @Test + fun day() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .day { + // subject inside this block is of type Int (actually 9) + toEqual(9) + toBeGreaterThan(5) + } // subject here is back to type LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .day { + // subject inside this block is of type Int (actually 9) + toEqual(5) + toBeLessThan(7) + } // subject here is back to type LocalDateTime + } + } +} diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/localDateTimeAssertions.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/localDateTimeAssertions.kt index a060baa33b..29f9c714af 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/localDateTimeAssertions.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/localDateTimeAssertions.kt @@ -17,6 +17,8 @@ import java.time.LocalDateTime * * @return The newly created [Expect] for the extracted feature. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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.LocalDateTimeExpectationSamples.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/LocalDateTimeExpectationSamples.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/LocalDateTimeExpectationSamples.kt new file mode 100644 index 0000000000..e6c803a8a2 --- /dev/null +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/LocalDateTimeExpectationSamples.kt @@ -0,0 +1,129 @@ +package ch.tutteli.atrium.api.infix.en_GB.samples + +import ch.tutteli.atrium.api.infix.en_GB.* +import ch.tutteli.atrium.api.infix.en_GB.workaround.it +import ch.tutteli.atrium.api.verbs.internal.expect +import java.time.DayOfWeek +import java.time.LocalDateTime +import java.time.Month +import kotlin.test.Test + +class LocalDateTimeExpectationSamples { + + @Test + fun yearFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)).year toEqual 2021 + // | subject is now of type Int + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)).year toEqual 2022 + // | subject is now of type Int + } + } + + @Test + fun year() { + 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 + it toBeGreaterThan 2022 + it toBeLessThan 2020 + } // subject here is back to type LocalDateTime + } + } + + @Test + fun monthFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month toEqual Month.OCTOBER.value + // | subject is now of type Int + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .month toEqual Month.SEPTEMBER.value + // | subject is now of type Int + } + } + + @Test + fun month() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) 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 LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) month { + // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10) + it toEqual Month.SEPTEMBER.value + it notToEqual Month.OCTOBER.value + } // subject here is back to type LocalDateTime + } + } + + @Test + fun dayOfWeekFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek toEqual DayOfWeek.SATURDAY + // | subject is now of type DayOfWeek + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) + .dayOfWeek toEqual DayOfWeek.MONDAY + // | subject is now of type DayOfWeek + } + } + + @Test + fun dayOfWeek() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) 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 LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) dayOfWeek { + // subject inside this block is of type DayOfWeek (actually SATURDAY) + it toEqual DayOfWeek.MONDAY + it notToEqual DayOfWeek.SATURDAY + } // subject here is back to type LocalDateTime + } + } + + @Test + fun dayFeature() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)).day toEqual 9 + // | subject is now of type DayOfWeek + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)).day toEqual 5 + // | subject is now of type DayOfWeek + } + } + + @Test + fun day() { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) day { + // subject inside this block is of type Int (actually 9) + it toEqual 9 + it toBeGreaterThan 5 + } // subject here is back to type LocalDateTime + + fails { + expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) day { + // subject inside this block is of type Int (actually 9) + it toEqual 5 + it toBeLessThan 7 + } // subject here is back to type LocalDateTime + } + } +}