com.wesleyhome.test.jupiter.provider.datetime.AbstractAnnotatedDateTimeRangeDataProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-jupiter-params-generated Show documentation
Show all versions of junit-jupiter-params-generated Show documentation
Library to help generate test parameter permutations for parameterized tests in JUnit.
This version is an initial attempt to convert to building with Gradle.
The newest version!
package com.wesleyhome.test.jupiter.provider.datetime
import com.wesleyhome.test.jupiter.annotations.validation.datetime.DateTimeRangeValidator
import com.wesleyhome.test.jupiter.propertyValue
import com.wesleyhome.test.jupiter.provider.AbstractAnnotatedParameterDataProvider
import com.wesleyhome.test.jupiter.provider.TestParameter
internal abstract class AbstractAnnotatedDateTimeRangeDataProvider, A : Annotation> :
AbstractAnnotatedParameterDataProvider() {
open val formatPropertyName: String = ""
final override fun createParameterOptionsData(testParameter: TestParameter): List {
val annotation = findAnnotation(testParameter)!!
val format = getFormatString(annotation)
val minString = annotation.propertyValue("min")
val maxString = annotation.propertyValue("max")
val increment = annotation.propertyValue("increment")
DateTimeRangeValidator.validate(minString, maxString, increment, format, this::convert).apply {
if (isNotEmpty()) {
throw IllegalArgumentException(joinToString(", "))
}
}
val min = convert(minString, format)
val max = convert(maxString, format)
val ascending = annotation.propertyValue("ascending")
val range = toList(min, max, increment)
return if (ascending) {
range
} else {
range.reversed()
}
}
open fun getFormatString(annotation: A): String = annotation.propertyValue(formatPropertyName)
abstract fun toList(min: T, max: T, increment: String): List
abstract fun convert(value: String, format: String): T
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy