Skip to content

Commit

Permalink
Merge pull request #1009 from robstoll/improve-samples
Browse files Browse the repository at this point in the history
Improve samples
  • Loading branch information
robstoll authored Oct 12, 2021
2 parents b6e40bd + 235455d commit d9f0281
Show file tree
Hide file tree
Showing 12 changed files with 1,181 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import java.time.LocalDate
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.yearFeature
*
* @since 0.9.0
*/
val Expect<LocalDate>.year: Expect<Int>
Expand All @@ -28,6 +30,8 @@ val Expect<LocalDate>.year: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.year
*
* @since 0.9.0
*/
fun Expect<LocalDate>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDate> =
Expand All @@ -39,6 +43,8 @@ fun Expect<LocalDate>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<Loc
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.monthFeature
*
* @since 0.9.0
*/
val Expect<LocalDate>.month: Expect<Int>
Expand All @@ -51,6 +57,8 @@ val Expect<LocalDate>.month: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.month
*
* @since 0.9.0
*/
fun Expect<LocalDate>.month(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDate> =
Expand All @@ -62,6 +70,8 @@ fun Expect<LocalDate>.month(assertionCreator: Expect<Int>.() -> Unit): Expect<Lo
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.dayOfWeekFeature
*
* @since 0.9.0
*/
val Expect<LocalDate>.dayOfWeek: Expect<DayOfWeek>
Expand All @@ -74,6 +84,8 @@ val Expect<LocalDate>.dayOfWeek: Expect<DayOfWeek>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.dayOfWeek
*
* @since 0.9.0
*/
fun Expect<LocalDate>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Unit): Expect<LocalDate> =
Expand All @@ -86,6 +98,8 @@ fun Expect<LocalDate>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Unit):
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.dayFeature
*
* @since 0.9.0
*/
val Expect<LocalDate>.day: Expect<Int>
Expand All @@ -98,6 +112,8 @@ val Expect<LocalDate>.day: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateExpectationSamples.day
*
* @since 0.9.0
*/
fun Expect<LocalDate>.day(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDate> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import java.time.LocalDateTime
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.yearFeature
*
* @since 0.9.0
*/
val Expect<LocalDateTime>.year: Expect<Int>
Expand All @@ -29,6 +31,8 @@ val Expect<LocalDateTime>.year: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.year
*
* @since 0.9.0
*/
fun Expect<LocalDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -40,6 +44,8 @@ fun Expect<LocalDateTime>.year(assertionCreator: Expect<Int>.() -> Unit): Expect
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.monthFeature
*
* @since 0.9.0
*/
val Expect<LocalDateTime>.month: Expect<Int>
Expand All @@ -52,6 +58,8 @@ val Expect<LocalDateTime>.month: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.month
*
* @since 0.9.0
*/
fun Expect<LocalDateTime>.month(assertionCreator: Expect<Int>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -63,6 +71,8 @@ fun Expect<LocalDateTime>.month(assertionCreator: Expect<Int>.() -> Unit): Expec
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayOfWeekFeature
*
* @since 0.9.0
*/
val Expect<LocalDateTime>.dayOfWeek: Expect<DayOfWeek>
Expand All @@ -75,6 +85,8 @@ val Expect<LocalDateTime>.dayOfWeek: Expect<DayOfWeek>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayOfWeek
*
* @since 0.9.0
*/
fun Expect<LocalDateTime>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Unit): Expect<LocalDateTime> =
Expand All @@ -86,6 +98,8 @@ fun Expect<LocalDateTime>.dayOfWeek(assertionCreator: Expect<DayOfWeek>.() -> Un
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.dayFeature
*
* @since 0.9.0
*/
val Expect<LocalDateTime>.day: Expect<Int>
Expand All @@ -98,6 +112,8 @@ val Expect<LocalDateTime>.day: Expect<Int>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.LocalDateTimeExpectationSamples.day
*
* @since 0.9.0
*/
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,144 @@
package ch.tutteli.atrium.api.fluent.en_GB.samples

import ch.tutteli.atrium.api.fluent.en_GB.*
import ch.tutteli.atrium.api.verbs.internal.expect
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.Month
import kotlin.test.Test

class LocalDateExpectationSamples {

@Test
fun yearFeature() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.year // subject is now of type Int (actually 2021)
.toEqual(2021)

fails {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.year // subject is now of type Int (actually 2021)
.toBeGreaterThan(2030) // fails
.toBeLessThan(2000) // not reported because toBeLessThan already fails
// use `.year { ... }` if you want that all expectations are evaluated
}
}

@Test
fun year() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.year { // subject inside this block is of type Int (actually 2021)
toEqual(2021)
toBeGreaterThan(2020)
} // subject here is back to type LocalDate

fails {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.year { // subject inside this block is of type Int (actually 2021)
notToEqual(1980) // fails
toBeLessThan(2000) // not reported because notToEqual already fails
// use `.year.` if you want a fail fast behaviour
} // subject here is back to type LocalDate
}
}

@Test
fun monthFeature() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.month // subject is now of type Int (actually Month.OCTOBER.value i.e. 10)
.toEqual(10)

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

@Test
fun month() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.month { // subject inside this block is of type Int (actually Month.OCTOBER.value i.e. 10)
toBeGreaterThan(5)
notToEqual(9)
} // subject here is back to type LocalDate

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

@Test
fun dayOfWeekFeature() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.dayOfWeek // subject is now of type DayOfWeek (actually SATURDAY)
.toEqual(DayOfWeek.SATURDAY)

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

@Test
fun dayOfWeek() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.dayOfWeek { // subject inside this block is of type DayOfWeek (actually SATURDAY)
toEqual(DayOfWeek.SATURDAY)
notToEqual(DayOfWeek.SUNDAY)
} // subject here is back to type LocalDate

fails {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.dayOfWeek { // subject inside this block is of type DayOfWeek (actually SATURDAY)
toEqual(DayOfWeek.MONDAY) // fails
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 LocalDate
}
}

@Test
fun dayFeature() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.day // subject is now of type Int (actually 9)
.toEqual(9)

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

@Test
fun day() {
expect(LocalDate.of(2021, Month.OCTOBER, 9))
.day { // subject inside this block is of type Int (actually 9)
toEqual(9)
toBeGreaterThan(5)
} // subject here is back to type LocalDate

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

}
Loading

0 comments on commit d9f0281

Please sign in to comment.