InstantRangeSource

@SourceProvider(value = InstantRangeSourceDataProvider::class)
annotation class InstantRangeSource(val min: String, val max: String, val increment: String = "PT1h", val ascending: Boolean = true)

Used to provide a range of instants to a test. The range is inclusive of the min and max values.

Parameters

min

The minimum value for the range. Should follow the ISO-8601 instant format e.g. "2022-01-01T00:00:00Z"

max

The maximum value for the range. Should follow the ISO-8601 instant format e.g. "2022-01-01T00:00:00Z"

increment

How much time to increment the value for each test. If ascending is false, this value will be negated. The default value is 1 hour. Should follow the ISO-8601 duration format e.g. "PT1h" for 1 hour, "PT30m" for 30 minutes.

ascending

The direction the values will be generated. If true, the range will start with min and increment until it reaches max. If false, the range will start with max and decrement until it reaches min.

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 10 tests with random Instant values
 * between 2023-01-01T00:00:00.000Z and 2023-01-02T01:00:00.000Z
 */
@GeneratedParametersTest
fun testRandomInstantSourceWithInstant(
    @RandomInstantSource(
        size = 10,
        min = "2023-01-01T00:00:00.000Z",
        max = "2023-01-02T01:00:00.000Z"
    )
    value: Instant
) {
    assertThat(value).isLessThan(Instant.now())
}

@GeneratedParametersTest
fun testRandomInstantSourceWithOffset(
    @RandomInstantSource(
        size = 10,
        min = "PT1H",
        max = "PT2H",
        useOffset = true
    )
    value: Instant
) {
    assertThat(value).isBetween(
        Instant.now().plus(1, ChronoUnit.HOURS),
        Instant.now().plus(2, ChronoUnit.HOURS)
    )
} 
   //sampleEnd
}

Properties

Link copied to clipboard
val ascending: Boolean = true

The direction the values will be generated. If true, the range will start with min and increment until it reaches max. If false, the range will start with max and decrement until it reaches min.

Link copied to clipboard

How much time to increment the value for each test. If ascending is false, this value will be negated. The default value is 1 hour. Should follow the ISO-8601 duration format e.g. "PT1h" for 1 hour, "PT30m" for 30 minutes.

Link copied to clipboard
val max: String

The maximum value for the range. Should follow the ISO-8601 instant format e.g. "2022-01-01T00:00:00Z"

Link copied to clipboard
val min: String

The minimum value for the range. Should follow the ISO-8601 instant format e.g. "2022-01-01T00:00:00Z"