Add MethodValidationResult

See gh-29825
This commit is contained in:
Rossen Stoyanchev
2023-06-07 11:17:09 +01:00
committed by rstoyanchev
parent 8b53fecc06
commit cc8361cd93
5 changed files with 170 additions and 66 deletions

View File

@@ -32,7 +32,6 @@ import org.springframework.util.ClassUtils;
import org.springframework.validation.FieldError;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Unit tests for {@link MethodValidationAdapter}.
@@ -40,6 +39,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
public class MethodValidationAdapterTests {
private static final MethodValidationAdapter validationAdapter = new MethodValidationAdapter();
private static final Person faustino1234 = new Person("Faustino1234");
private static final Person cayetana6789 = new Person("Cayetana6789");
@@ -154,23 +155,17 @@ public class MethodValidationAdapterTests {
}
private void validateArguments(
Object target, Method method, Object[] arguments, Consumer<MethodValidationException> assertions) {
Object target, Method method, Object[] arguments, Consumer<MethodValidationResult> assertions) {
MethodValidationAdapter adapter = new MethodValidationAdapter();
assertThatExceptionOfType(MethodValidationException.class)
.isThrownBy(() -> adapter.validateMethodArguments(target, method, arguments, new Class<?>[0]))
.satisfies(assertions);
assertions.accept(
validationAdapter.validateMethodArguments(target, method, arguments, new Class<?>[0]));
}
private void validateReturnValue(
Object target, Method method, @Nullable Object returnValue, Consumer<MethodValidationException> assertions) {
Object target, Method method, @Nullable Object returnValue, Consumer<MethodValidationResult> assertions) {
MethodValidationAdapter adapter = new MethodValidationAdapter();
assertThatExceptionOfType(MethodValidationException.class)
.isThrownBy(() -> adapter.validateMethodReturnValue(target, method, returnValue, new Class<?>[0]))
.satisfies(assertions);
assertions.accept(
validationAdapter.validateMethodReturnValue(target, method, returnValue, new Class<?>[0]));
}
private static void assertBeanResult(
@@ -225,12 +220,6 @@ public class MethodValidationAdapterTests {
@SuppressWarnings("unused")
private record Person(@Size(min = 1, max = 10) String name) {
@Override
public String name() {
return this.name;
}
}
}