Initialize propertyName

MethodArgumentTypeMismatchException and
MethodArgumentConversionNotSupportedException are TypeMismatchException
subclasses with MethodParameter information and should initialize
propertyName in TypeMismatchInformation.

Closes gh-29959
This commit is contained in:
rstoyanchev
2023-02-14 18:12:48 +00:00
parent a3efcabe0c
commit f54e1ef880
3 changed files with 11 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
@@ -242,15 +243,16 @@ class RequestHeaderMethodArgumentResolverTests {
}
@Test
void uuidConversionWithInvalidValue() throws Exception {
void uuidConversionWithInvalidValue() {
servletRequest.addHeader("name", "bogus-uuid");
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
assertThatExceptionOfType(MethodArgumentTypeMismatchException.class).isThrownBy(
() -> resolver.resolveArgument(paramUuid, null, webRequest,
new DefaultDataBinderFactory(bindingInitializer)));
assertThatThrownBy(() ->
resolver.resolveArgument(paramUuid, null, webRequest, new DefaultDataBinderFactory(bindingInitializer)))
.isInstanceOf(MethodArgumentTypeMismatchException.class)
.extracting("propertyName").isEqualTo("name");
}
@Test