Skip to content

Commit 55e601c

Browse files
committed
Revise system property replacement tests
See gh-22959
1 parent 515d627 commit 55e601c

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
public class ResourceEditorTests {
3535

3636
@Test
37-
public void sunnyDay() throws Exception {
37+
public void sunnyDay() {
3838
PropertyEditor editor = new ResourceEditor();
3939
editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
4040
Resource resource = (Resource) editor.getValue();
@@ -43,26 +43,40 @@ public void sunnyDay() throws Exception {
4343
}
4444

4545
@Test(expected = IllegalArgumentException.class)
46-
public void ctorWithNullCtorArgs() throws Exception {
46+
public void ctorWithNullCtorArgs() {
4747
new ResourceEditor(null, null);
4848
}
4949

5050
@Test
51-
public void setAndGetAsTextWithNull() throws Exception {
51+
public void setAndGetAsTextWithNull() {
5252
PropertyEditor editor = new ResourceEditor();
5353
editor.setAsText(null);
5454
assertEquals("", editor.getAsText());
5555
}
5656

5757
@Test
58-
public void setAndGetAsTextWithWhitespaceResource() throws Exception {
58+
public void setAndGetAsTextWithWhitespaceResource() {
5959
PropertyEditor editor = new ResourceEditor();
6060
editor.setAsText(" ");
6161
assertEquals("", editor.getAsText());
6262
}
6363

6464
@Test
6565
public void testSystemPropertyReplacement() {
66+
PropertyEditor editor = new ResourceEditor();
67+
System.setProperty("test.prop", "foo");
68+
try {
69+
editor.setAsText("${test.prop}");
70+
Resource resolved = (Resource) editor.getValue();
71+
assertEquals("foo", resolved.getFilename());
72+
}
73+
finally {
74+
System.getProperties().remove("test.prop");
75+
}
76+
}
77+
78+
@Test
79+
public void testSystemPropertyReplacementWithUnresolvablePlaceholder() {
6680
PropertyEditor editor = new ResourceEditor();
6781
System.setProperty("test.prop", "foo");
6882
try {
@@ -76,13 +90,11 @@ public void testSystemPropertyReplacement() {
7690
}
7791

7892
@Test(expected = IllegalArgumentException.class)
79-
public void testStrictSystemPropertyReplacement() {
93+
public void testStrictSystemPropertyReplacementWithUnresolvablePlaceholder() {
8094
PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
8195
System.setProperty("test.prop", "foo");
8296
try {
8397
editor.setAsText("${test.prop}-${bar}");
84-
Resource resolved = (Resource) editor.getValue();
85-
assertEquals("foo-${bar}", resolved.getFilename());
8698
}
8799
finally {
88100
System.getProperties().remove("test.prop");

spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
public class ResourceArrayPropertyEditorTests {
3333

3434
@Test
35-
public void testVanillaResource() throws Exception {
35+
public void testVanillaResource() {
3636
PropertyEditor editor = new ResourceArrayPropertyEditor();
3737
editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
3838
Resource[] resources = (Resource[]) editor.getValue();
@@ -41,7 +41,7 @@ public void testVanillaResource() throws Exception {
4141
}
4242

4343
@Test
44-
public void testPatternResource() throws Exception {
44+
public void testPatternResource() {
4545
// N.B. this will sometimes fail if you use classpath: instead of classpath*:.
4646
// The result depends on the classpath - if test-classes are segregated from classes
4747
// and they come first on the classpath (like in Maven) then it breaks, if classes
@@ -58,25 +58,23 @@ public void testSystemPropertyReplacement() {
5858
PropertyEditor editor = new ResourceArrayPropertyEditor();
5959
System.setProperty("test.prop", "foo");
6060
try {
61-
editor.setAsText("${test.prop}-${bar}");
61+
editor.setAsText("${test.prop}");
6262
Resource[] resources = (Resource[]) editor.getValue();
63-
assertEquals("foo-${bar}", resources[0].getFilename());
63+
assertEquals("foo", resources[0].getFilename());
6464
}
6565
finally {
6666
System.getProperties().remove("test.prop");
6767
}
6868
}
6969

7070
@Test(expected = IllegalArgumentException.class)
71-
public void testStrictSystemPropertyReplacement() {
71+
public void testStrictSystemPropertyReplacementWithUnresolvablePlaceholder() {
7272
PropertyEditor editor = new ResourceArrayPropertyEditor(
7373
new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
7474
false);
7575
System.setProperty("test.prop", "foo");
7676
try {
7777
editor.setAsText("${test.prop}-${bar}");
78-
Resource[] resources = (Resource[]) editor.getValue();
79-
assertEquals("foo-${bar}", resources[0].getFilename());
8078
}
8179
finally {
8280
System.getProperties().remove("test.prop");

0 commit comments

Comments
 (0)