Skip to content

Commit

Permalink
Add samples for infix api zonedDateTimeAssertions (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
iljakorneckis committed Oct 22, 2021
1 parent 5f52211 commit 4602f92
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import java.time.ZonedDateTime
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.yearFeature
*
* @since 0.12.0
*/
val Expect<ZonedDateTime>.year: Expect<Int>
Expand All @@ -29,6 +31,8 @@ val Expect<ZonedDateTime>.year: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.year
*
* @since 0.12.0
*/
infix fun Expect<ZonedDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<ZonedDateTime> =
Expand All @@ -40,6 +44,8 @@ infix fun Expect<ZonedDateTime>.year(assertionCreator: Expect<Int>.() -> Unit):
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.monthFeature
*
* @since 0.12.0
*/
val Expect<ZonedDateTime>.month: Expect<Int>
Expand All @@ -52,6 +58,8 @@ val Expect<ZonedDateTime>.month: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.month
*
* @since 0.12.0
*/
infix fun Expect<ZonedDateTime>.month(assertionCreator: Expect<Int>.() -> Unit): Expect<ZonedDateTime> =
Expand All @@ -63,6 +71,8 @@ infix fun Expect<ZonedDateTime>.month(assertionCreator: Expect<Int>.() -> Unit):
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayOfWeekFeature
*
* @since 0.12.0
*/
val Expect<ZonedDateTime>.dayOfWeek: Expect<DayOfWeek>
Expand All @@ -75,6 +85,8 @@ val Expect<ZonedDateTime>.dayOfWeek: Expect<DayOfWeek>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayOfWeek
*
* @since 0.12.0
*/
infix fun Expect<ZonedDateTime>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Unit): Expect<ZonedDateTime> =
Expand All @@ -86,6 +98,8 @@ infix fun Expect<ZonedDateTime>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.()
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.dayFeature
*
* @since 0.12.0
*/
val Expect<ZonedDateTime>.day: Expect<Int>
Expand All @@ -98,6 +112,8 @@ val Expect<ZonedDateTime>.day: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.ZonedDateTimeExpectationSamples.day
*
* @since 0.12.0
*/
infix fun Expect<ZonedDateTime>.day(assertionCreator: Expect<Int>.() -> Unit): Expect<ZonedDateTime> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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.*
import kotlin.test.Test

class ZonedDateTimeExpectationSamples {

@Test
fun yearFeature() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.year toEqual 2021
// | subject is now of type Int (actually 2021)

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.year toEqual 2022 toBeLessThan 2000
// | | | not reported because notToEqual already fails
// | | | use `year { ... }` if you want that all expectations are evaluated
// | | fails
// | subject is now of type Int (actually 2021)
}
}

@Test
fun year() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) year {
// subject inside this block is of type Int (actually 2021)
it toEqual 2021
it toBeGreaterThan 2020
} // subject here is back to type ZonedDateTime

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) year {
// subject inside this block is of type Int (actually 2021)
it notToEqual 2021 // fails
it toBeGreaterThan 2022 // not reported because notToEqual already fails
// use `.year.` if you want a fail fast behaviour
} // subject here is back to type ZonedDateTime
}
}

@Test
fun monthFeature() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.month toEqual Month.OCTOBER.value
// | subject is now of type Int (actually Month.OCTOBER.value i.e. 10)

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.month toBeLessThan 9 toBeGreaterThan 11
// | | | not reported because toBeLessThan already fails
// | | | use `month { ... }` if you want that all expectations are evaluated
// | | fails
// | subject is now of type Int (actually Month.OCTOBER.value i.e. 10)
}
}

@Test
fun month() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) 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 ZonedDateTime

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) month {
// subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10)
it toBeLessThan 9 // fails
it toBeGreaterThan 11 // still evaluated even though toBeLessThan already fails
// use `.month` if you want a fail fast behaviour
} // subject here is back to type ZonedDateTime
}
}

@Test
fun dayOfWeekFeature() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.dayOfWeek toEqual DayOfWeek.SATURDAY
// | subject is now of type DayOfWeek (actually SATURDAY)

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.dayOfWeek toEqual DayOfWeek.MONDAY
// | | | not reported because toEqual already fails
// | | | use `dayOfWeek { ... }` if you want that all expectations are evaluated
// | | fails
// | subject is now of type DayOfWeek (actually SATURDAY)
}
}

@Test
fun dayOfWeek() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) 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 ZonedDateTime

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) dayOfWeek {
// subject inside this block is of type DayOfWeek (actually SATURDAY)
it toEqual DayOfWeek.MONDAY // fails
it notToEqual DayOfWeek.SATURDAY // still evaluated even though toEqual already fails
// use `.dayOfWeek.` if you want a fail fast behaviour
} // subject here is back to type ZonedDateTime
}
}

@Test
fun dayFeature() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.day toEqual 9
// | subject is now of type Int (actually 9)

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault()))
.day toEqual 5 toBeGreaterThan 10
// | | | not reported because toEqual already fails
// | | | use `day { ... }` if you want that all expectations are evaluated
// | | fails
// | subject is now of type Int (actually 9)
}
}

@Test
fun day() {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) day {
// subject inside this block is of type Int (actually 9)
it toEqual 9
it toBeGreaterThan 5
} // subject here is back to type ZonedDateTime

fails {
expect(ZonedDateTime.of(LocalDateTime.of(2021, Month.OCTOBER, 9, 11, 56), ZoneId.systemDefault())) day {
// subject inside this block is of type Int (actually 9)
it toEqual 5 // fails
it toBeLessThan 7 // still evaluated even though toEqual already fails
// use `.day` if you want a fail fast behaviour
} // subject here is back to type ZonedDateTime
}
}
}

0 comments on commit 4602f92

Please sign in to comment.