Improve analysis of bind failures caused by a conversion failure

Closes gh-13357
This commit is contained in:
Andy Wilkinson
2018-06-04 16:26:43 +01:00
parent ea51cfabca
commit 9c8d2c8016
2 changed files with 12 additions and 6 deletions

View File

@@ -70,6 +70,12 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> {
}
private String getMessage(BindException cause) {
ConversionFailedException conversionFailure = findCause(cause,
ConversionFailedException.class);
if (conversionFailure != null) {
return "failed to convert " + conversionFailure.getSourceType() + " to "
+ conversionFailure.getTargetType();
}
Throwable failure = cause;
while (failure.getCause() != null) {
failure = failure.getCause();

View File

@@ -62,10 +62,10 @@ public class BindFailureAnalyzerTests {
@Test
public void bindExceptionDueToOtherFailure() {
FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class,
"test.foo.value=${BAR}");
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "${BAR}",
"test.foo.value=alpha");
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "alpha",
"\"test.foo.value\" from property source \"test\"",
"Could not resolve placeholder 'BAR' in value \"${BAR}\""));
"failed to convert java.lang.String to int"));
}
@Test
@@ -187,13 +187,13 @@ public class BindFailureAnalyzerTests {
@ConfigurationProperties("test.foo")
static class GenericFailureProperties {
private String value;
private int value;
public String getValue() {
public int getValue() {
return this.value;
}
public void setValue(String value) {
public void setValue(int value) {
this.value = value;
}