LocalTimeSource

@SourceProvider(value = LocalDateTimeValueSourceDataProvider::class)
annotation class LocalTimeSource(val values: Array<String>, val timeFormat: String = "HH:mm")

Annotation to be utilized on a parameter of type LocalTime in a parametrized test. The annotated parameter's value will be populated with a randomized value derived from the provided values array.

The values array should consist of time string values, formatted according to the timeFormat property.

Default value for timeFormat is "HH:mm".

Samples

import assertk.Assert
import assertk.all
import assertk.assertThat
import assertk.assertions.isBetween
import assertk.assertions.isIn
import assertk.assertions.isLessThan
import assertk.assertions.support.expected
import com.wesleyhome.test.jupiter.annotations.GeneratedParametersTest
import com.wesleyhome.test.jupiter.annotations.StringSource
import com.wesleyhome.test.jupiter.annotations.datetime.InstantRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.InstantSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateTimeRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateTimeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalTimeRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalTimeSource
import com.wesleyhome.test.jupiter.annotations.datetime.RandomInstantSource
import com.wesleyhome.test.jupiter.annotations.number.DoubleRangeSource
import com.wesleyhome.test.jupiter.annotations.number.DoubleSource
import com.wesleyhome.test.jupiter.annotations.number.FloatRangeSource
import com.wesleyhome.test.jupiter.annotations.number.FloatSource
import com.wesleyhome.test.jupiter.annotations.number.IntRangeSource
import com.wesleyhome.test.jupiter.annotations.number.IntSource
import com.wesleyhome.test.jupiter.annotations.number.LongRangeSource
import com.wesleyhome.test.jupiter.annotations.number.LongSource
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.temporal.ChronoUnit

fun main() { 
   //sampleStart 
   /**
 * 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 testLocalTimeSource(
    @LocalTimeSource(
        values = [
            "00:00",
            "02:00",
            "04:00",
            "06:00",
            "08:00"
        ]
    )
    value: LocalTime
) {
    assertThat(value).isLessThan(LocalTime.parse("09:00"))
}

/**
 * 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 testLocalTimeSourceWithFormat(
    @LocalTimeSource(
        values = [
            "00:00:01",
            "02:00:02",
            "03:00:03",
            "04:00:04",
            "05:00:05"
        ],
        timeFormat = "hh:mm:ss"
    )
    value: LocalTime
) {
    assertThat(value).isLessThan(LocalTime.parse("06:00"))
} 
   //sampleEnd
}

Properties

Link copied to clipboard

A String representing the pattern to be used for parsing the values into LocalTime instances. Default value is "HH:mm".

Link copied to clipboard

An array of string representing time, to be converted into LocalTime instances. The time strings should be formatted according to the timeFormat property.