Skip to content

Commit

Permalink
Add samples for localDateTimeAssertions of api-infix (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhushikesh committed Oct 9, 2021
1 parent ea6230b commit 04a0e50
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ val Expect<LocalDateTime>.year: Expect<Int>
*
* @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<LocalDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -52,6 +54,8 @@ val Expect<LocalDateTime>.month: Expect<Int>
*
* @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<LocalDateTime>.month(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -75,6 +79,8 @@ val Expect<LocalDateTime>.dayOfWeek: Expect<DayOfWeek>
*
* @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<LocalDateTime>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -98,6 +104,8 @@ val Expect<LocalDateTime>.day: Expect<Int>
*
* @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<LocalDateTime>.day(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.DayOfWeek
import java.time.LocalDateTime
import java.time.Month
import kotlin.test.Test

class LocalDateTimeExpectationSamples {

@Test
fun year() {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) year {
it toEqual 2021
it toBeGreaterThan 2020
}

fails {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) year {
it notToEqual 2022
it toBeGreaterThan 2022
it toBeLessThan 2020
}
}
}

@Test
fun month() {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) month {
it toEqual Month.OCTOBER.value
it notToEqual Month.SEPTEMBER.value
}

fails {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) month {
it toEqual Month.SEPTEMBER.value
it notToEqual Month.OCTOBER.value
}
}
}

@Test
fun dayOfWeek() {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) dayOfWeek {
it toEqual DayOfWeek.SATURDAY
it notToEqual DayOfWeek.SUNDAY
}

fails {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) dayOfWeek {
it toEqual DayOfWeek.MONDAY
it notToEqual DayOfWeek.SATURDAY
}
}
}

@Test
fun day() {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) day {
it toEqual 9
it toBeGreaterThan 5
}

fails {
expect(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56)) day {
it toEqual 5
it toBeLessThan 7
}
}
}

}

0 comments on commit 04a0e50

Please sign in to comment.