Merge branch '2.0.x'
This commit is contained in:
commit
d0ce919d8c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -51,7 +51,7 @@ public class PropertySourcesPlaceholdersResolver implements PlaceholdersResolver
|
||||||
this.helper = (helper != null ? helper
|
this.helper = (helper != null ? helper
|
||||||
: new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
|
: new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
|
||||||
SystemPropertyUtils.PLACEHOLDER_SUFFIX,
|
SystemPropertyUtils.PLACEHOLDER_SUFFIX,
|
||||||
SystemPropertyUtils.VALUE_SEPARATOR, false));
|
SystemPropertyUtils.VALUE_SEPARATOR, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -70,6 +70,12 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMessage(BindException cause) {
|
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;
|
Throwable failure = cause;
|
||||||
while (failure.getCause() != null) {
|
while (failure.getCause() != null) {
|
||||||
failure = failure.getCause();
|
failure = failure.getCause();
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.assertj.core.matcher.AssertionMatcher;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.internal.matchers.ThrowableMessageMatcher;
|
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
@ -53,7 +52,6 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
@ -153,15 +151,13 @@ public class BinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindToValueWithMissingPlaceholdersShouldThrowException() {
|
public void bindToValueWithMissingPlaceholderShouldResolveToValueWithPlaceholder() {
|
||||||
StandardEnvironment environment = new StandardEnvironment();
|
StandardEnvironment environment = new StandardEnvironment();
|
||||||
this.sources.add(new MockConfigurationPropertySource("foo", "${bar}"));
|
this.sources.add(new MockConfigurationPropertySource("foo", "${bar}"));
|
||||||
this.binder = new Binder(this.sources,
|
this.binder = new Binder(this.sources,
|
||||||
new PropertySourcesPlaceholdersResolver(environment));
|
new PropertySourcesPlaceholdersResolver(environment));
|
||||||
this.thrown.expect(BindException.class);
|
BindResult<String> result = this.binder.bind("foo", Bindable.of(String.class));
|
||||||
this.thrown.expectCause(ThrowableMessageMatcher.hasMessage(containsString(
|
assertThat(result.get()).isEqualTo("${bar}");
|
||||||
"Could not resolve placeholder 'bar' in value \"${bar}\"")));
|
|
||||||
this.binder.bind("foo", Bindable.of(Integer.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -67,12 +67,10 @@ public class PropertySourcesPlaceholdersResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveIfPlaceholderAbsentAndNoDefaultShouldThrowException() {
|
public void resolveIfPlaceholderAbsentAndNoDefaultUsesPlaceholder() {
|
||||||
this.resolver = new PropertySourcesPlaceholdersResolver((PropertySources) null);
|
this.resolver = new PropertySourcesPlaceholdersResolver((PropertySources) null);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
Object resolved = this.resolver.resolvePlaceholders("${FOO}");
|
||||||
this.thrown
|
assertThat(resolved).isEqualTo("${FOO}");
|
||||||
.expectMessage("Could not resolve placeholder 'FOO' in value \"${FOO}\"");
|
|
||||||
this.resolver.resolvePlaceholders("${FOO}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -62,10 +62,10 @@ public class BindFailureAnalyzerTests {
|
||||||
@Test
|
@Test
|
||||||
public void bindExceptionDueToOtherFailure() {
|
public void bindExceptionDueToOtherFailure() {
|
||||||
FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class,
|
FailureAnalysis analysis = performAnalysis(GenericFailureConfiguration.class,
|
||||||
"test.foo.value=${BAR}");
|
"test.foo.value=alpha");
|
||||||
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "${BAR}",
|
assertThat(analysis.getDescription()).contains(failure("test.foo.value", "alpha",
|
||||||
"\"test.foo.value\" from property source \"test\"",
|
"\"test.foo.value\" from property source \"test\"",
|
||||||
"Could not resolve placeholder 'BAR' in value \"${BAR}\""));
|
"failed to convert java.lang.String to int"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -187,13 +187,13 @@ public class BindFailureAnalyzerTests {
|
||||||
@ConfigurationProperties("test.foo")
|
@ConfigurationProperties("test.foo")
|
||||||
static class GenericFailureProperties {
|
static class GenericFailureProperties {
|
||||||
|
|
||||||
private String value;
|
private int value;
|
||||||
|
|
||||||
public String getValue() {
|
public int getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue