Fix assertions in ValidationAutoConfigurationTests

pull/33770/merge
Moritz Halbritter 2 years ago
parent c5b5449a07
commit 90a6d514a3

@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.validation;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validator;
@ -207,6 +208,7 @@ class ValidationAutoConfigurationTests {
}
@Test
@SuppressWarnings("unchecked")
void userDefinedMethodValidationPostProcessorTakesPrecedence() {
this.contextRunner.withUserConfiguration(SampleConfiguration.class).run((context) -> {
assertThat(context.getBeansOfType(Validator.class)).hasSize(1);
@ -214,8 +216,9 @@ class ValidationAutoConfigurationTests {
assertThat(context.getBean(MethodValidationPostProcessor.class))
.isSameAs(userMethodValidationPostProcessor);
assertThat(context.getBeansOfType(MethodValidationPostProcessor.class)).hasSize(1);
assertThat(context.getBean(Validator.class))
.isNotSameAs(ReflectionTestUtils.getField(userMethodValidationPostProcessor, "validator"));
Object validator = ReflectionTestUtils.getField(userMethodValidationPostProcessor, "validator");
assertThat(validator).isNotNull().isInstanceOf(Supplier.class);
assertThat(context.getBean(Validator.class)).isNotSameAs(((Supplier<Validator>) validator).get());
});
}

Loading…
Cancel
Save