From 53de3023e455b42a2b150b84c7e9d4a73dfcca1d Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Fri, 21 May 2021 21:09:48 +0200 Subject: [PATCH] rename chronoLocalDateAssertion functions to new schema in api-fluent --- .../en_GB/chronoLocalDateExpectations.kt | 128 ++++++++++++++++++ .../en_GB/ChronoLocalDateExpectationsSpec.kt | 20 +-- ...ChronoLocalDateAsStringExpectationsSpec.kt | 70 +++++----- .../ChronoLocalDateExpectationsSpec.kt | 96 ++++++------- 4 files changed, 221 insertions(+), 93 deletions(-) create mode 100644 apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/chronoLocalDateExpectations.kt diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/chronoLocalDateExpectations.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/chronoLocalDateExpectations.kt new file mode 100644 index 000000000..43f749458 --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/chronoLocalDateExpectations.kt @@ -0,0 +1,128 @@ +@file:Suppress( + // TODO remove once https://youtrack.jetbrains.com/issue/KT-35343 is fixed + "JAVA_MODULE_DOES_NOT_READ_UNNAMED_MODULE" +) + +package ch.tutteli.atrium.api.fluent.en_GB + +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic.* +import java.time.chrono.ChronoLocalDate + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is before the [expected] [ChronoLocalDate]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeBefore(expected: ChronoLocalDate): Expect = + _logicAppend { isBefore(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is before the [expected] [java.time.LocalDate] given as [String]. + * The [expected] parameter needs to be in the form of **yyyy-mm-dd** or else an exception will be thrown. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeBefore(expected: String): Expect = + _logicAppend { isBefore(expected) } + + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is before or equal the [expected] [ChronoLocalDate]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeBeforeOrTheSamePointInTimeAs(expected: ChronoLocalDate): Expect = + _logicAppend { isBeforeOrEqual(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is before or equal the [expected] [java.time.LocalDate] given as [String]. + * The [expected] parameter needs to be in the form of **yyyy-mm-dd** or else an exception will be thrown. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeBeforeOrTheSamePointInTimeAs(expected: String): Expect = + _logicAppend { isBeforeOrEqual(expected) } + + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is equal to the [expected] [ChronoLocalDate]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeTheSamePointInTimeAs(expected: ChronoLocalDate): Expect = + _logicAppend { isEqual(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is equal to the [expected] [java.time.LocalDate] given as [String]. + * The [expected] parameter needs to be in the form of **yyyy-mm-dd** or else an exception will be thrown. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeTheSamePointInTimeAs(expected: String): Expect = + _logicAppend { isEqual(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is after or equal the [expected] [ChronoLocalDate]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeAfterOrTheSamePointInTimeAs(expected: ChronoLocalDate): Expect = + _logicAppend { isAfterOrEqual(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is after or equal the [expected] [java.time.LocalDate] given as [String]. + * The [expected] parameter needs to be in the form of **yyyy-mm-dd** or else an exception will be thrown. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeAfterOrTheSamePointInTimeAs(expected: String): Expect = + _logicAppend { isAfterOrEqual(expected) } + + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is after the [expected] [ChronoLocalDate]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeAfter(expected: ChronoLocalDate): Expect = + _logicAppend { isAfter(expected) } + +/** + * Expects that the subject of `this` expectation (a [ChronoLocalDate]) + * is after the [expected] [java.time.LocalDate] given as [String]. + * The [expected] parameter needs to be in the form of **yyyy-mm-dd** or else an [Exception] will be thrown. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @since 0.17.0 + */ +fun Expect.toBeAfter(expected: String): Expect = + _logicAppend { isAfter(expected) } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/ChronoLocalDateExpectationsSpec.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/ChronoLocalDateExpectationsSpec.kt index d10feef9a..545c16eba 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/ChronoLocalDateExpectationsSpec.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/ChronoLocalDateExpectationsSpec.kt @@ -13,19 +13,19 @@ class ChronoLocalDateExpectationsSpec : Spek({ include(ChronoLocalDateAsStringSpec) }) { object ChronoLocalDateSpec : ch.tutteli.atrium.specs.integration.ChronoLocalDateExpectationsSpec( - fun1(Expect::isBefore), - fun1(Expect::isBeforeOrEqual), - fun1(Expect::isAfter), - fun1(Expect::isAfterOrEqual), - fun1(Expect::isEqual) + fun1(Expect::toBeBefore), + fun1(Expect::toBeBeforeOrTheSamePointInTimeAs), + fun1(Expect::toBeAfter), + fun1(Expect::toBeAfterOrTheSamePointInTimeAs), + fun1(Expect::toBeTheSamePointInTimeAs) ) object ChronoLocalDateAsStringSpec : ch.tutteli.atrium.specs.integration.ChronoLocalDateAsStringExpectationsSpec( - fun1(Expect::isBefore), - fun1(Expect::isBeforeOrEqual), - fun1(Expect::isAfter), - fun1(Expect::isAfterOrEqual), - fun1(Expect::isEqual) + fun1(Expect::toBeBefore), + fun1(Expect::toBeBeforeOrTheSamePointInTimeAs), + fun1(Expect::toBeAfter), + fun1(Expect::toBeAfterOrTheSamePointInTimeAs), + fun1(Expect::toBeTheSamePointInTimeAs) ) @Suppress("unused", "UNUSED_VALUE") diff --git a/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateAsStringExpectationsSpec.kt b/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateAsStringExpectationsSpec.kt index 1c646ff55..d19a7278b 100644 --- a/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateAsStringExpectationsSpec.kt +++ b/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateAsStringExpectationsSpec.kt @@ -16,58 +16,58 @@ import java.time.format.DateTimeFormatter import java.time.format.DateTimeParseException abstract class ChronoLocalDateAsStringExpectationsSpec( - isBefore: Fun1, - isBeforeOrEqual: Fun1, - isAfter: Fun1, - isAfterOrEqual: Fun1, - isEqual: Fun1, + toBeBefore: Fun1, + toBeBeforeOrTheSamePointInTimeAs: Fun1, + toBeAfter: Fun1, + toBeAfterOrTheSamePointInTimeAs: Fun1, + toBeTheSamePointInTimeAs: Fun1, describePrefix: String = "[Atrium] " ) : Spek({ - fun isBefore( + fun toBeBefore( expect: Expect, expected: ChronoLocalDate ): Expect = - expect.(isBefore.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) + expect.(toBeBefore.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) - fun isBeforeOrEqual( + fun toBeBeforeOrTheSamePointInTimeAs( expect: Expect, expected: ChronoLocalDate ): Expect = - expect.(isBeforeOrEqual.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) + expect.(toBeBeforeOrTheSamePointInTimeAs.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) - fun isAfter( + fun toBeAfter( expect: Expect, expected: ChronoLocalDate ): Expect = - expect.(isAfter.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) + expect.(toBeAfter.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) - fun isAfterOrEqual( + fun toBeAfterOrTheSamePointInTimeAs( expect: Expect, expected: ChronoLocalDate ): Expect = - expect.(isAfterOrEqual.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) + expect.(toBeAfterOrTheSamePointInTimeAs.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) - fun isEqual( + fun toBeTheSamePointInTimeAs( expect: Expect, expected: ChronoLocalDate ): Expect = - expect.(isEqual.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) + expect.(toBeTheSamePointInTimeAs.lambda)(expected.format(DateTimeFormatter.ISO_LOCAL_DATE)) include(object : ChronoLocalDateExpectationsSpec( - fun1(::isBefore), - fun1(::isBeforeOrEqual), - fun1(::isAfter), - fun1(::isAfterOrEqual), - fun1(::isEqual), + fun1(::toBeBefore), + fun1(::toBeBeforeOrTheSamePointInTimeAs), + fun1(::toBeAfter), + fun1(::toBeAfterOrTheSamePointInTimeAs), + fun1(::toBeTheSamePointInTimeAs), describePrefix ) {}) - val isBeforeFun = isBefore.lambda - val isBeforeOrEqualFun = isBeforeOrEqual.lambda - val isAfterFun = isAfter.lambda - val isAfterOrEqualFun = isAfterOrEqual.lambda - val isEqualFun = isEqual.lambda + val toBeBeforeFun = toBeBefore.lambda + val toBeBeforeOrTheSamePointInTimeAsFun = toBeBeforeOrTheSamePointInTimeAs.lambda + val toBeAfterFun = toBeAfter.lambda + val toBeAfterOrTheSamePointInTimeAsFun = toBeAfterOrTheSamePointInTimeAs.lambda + val toBeTheSamePointInTimeAsFun = toBeTheSamePointInTimeAs.lambda val subject = LocalDate.now() as ChronoLocalDate val now = expect(subject) @@ -81,29 +81,29 @@ abstract class ChronoLocalDateAsStringExpectationsSpec( "2020-09-03T07:14" ).forEach { value -> context(value) { - it("${isBefore.name} throws a DateTimeParseException") { + it("${toBeBefore.name} throws a DateTimeParseException") { expect { - now.isBeforeFun(value) + now.toBeBeforeFun(value) }.toThrow { messageToContain("could not be parsed") } } - it("${isBeforeOrEqual.name} throws a DateTimeParseException") { + it("${toBeBeforeOrTheSamePointInTimeAs.name} throws a DateTimeParseException") { expect { - now.isBeforeOrEqualFun(value) + now.toBeBeforeOrTheSamePointInTimeAsFun(value) }.toThrow { messageToContain("could not be parsed") } } - it("${isAfter.name} throws a DateTimeParseException") { + it("${toBeAfter.name} throws a DateTimeParseException") { expect { - now.isAfterFun(value) + now.toBeAfterFun(value) }.toThrow { messageToContain("could not be parsed") } } - it("isAfterOrEqual throws a DateTimeParseException") { + it("toBeAfterOrTheSamePointInTimeAs throws a DateTimeParseException") { expect { - now.isAfterOrEqualFun(value) + now.toBeAfterOrTheSamePointInTimeAsFun(value) }.toThrow { messageToContain("could not be parsed") } } - it("${isEqual.name} throws a DateTimeParseException") { + it("${toBeTheSamePointInTimeAs.name} throws a DateTimeParseException") { expect { - now.isEqualFun(value) + now.toBeTheSamePointInTimeAsFun(value) }.toThrow { messageToContain("could not be parsed") } } } diff --git a/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateExpectationsSpec.kt b/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateExpectationsSpec.kt index bca939b15..bc9d8ac87 100644 --- a/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateExpectationsSpec.kt +++ b/misc/specs/atrium-specs-jvm/src/main/kotlin/ch/tutteli/atrium/specs/integration/ChronoLocalDateExpectationsSpec.kt @@ -12,11 +12,11 @@ import java.time.chrono.ChronoLocalDate import java.time.chrono.JapaneseDate abstract class ChronoLocalDateExpectationsSpec( - isBefore: Fun1, - isBeforeOrEqual: Fun1, - isAfter: Fun1, - isAfterOrEqual: Fun1, - isEqual: Fun1, + toBeBefore: Fun1, + toBeBeforeOrTheSamePointInTimeAs: Fun1, + toBeAfter: Fun1, + toBeAfterOrTheSamePointInTimeAs: Fun1, + toBeTheSamePointInTimeAs: Fun1, describePrefix: String = "[Atrium] " ) : Spek({ @@ -26,18 +26,18 @@ abstract class ChronoLocalDateExpectationsSpec( include(object : SubjectLessSpec( describePrefix, - isBefore.forSubjectLess(december23), - isBeforeOrEqual.forSubjectLess(december23), - isAfter.forSubjectLess(december23), - isAfterOrEqual.forSubjectLess(december23), - isEqual.forSubjectLess(december23) + toBeBefore.forSubjectLess(december23), + toBeBeforeOrTheSamePointInTimeAs.forSubjectLess(december23), + toBeAfter.forSubjectLess(december23), + toBeAfterOrTheSamePointInTimeAs.forSubjectLess(december23), + toBeTheSamePointInTimeAs.forSubjectLess(december23) ) {}) - val isBeforeDescr = DescriptionDateTimeLikeAssertion.IS_BEFORE.getDefault() - val isBeforeOrEqualDescr = DescriptionDateTimeLikeAssertion.IS_BEFORE_OR_EQUAL.getDefault() - val isAfterDescr = DescriptionDateTimeLikeAssertion.IS_AFTER.getDefault() - val isAfterOrEqualDescr = DescriptionDateTimeLikeAssertion.IS_AFTER_OR_EQUAL.getDefault() - val isEqualDescr = DescriptionDateTimeLikeAssertion.SAME_DAY.getDefault() + val toBeBeforeDescr = DescriptionDateTimeLikeAssertion.IS_BEFORE.getDefault() + val toBeBeforeOrTheSamePointInTimeAsDescr = DescriptionDateTimeLikeAssertion.IS_BEFORE_OR_EQUAL.getDefault() + val toBeAfterDescr = DescriptionDateTimeLikeAssertion.IS_AFTER.getDefault() + val toBeAfterOrTheSamePointInTimeAsDescr = DescriptionDateTimeLikeAssertion.IS_AFTER_OR_EQUAL.getDefault() + val toBeTheSamePointInTimeAsDescr = DescriptionDateTimeLikeAssertion.SAME_DAY.getDefault() listOf( @@ -47,85 +47,85 @@ abstract class ChronoLocalDateExpectationsSpec( val fluent = expect(subject) describe("$describePrefix subject is $subject") { - describe("${isBefore.name} ...") { - val isBeforeFun = isBefore.lambda + describe("${toBeBefore.name} ...") { + val toBeBeforeFun = toBeBefore.lambda it("... $december22 throws an AssertionError") { expect { - fluent.isBeforeFun(december22) - }.toThrow { messageToContain("$isBeforeDescr: $december22") } + fluent.toBeBeforeFun(december22) + }.toThrow { messageToContain("$toBeBeforeDescr: $december22") } } it("... $december23 throws an AssertionError") { expect { - fluent.isBeforeFun(december23) - }.toThrow { messageToContain("$isBeforeDescr: $december23") } + fluent.toBeBeforeFun(december23) + }.toThrow { messageToContain("$toBeBeforeDescr: $december23") } } it("... $december24 does not throw") { - fluent.isBeforeFun(december24) + fluent.toBeBeforeFun(december24) } } - describe("${isBeforeOrEqual.name} ...") { - val isBeforeOrEqualFun = isBeforeOrEqual.lambda + describe("${toBeBeforeOrTheSamePointInTimeAs.name} ...") { + val toBeBeforeOrTheSamePointInTimeAsFun = toBeBeforeOrTheSamePointInTimeAs.lambda it("... $december22 throws an AssertionError") { expect { - fluent.isBeforeOrEqualFun(december22) - }.toThrow { messageToContain("$isBeforeOrEqualDescr: $december22") } + fluent.toBeBeforeOrTheSamePointInTimeAsFun(december22) + }.toThrow { messageToContain("$toBeBeforeOrTheSamePointInTimeAsDescr: $december22") } } it("... $december23 does not throw") { - fluent.isBeforeOrEqualFun(december23) + fluent.toBeBeforeOrTheSamePointInTimeAsFun(december23) } it("... $december24 does not throw") { - fluent.isBeforeOrEqualFun(december24) + fluent.toBeBeforeOrTheSamePointInTimeAsFun(december24) } } - describe("${isAfter.name} ...") { - val isAfterFun = isAfter.lambda + describe("${toBeAfter.name} ...") { + val toBeAfterFun = toBeAfter.lambda it("... $december22 does not throw") { - fluent.isAfterFun(december22) + fluent.toBeAfterFun(december22) } it("... $december23 throws an AssertionError") { expect { - fluent.isAfterFun(december23) - }.toThrow { messageToContain("$isAfterDescr: $december23") } + fluent.toBeAfterFun(december23) + }.toThrow { messageToContain("$toBeAfterDescr: $december23") } } it("... $december24 throws an AssertionError") { expect { - fluent.isAfterFun(december24) - }.toThrow { messageToContain("$isAfterDescr: $december24") } + fluent.toBeAfterFun(december24) + }.toThrow { messageToContain("$toBeAfterDescr: $december24") } } } - describe("${isAfterOrEqual.name} ...") { - val isAfterOrEqualFun = isAfterOrEqual.lambda + describe("${toBeAfterOrTheSamePointInTimeAs.name} ...") { + val toBeAfterOrTheSamePointInTimeAsFun = toBeAfterOrTheSamePointInTimeAs.lambda it("... $december22 does not throw") { - fluent.isAfterOrEqualFun(december22) + fluent.toBeAfterOrTheSamePointInTimeAsFun(december22) } it("... $december23 does not throw") { - fluent.isAfterOrEqualFun(december23) + fluent.toBeAfterOrTheSamePointInTimeAsFun(december23) } it("... $december24 throws an AssertionError") { expect { - fluent.isAfterOrEqualFun(december24) - }.toThrow { messageToContain("$isAfterOrEqualDescr: $december24") } + fluent.toBeAfterOrTheSamePointInTimeAsFun(december24) + }.toThrow { messageToContain("$toBeAfterOrTheSamePointInTimeAsDescr: $december24") } } } - describe("${isEqual.name} ...") { - val isEqualFun = isEqual.lambda + describe("${toBeTheSamePointInTimeAs.name} ...") { + val toBeTheSamePointInTimeAsFun = toBeTheSamePointInTimeAs.lambda it("... $december22 throws an AssertionError") { expect { - fluent.isEqualFun(december22) - }.toThrow { messageToContain("$isEqualDescr: $december22") } + fluent.toBeTheSamePointInTimeAsFun(december22) + }.toThrow { messageToContain("$toBeTheSamePointInTimeAsDescr: $december22") } } it("... $december23 does not throw") { - fluent.isEqualFun(december23) + fluent.toBeTheSamePointInTimeAsFun(december23) } it("... $december24 throws an AssertionError") { expect { - fluent.isEqualFun(december24) - }.toThrow { messageToContain("$isEqualDescr: $december24") } + fluent.toBeTheSamePointInTimeAsFun(december24) + }.toThrow { messageToContain("$toBeTheSamePointInTimeAsDescr: $december24") } } } }