Skip to content

Commit 3a09644

Browse files
jhoellerunknown
authored and
unknown
committed
Adapted PropertySourcesPropertyResolverTests for different error message format
1 parent 5b93b14 commit 3a09644

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

spring-core/src/test/java/org/springframework/core/env/PropertySourcesPropertyResolverTests.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@
3636
* @since 3.1
3737
*/
3838
public class PropertySourcesPropertyResolverTests {
39+
3940
private Properties testProperties;
41+
4042
private MutablePropertySources propertySources;
43+
4144
private ConfigurablePropertyResolver propertyResolver;
4245

46+
4347
@Before
4448
public void setUp() {
4549
propertySources = new MutablePropertySources();
@@ -48,6 +52,7 @@ public void setUp() {
4852
propertySources.addFirst(new PropertiesPropertySource("testProperties", testProperties));
4953
}
5054

55+
5156
@Test
5257
public void containsProperty() {
5358
assertThat(propertyResolver.containsProperty("foo"), is(false));
@@ -103,7 +108,6 @@ public void getProperty_withStringArrayConversion() {
103108
assertThat(propertyResolver.getProperty("foo", String[].class), equalTo(new String[] { "bar", "baz" }));
104109
}
105110

106-
107111
@Test
108112
public void getProperty_withNonConvertibleTargetType() {
109113
testProperties.put("foo", "bar");
@@ -113,7 +117,8 @@ class TestType { }
113117
try {
114118
propertyResolver.getProperty("foo", TestType.class);
115119
fail("Expected IllegalArgumentException due to non-convertible types");
116-
} catch (IllegalArgumentException ex) {
120+
}
121+
catch (IllegalArgumentException ex) {
117122
// expected
118123
}
119124
}
@@ -172,7 +177,8 @@ public void getRequiredProperty() {
172177
try {
173178
propertyResolver.getRequiredProperty("bogus");
174179
fail("expected IllegalStateException");
175-
} catch (IllegalStateException ex) {
180+
}
181+
catch (IllegalStateException ex) {
176182
// expected
177183
}
178184
}
@@ -185,7 +191,8 @@ public void getRequiredProperty_withStringArrayConversion() {
185191
try {
186192
propertyResolver.getRequiredProperty("bogus", String[].class);
187193
fail("expected IllegalStateException");
188-
} catch (IllegalStateException ex) {
194+
}
195+
catch (IllegalStateException ex) {
189196
// expected
190197
}
191198
}
@@ -327,7 +334,8 @@ public void setRequiredProperties_andValidateRequiredProperties() {
327334
try {
328335
propertyResolver.validateRequiredProperties();
329336
fail("expected validation exception");
330-
} catch (MissingRequiredPropertiesException ex) {
337+
}
338+
catch (MissingRequiredPropertiesException ex) {
331339
assertThat(ex.getMessage(), equalTo(
332340
"The following properties were declared as required " +
333341
"but could not be resolved: [foo, bar]"));
@@ -338,7 +346,8 @@ public void setRequiredProperties_andValidateRequiredProperties() {
338346
try {
339347
propertyResolver.validateRequiredProperties();
340348
fail("expected validation exception");
341-
} catch (MissingRequiredPropertiesException ex) {
349+
}
350+
catch (MissingRequiredPropertiesException ex) {
342351
assertThat(ex.getMessage(), equalTo(
343352
"The following properties were declared as required " +
344353
"but could not be resolved: [bar]"));
@@ -369,14 +378,16 @@ public void resolveNestedPropertyPlaceholders() {
369378
assertThat(pr.getProperty("p4"), equalTo("v1:v2"));
370379
try {
371380
pr.getProperty("p5");
372-
} catch (IllegalArgumentException ex) {
381+
}
382+
catch (IllegalArgumentException ex) {
373383
assertThat(ex.getMessage(), containsString(
374-
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
384+
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
375385
}
376386
assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
377387
try {
378388
pr.getProperty("pL");
379-
} catch (StackOverflowError ex) {
389+
}
390+
catch (StackOverflowError ex) {
380391
// no explicit handling for cyclic references for now
381392
}
382393
}
@@ -399,9 +410,10 @@ public void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
399410
// exception by default
400411
try {
401412
pr.getProperty("p4");
402-
} catch (IllegalArgumentException ex) {
413+
}
414+
catch (IllegalArgumentException ex) {
403415
assertThat(ex.getMessage(), containsString(
404-
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
416+
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
405417
}
406418

407419
// relax the treatment of unresolvable nested placeholders
@@ -414,13 +426,18 @@ public void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
414426
assertThat(pr.resolvePlaceholders("${p1}:${p2}:${bogus}"), equalTo("v1:v2:${bogus}"));
415427
try {
416428
pr.resolveRequiredPlaceholders("${p1}:${p2}:${bogus}");
417-
} catch (IllegalArgumentException ex) {
429+
}
430+
catch (IllegalArgumentException ex) {
418431
assertThat(ex.getMessage(), containsString(
419-
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
432+
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
420433
}
421434
}
422435

423436

424-
static interface SomeType { }
425-
static class SpecificType implements SomeType { }
437+
interface SomeType {
438+
}
439+
440+
static class SpecificType implements SomeType {
441+
}
442+
426443
}

0 commit comments

Comments
 (0)