Skip to content

Commit

Permalink
robstoll#481 added Companion implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rkiselev committed Jul 26, 2020
1 parent def1fc9 commit 0a743da
Show file tree
Hide file tree
Showing 3 changed files with 94 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 @@ -24,21 +24,42 @@ class ChronoLocalDateTimeAssertionSpec : Spek({

object StringSpec : ch.tutteli.atrium.specs.integration.ChronoLocalDateTimeAssertionSpec(
fun1(Companion::isBefore),
//TODO #481 introduce more companions
fun1(Expect<ChronoLocalDateTime<*>>::isBeforeOrEqual),
fun1(Expect<ChronoLocalDateTime<*>>::isAfter),
fun1(Expect<ChronoLocalDateTime<*>>::isAfterOrEqual),
fun1(Expect<ChronoLocalDateTime<*>>::isEqual)
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.format(DateTimeFormatter.ISO_DATE_TIME))
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 @@ -11,8 +11,6 @@ import ch.tutteli.atrium.assertions.Assertion
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.domain.creating.ChronoLocalDateTimeAssertions
import ch.tutteli.atrium.domain.robstoll.lib.creating.*
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.chrono.ChronoLocalDate
import java.time.chrono.ChronoLocalDateTime

Expand Down

0 comments on commit 0a743da

Please sign in to comment.