From 90a6d514a3d0e18ff4f06fb395240de1cfb45a17 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 11 Jan 2023 10:51:29 +0100 Subject: [PATCH] Fix assertions in ValidationAutoConfigurationTests --- .../validation/ValidationAutoConfigurationTests.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java index 584e16144e..5b404df280 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java @@ -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).get()); }); }