Polish
This commit is contained in:
parent
270acd4636
commit
8aaf95b792
|
@ -167,7 +167,7 @@ class DataSourceInitializer {
|
|||
}
|
||||
else if (validate) {
|
||||
throw new InvalidConfigurationPropertyValueException(propertyName,
|
||||
resource, "the specified resource does not exist");
|
||||
resource, "The specified resource does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.context.properties.source;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Exception thrown when a configuration property value is invalid.
|
||||
*
|
||||
|
@ -31,9 +33,19 @@ public class InvalidConfigurationPropertyValueException extends RuntimeException
|
|||
|
||||
private final String reason;
|
||||
|
||||
/**
|
||||
* Creates a new instance for the specified property {@code name} and {@code value},
|
||||
* including a {@code reason} why the value is invalid.
|
||||
* @param name the name of the property in canonical format
|
||||
* @param value the value of the property, can be {@code null}
|
||||
* @param reason a human-readable text that describes why the reason is invalid.
|
||||
* Starts with an upper-case and ends with a dots. Several sentences and carriage
|
||||
* returns are allowed.
|
||||
*/
|
||||
public InvalidConfigurationPropertyValueException(String name, Object value,
|
||||
String reason) {
|
||||
super("Property " + name + " with value '" + value + "' is invalid: " + reason);
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.reason = reason;
|
||||
|
|
|
@ -94,7 +94,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
|
|||
private void appendReason(StringBuilder message,
|
||||
InvalidConfigurationPropertyValueException cause) {
|
||||
if (StringUtils.hasText(cause.getReason())) {
|
||||
message.append(" Validation failed for the following reason\n\n");
|
||||
message.append(" Validation failed for the following reason:\n\n");
|
||||
message.append(cause.getReason());
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter;
|
||||
import org.springframework.boot.origin.Origin;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
|
@ -43,7 +42,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
@Test
|
||||
public void analysisWithNullEnvironment() {
|
||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||
"test.property", "invalid", "this is not valid");
|
||||
"test.property", "invalid", "This is not valid.");
|
||||
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer()
|
||||
.analyze(failure);
|
||||
assertThat(analysis).isNull();
|
||||
|
@ -56,12 +55,12 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
this.environment.getPropertySources()
|
||||
.addFirst(OriginCapablePropertySource.get(source));
|
||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||
"test.property", "invalid", "this is not valid");
|
||||
"test.property", "invalid", "This is not valid.");
|
||||
FailureAnalysis analysis = performAnalysis(failure);
|
||||
assertCommonParts(failure, analysis);
|
||||
assertThat(analysis.getDescription())
|
||||
.contains("Validation failed for the following reason")
|
||||
.contains("this is not valid")
|
||||
.contains("This is not valid.")
|
||||
.doesNotContain("Additionally, this property is also set");
|
||||
}
|
||||
|
||||
|
@ -93,7 +92,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
this.environment.getPropertySources()
|
||||
.addLast(OriginCapablePropertySource.get(another));
|
||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||
"test.property", "invalid", "this is not valid");
|
||||
"test.property", "invalid", "This is not valid.");
|
||||
FailureAnalysis analysis = performAnalysis(failure);
|
||||
assertCommonParts(failure, analysis);
|
||||
assertThat(analysis.getDescription())
|
||||
|
@ -106,7 +105,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
@Test
|
||||
public void analysisWithUnknownKey() {
|
||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||
"test.key.not.defined", "invalid", "this is not valid");
|
||||
"test.key.not.defined", "invalid", "This is not valid.");
|
||||
assertThat(performAnalysis(failure)).isNull();
|
||||
}
|
||||
|
||||
|
@ -123,11 +122,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
InvalidConfigurationPropertyValueException failure) {
|
||||
InvalidConfigurationPropertyValueFailureAnalyzer analyzer = new InvalidConfigurationPropertyValueFailureAnalyzer();
|
||||
analyzer.setEnvironment(this.environment);
|
||||
FailureAnalysis analysis = analyzer.analyze(failure);
|
||||
if (analysis != null) {
|
||||
new LoggingFailureAnalysisReporter().report(analysis);
|
||||
}
|
||||
return analysis;
|
||||
return analyzer.analyze(failure);
|
||||
}
|
||||
|
||||
static class OriginCapablePropertySource<T> extends EnumerablePropertySource<T>
|
||||
|
|
Loading…
Reference in New Issue