Merge branch '6.1.x'
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.validation.beanvalidation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
@@ -201,9 +202,7 @@ class MethodValidationAdapterTests {
|
||||
Method method = getMethod(target, "addHobbies");
|
||||
|
||||
testArgs(target, method, new Object[] {List.of(" ")}, ex -> {
|
||||
|
||||
assertThat(ex.getAllValidationResults()).hasSize(1);
|
||||
|
||||
assertValueResult(ex.getValueResults().get(0), 0, " ", List.of("""
|
||||
org.springframework.context.support.DefaultMessageSourceResolvable: \
|
||||
codes [NotBlank.myService#addHobbies.hobbies,NotBlank.hobbies,NotBlank.java.util.List,NotBlank]; \
|
||||
@@ -213,6 +212,22 @@ class MethodValidationAdapterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // gh-33150
|
||||
void validateValueSetArgument() {
|
||||
MyService target = new MyService();
|
||||
Method method = getMethod(target, "addUniqueHobbies");
|
||||
|
||||
testArgs(target, method, new Object[] {Set.of("test", " ")}, ex -> {
|
||||
assertThat(ex.getAllValidationResults()).hasSize(1);
|
||||
assertValueResult(ex.getValueResults().get(0), 0, Set.of("test", " "), List.of("""
|
||||
org.springframework.context.support.DefaultMessageSourceResolvable: \
|
||||
codes [NotBlank.myService#addUniqueHobbies.hobbies,NotBlank.hobbies,NotBlank.java.util.Set,NotBlank]; \
|
||||
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: \
|
||||
codes [myService#addUniqueHobbies.hobbies,hobbies]; \
|
||||
arguments []; default message [hobbies]]; default message [must not be blank]"""));
|
||||
});
|
||||
}
|
||||
|
||||
private void testArgs(Object target, Method method, Object[] args, Consumer<MethodValidationResult> consumer) {
|
||||
consumer.accept(this.validationAdapter.validateArguments(target, method, null, args, new Class<?>[0]));
|
||||
}
|
||||
@@ -271,6 +286,8 @@ class MethodValidationAdapterTests {
|
||||
public void addHobbies(List<@NotBlank String> hobbies) {
|
||||
}
|
||||
|
||||
public void addUniqueHobbies(Set<@NotBlank String> hobbies) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user