LocalDateRangeSource

@SourceProvider(value = LocalDateRangeDataProvider::class)
annotation class LocalDateRangeSource(val min: String, val max: String, val increment: String = "P1d", val ascending: Boolean = true, val dateFormat: String = "yyyy-MM-dd")

Annotation to indicate that the annotated LocalDate parameter should be populated with a LocalDate range from min to max with an increment step in the ascending direction. The default increment is 1 day. The default ascending is true.

Samples

/**
 * This will generate 10 tests with random LocalDate values
 * between 2023-01-01 and 2023-01-10
 */
@GeneratedParametersTest
fun testLocalDateRangeSource(
    @LocalDateRangeSource(
        min = "2023-01-01",
        max = "2023-01-10"
    )
    value: LocalDate
) {
    assertThat(value).isBetween(
        LocalDate.parse("2023-01-01"),
        LocalDate.parse("2023-01-10")
    )
}

/**
 * This will generate 10 tests with random LocalDate values
 * between 01/01/2023 and 01/10/2023
 * The values will be parsed using the format "MM/dd/yyyy"
 */
@GeneratedParametersTest
fun testLocalDateRangeSourceWithFormat(
    @LocalDateRangeSource(
        min = "01/01/2023",
        max = "01/10/2023",
        dateFormat = "MM/dd/yyyy"
    )
    value: LocalDate
) {
    assertThat(value).isBetween(
        LocalDate.parse("2023-01-01"),
        LocalDate.parse("2023-01-10")
    )
}

/**
 * This will generate 10 tests with random LocalDate values
 * between 01/01/2023 and 01/10/2023
 * The values will be parsed using the format "MM/dd/yyyy"
 * The values will be incremented by 2 days
 */
@GeneratedParametersTest
fun testLocalDateRangeSourceWithIncrement(
    @LocalDateRangeSource(
        min = "01/01/2023",
        max = "01/10/2023",
        dateFormat = "MM/dd/yyyy",
        increment = "P2d"
    )
    value: LocalDate
) {
    assertThat(value).isBetween(
        LocalDate.parse("2023-01-01"),
        LocalDate.parse("2023-01-10")
    )
}

Properties

Link copied to clipboard
val ascending: Boolean = true
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val max: String
Link copied to clipboard
val min: String