1
1
/*
2
- * Copyright 2002-2010 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
public class ResourceEditorTests {
35
35
36
36
@ Test
37
- public void sunnyDay () throws Exception {
37
+ public void sunnyDay () {
38
38
PropertyEditor editor = new ResourceEditor ();
39
39
editor .setAsText ("classpath:org/springframework/core/io/ResourceEditorTests.class" );
40
40
Resource resource = (Resource ) editor .getValue ();
@@ -43,26 +43,40 @@ public void sunnyDay() throws Exception {
43
43
}
44
44
45
45
@ Test (expected = IllegalArgumentException .class )
46
- public void ctorWithNullCtorArgs () throws Exception {
46
+ public void ctorWithNullCtorArgs () {
47
47
new ResourceEditor (null , null );
48
48
}
49
49
50
50
@ Test
51
- public void setAndGetAsTextWithNull () throws Exception {
51
+ public void setAndGetAsTextWithNull () {
52
52
PropertyEditor editor = new ResourceEditor ();
53
53
editor .setAsText (null );
54
54
assertEquals ("" , editor .getAsText ());
55
55
}
56
56
57
57
@ Test
58
- public void setAndGetAsTextWithWhitespaceResource () throws Exception {
58
+ public void setAndGetAsTextWithWhitespaceResource () {
59
59
PropertyEditor editor = new ResourceEditor ();
60
60
editor .setAsText (" " );
61
61
assertEquals ("" , editor .getAsText ());
62
62
}
63
63
64
64
@ Test
65
65
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 () {
66
80
PropertyEditor editor = new ResourceEditor ();
67
81
System .setProperty ("test.prop" , "foo" );
68
82
try {
@@ -76,13 +90,11 @@ public void testSystemPropertyReplacement() {
76
90
}
77
91
78
92
@ Test (expected = IllegalArgumentException .class )
79
- public void testStrictSystemPropertyReplacement () {
93
+ public void testStrictSystemPropertyReplacementWithUnresolvablePlaceholder () {
80
94
PropertyEditor editor = new ResourceEditor (new DefaultResourceLoader (), new StandardEnvironment (), false );
81
95
System .setProperty ("test.prop" , "foo" );
82
96
try {
83
97
editor .setAsText ("${test.prop}-${bar}" );
84
- Resource resolved = (Resource ) editor .getValue ();
85
- assertEquals ("foo-${bar}" , resolved .getFilename ());
86
98
}
87
99
finally {
88
100
System .getProperties ().remove ("test.prop" );
0 commit comments