Adapted PropertySourcesPropertyResolverTests for different error message format
This commit is contained in:
parent
5b93b14392
commit
3a09644843
|
|
@ -36,10 +36,14 @@ import static org.junit.Assert.*;
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public class PropertySourcesPropertyResolverTests {
|
public class PropertySourcesPropertyResolverTests {
|
||||||
|
|
||||||
private Properties testProperties;
|
private Properties testProperties;
|
||||||
|
|
||||||
private MutablePropertySources propertySources;
|
private MutablePropertySources propertySources;
|
||||||
|
|
||||||
private ConfigurablePropertyResolver propertyResolver;
|
private ConfigurablePropertyResolver propertyResolver;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
propertySources = new MutablePropertySources();
|
propertySources = new MutablePropertySources();
|
||||||
|
|
@ -48,6 +52,7 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
propertySources.addFirst(new PropertiesPropertySource("testProperties", testProperties));
|
propertySources.addFirst(new PropertiesPropertySource("testProperties", testProperties));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void containsProperty() {
|
public void containsProperty() {
|
||||||
assertThat(propertyResolver.containsProperty("foo"), is(false));
|
assertThat(propertyResolver.containsProperty("foo"), is(false));
|
||||||
|
|
@ -103,7 +108,6 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
assertThat(propertyResolver.getProperty("foo", String[].class), equalTo(new String[] { "bar", "baz" }));
|
assertThat(propertyResolver.getProperty("foo", String[].class), equalTo(new String[] { "bar", "baz" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProperty_withNonConvertibleTargetType() {
|
public void getProperty_withNonConvertibleTargetType() {
|
||||||
testProperties.put("foo", "bar");
|
testProperties.put("foo", "bar");
|
||||||
|
|
@ -113,7 +117,8 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
try {
|
try {
|
||||||
propertyResolver.getProperty("foo", TestType.class);
|
propertyResolver.getProperty("foo", TestType.class);
|
||||||
fail("Expected IllegalArgumentException due to non-convertible types");
|
fail("Expected IllegalArgumentException due to non-convertible types");
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +177,8 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
try {
|
try {
|
||||||
propertyResolver.getRequiredProperty("bogus");
|
propertyResolver.getRequiredProperty("bogus");
|
||||||
fail("expected IllegalStateException");
|
fail("expected IllegalStateException");
|
||||||
} catch (IllegalStateException ex) {
|
}
|
||||||
|
catch (IllegalStateException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +191,8 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
try {
|
try {
|
||||||
propertyResolver.getRequiredProperty("bogus", String[].class);
|
propertyResolver.getRequiredProperty("bogus", String[].class);
|
||||||
fail("expected IllegalStateException");
|
fail("expected IllegalStateException");
|
||||||
} catch (IllegalStateException ex) {
|
}
|
||||||
|
catch (IllegalStateException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -327,7 +334,8 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
try {
|
try {
|
||||||
propertyResolver.validateRequiredProperties();
|
propertyResolver.validateRequiredProperties();
|
||||||
fail("expected validation exception");
|
fail("expected validation exception");
|
||||||
} catch (MissingRequiredPropertiesException ex) {
|
}
|
||||||
|
catch (MissingRequiredPropertiesException ex) {
|
||||||
assertThat(ex.getMessage(), equalTo(
|
assertThat(ex.getMessage(), equalTo(
|
||||||
"The following properties were declared as required " +
|
"The following properties were declared as required " +
|
||||||
"but could not be resolved: [foo, bar]"));
|
"but could not be resolved: [foo, bar]"));
|
||||||
|
|
@ -338,7 +346,8 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
try {
|
try {
|
||||||
propertyResolver.validateRequiredProperties();
|
propertyResolver.validateRequiredProperties();
|
||||||
fail("expected validation exception");
|
fail("expected validation exception");
|
||||||
} catch (MissingRequiredPropertiesException ex) {
|
}
|
||||||
|
catch (MissingRequiredPropertiesException ex) {
|
||||||
assertThat(ex.getMessage(), equalTo(
|
assertThat(ex.getMessage(), equalTo(
|
||||||
"The following properties were declared as required " +
|
"The following properties were declared as required " +
|
||||||
"but could not be resolved: [bar]"));
|
"but could not be resolved: [bar]"));
|
||||||
|
|
@ -369,14 +378,16 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
assertThat(pr.getProperty("p4"), equalTo("v1:v2"));
|
assertThat(pr.getProperty("p4"), equalTo("v1:v2"));
|
||||||
try {
|
try {
|
||||||
pr.getProperty("p5");
|
pr.getProperty("p5");
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
assertThat(ex.getMessage(), containsString(
|
assertThat(ex.getMessage(), containsString(
|
||||||
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
|
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
|
||||||
}
|
}
|
||||||
assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
|
assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
|
||||||
try {
|
try {
|
||||||
pr.getProperty("pL");
|
pr.getProperty("pL");
|
||||||
} catch (StackOverflowError ex) {
|
}
|
||||||
|
catch (StackOverflowError ex) {
|
||||||
// no explicit handling for cyclic references for now
|
// no explicit handling for cyclic references for now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -399,9 +410,10 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
// exception by default
|
// exception by default
|
||||||
try {
|
try {
|
||||||
pr.getProperty("p4");
|
pr.getProperty("p4");
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
assertThat(ex.getMessage(), containsString(
|
assertThat(ex.getMessage(), containsString(
|
||||||
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
|
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
// relax the treatment of unresolvable nested placeholders
|
// relax the treatment of unresolvable nested placeholders
|
||||||
|
|
@ -414,13 +426,18 @@ public class PropertySourcesPropertyResolverTests {
|
||||||
assertThat(pr.resolvePlaceholders("${p1}:${p2}:${bogus}"), equalTo("v1:v2:${bogus}"));
|
assertThat(pr.resolvePlaceholders("${p1}:${p2}:${bogus}"), equalTo("v1:v2:${bogus}"));
|
||||||
try {
|
try {
|
||||||
pr.resolveRequiredPlaceholders("${p1}:${p2}:${bogus}");
|
pr.resolveRequiredPlaceholders("${p1}:${p2}:${bogus}");
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
assertThat(ex.getMessage(), containsString(
|
assertThat(ex.getMessage(), containsString(
|
||||||
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
|
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static interface SomeType { }
|
interface SomeType {
|
||||||
static class SpecificType implements SomeType { }
|
}
|
||||||
|
|
||||||
|
static class SpecificType implements SomeType {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue