Skip to content

Commit

Permalink
Merge branch 'robstoll#481-ChronoLocalDateTime-as-string' into robsto…
Browse files Browse the repository at this point in the history
…ll#481-chrono-local-date-time

# Conflicts:
#	apis/fluent-en_GB/atrium-api-fluent-en_GB-jvm/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/ChronoLocalDateTimeAssertionSpec.kt
#	logic/atrium-logic-jvm/src/main/kotlin/ch/tutteli/atrium/logic/impl/DefaultChronoLocalDateTimeAssertions.kt
  • Loading branch information
rkiselev committed Jul 26, 2020
2 parents 5e646ee + 0a743da commit 5b0a2d1
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,68 @@ fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isAfterOrEqual(
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isEqual(
expected: ChronoLocalDateTime<*>
): Expect<T> = _logicAppend { isEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoLocalDateTime])
* is before the [expected] [String].
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.13.0
*/
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isBefore(
expected: String
): Expect<T> = _logicAppend { isBefore(expected) }

/**
* Expects that the subject of the assertion (a [ChronoLocalDateTime])
* is before or equal the [expected] [String].
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.13.0
*/
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isBeforeOrEqual(
expected: String
): Expect<T> = _logicAppend { isBeforeOrEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoLocalDateTime])
* is after the [expected] [String].
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.13.0
*/
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isAfter(
expected: String
): Expect<T> = _logicAppend { isAfter(expected) }

/**
* Expects that the subject of the assertion (a [ChronoLocalDateTime])
* is after or equal the [expected] [String].
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.13.0
*/
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isAfterOrEqual(
expected: String
): Expect<T> = _logicAppend { isAfterOrEqual(expected) }

/**
* Expects that the subject of the assertion (a [ChronoLocalDateTime])
* is equal to the [expected] [String].
*
* @return An [Expect] for the current subject of the assertion.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*
* @since 0.13.0
*/
fun <T : ChronoLocalDateTime<out ChronoLocalDate>> Expect<T>.isEqual(
expected: String
): Expect<T> = _logicAppend { isEqual(expected) }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.time.LocalDate
import java.time.LocalDateTime
import java.time.chrono.ChronoLocalDate
import java.time.chrono.ChronoLocalDateTime
import java.time.format.DateTimeFormatter

class ChronoLocalDateTimeAssertionSpec : Spek({
include(ChronoLocalDateTimeSpec)
Expand All @@ -22,20 +23,43 @@ class ChronoLocalDateTimeAssertionSpec : Spek({
)

object StringSpec : ch.tutteli.atrium.specs.integration.ChronoLocalDateTimeAssertionSpec(
fun1(Expect<ChronoLocalDateTime<*>>::isBefore),
fun1(Expect<ChronoLocalDateTime<*>>::isBeforeOrEqual),
fun1(Expect<ChronoLocalDateTime<*>>::isAfter),
fun1(Expect<ChronoLocalDateTime<*>>::isAfterOrEqual),
fun1(Expect<ChronoLocalDateTime<*>>::isEqual)
fun1(Companion::isBefore),
fun1(Companion::isBeforeOrEqual),
fun1(Companion::isAfter),
fun1(Companion::isAfterOrEqual),
fun1(Companion::isEqual)
)

companion object {
fun isBefore(
expect: Expect<ChronoLocalDateTime<*>>,
expected: ChronoLocalDateTime<*>
): Expect<ChronoLocalDateTime<*>> =
//TODO #481 turn into string in ISO format
expect.isBefore(expected)
expect.isBefore(expected.format(DateTimeFormatter.ISO_DATE_TIME))

fun isBeforeOrEqual(
expect: Expect<ChronoLocalDateTime<*>>,
expected: ChronoLocalDateTime<*>
): Expect<ChronoLocalDateTime<*>> =
expect.isBeforeOrEqual(expected.format(DateTimeFormatter.ISO_DATE_TIME))

fun isAfter(
expect: Expect<ChronoLocalDateTime<*>>,
expected: ChronoLocalDateTime<*>
): Expect<ChronoLocalDateTime<*>> =
expect.isAfter(expected.format(DateTimeFormatter.ISO_DATE_TIME))

fun isAfterOrEqual(
expect: Expect<ChronoLocalDateTime<*>>,
expected: ChronoLocalDateTime<*>
): Expect<ChronoLocalDateTime<*>> =
expect.isAfterOrEqual(expected.format(DateTimeFormatter.ISO_DATE_TIME))

fun isEqual(
expect: Expect<ChronoLocalDateTime<*>>,
expected: ChronoLocalDateTime<*>
): Expect<ChronoLocalDateTime<*>> =
expect.isEqual(expected.format(DateTimeFormatter.ISO_DATE_TIME))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ package ch.tutteli.atrium.logic.impl

import ch.tutteli.atrium.assertions.Assertion
import ch.tutteli.atrium.creating.AssertionContainer
import ch.tutteli.atrium.logic.ChronoLocalDateTimeAssertions
import ch.tutteli.atrium.logic.createDescriptiveAssertion
import ch.tutteli.atrium.logic.*
import ch.tutteli.atrium.translations.DescriptionDateTimeLikeAssertion.*
import java.time.LocalDate
import java.time.LocalDateTime
Expand Down Expand Up @@ -46,7 +45,7 @@ class DefaultChronoLocalDateTimeAssertions : ChronoLocalDateTimeAssertions {
override fun <T : ChronoLocalDateTime<out ChronoLocalDate>> isAfter(
container: AssertionContainer<T>,
expected: String
): Assertion = isAfter(stringToLocalDateTime(expected))
): Assertion = container.isAfter(stringToLocalDateTime(expected))

override fun <T : ChronoLocalDateTime<out ChronoLocalDate>> isAfterOrEqual(
container: AssertionContainer<T>,
Expand Down

0 comments on commit 5b0a2d1

Please sign in to comment.