Joel Hess
01/13/2021, 9:37 PMfun <T> assertValidation(o: Any, validation: Class<T>, propertyName: String? = null) {
val violations = when (propertyName) {
null -> validator.validate(o)
else -> validator.validateProperty(o, propertyName)
}
assertAll(
Executable {
assertEquals(
1,
violations.count(),
"Expecting one violation, received ${violations.count()}"
)
},
Executable {
violations.forEach { violation ->
val annotation = violation.constraintDescriptor.annotation
assertThat(annotation, instanceOf(validation))
}
}
)
I’m trying to convert the type assertion to use ShouldBeInstanceOf<t> but the compiler doesn’t like it because its a generic type. I’m trying to change it to something along the lines of
inline fun <reified T> assertValidation(o: Any, validation: Class<T>, propertyName: String? = null) {
val violations = when (propertyName) {
null -> validator.validate(o)
else -> validator.validateProperty(o, propertyName)
}
assertSoftly {
withClue("Expecting one violation, received ${violations.count()}") {
violations.shouldHaveSize(1)
}
violations.forEach { violation ->
val annotation = violation.constraintDescriptor.annotation
annotation.shouldBeInstanceOf<validation>()
//assertThat(annotation, instanceOf(validation))
}
}
}
How can I use ShouldBeInstanceOf in this case?sam
01/13/2021, 9:45 PMinline fun <reified T> assertValidation(o: Any, validation: Class<T>, propertyName: String? = null) {
val violations = when (propertyName) {
null -> validator.validate(o)
else -> validator.validateProperty(o, propertyName)
}
assertSoftly {
withClue("Expecting one violation, received ${violations.count()}") {
violations.shouldHaveSize(1)
}
violations.forEach { violation ->
val annotation = violation.constraintDescriptor.annotation
annotation.shouldBeInstanceOf<T>()
//assertThat(annotation, instanceOf(validation))
}
}
}
Joel Hess
01/13/2021, 9:56 PMType argument is not within its bounds: should be subtype of 'Any'
sam
01/13/2021, 9:56 PMinline fun <reified T: Any>
^^ change to thatJoel Hess
01/13/2021, 10:02 PMsam
01/13/2021, 10:09 PM