LocalDateSource

@SourceProvider(value = LocalDateValueSourceDataProvider::class)
annotation class LocalDateSource(val values: Array<String>, val dateFormat: String = "yyyy-MM-dd")

Annotation to indicate that the annotated LocalDate parameter should be populated with a random value from the provided values array.

Samples

/**
 * This will generate 5 tests with the values "2020-01-01", "2021-01-01", "2022-01-01", "2023-01-01", "2024-01-01"
 */
@GeneratedParametersTest
fun testLocalDateSource(@LocalDateSource(values = ["2020-01-01", "2021-01-01", "2022-01-01", "2023-01-01", "2024-01-01"]) value: LocalDate) {
    assertThat(value).isLessThan(LocalDate.now())
}

/**
 * This will generate 5 tests with the values "01/01/2020", "01/01/2021", "01/01/2022", "01/01/2023", "01/01/2024"
 * The values will be parsed using the format "MM/dd/yyyy"
 */
@GeneratedParametersTest
fun testLocalDateSourceWithFormat(
    @LocalDateSource(
        values = ["01/01/2020", "01/01/2021", "01/01/2022", "01/01/2023", "01/01/2024"],
        dateFormat = "MM/dd/yyyy"
    )
    value: LocalDate
) {
    assertThat(value).isLessThan(LocalDate.now())
}

Properties

Link copied to clipboard

The format to use when parsing the date string.

Link copied to clipboard

The array of possible values to use for the random date.