1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2023 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.
37
37
* Unit tests for {@link PropertyPlaceholderConfigurer}.
38
38
*
39
39
* @author Chris Beams
40
+ * @author Sam Brannen
40
41
*/
41
42
@ SuppressWarnings ("deprecation" )
42
- public class PropertyPlaceholderConfigurerTests {
43
+ class PropertyPlaceholderConfigurerTests {
43
44
44
45
private static final String P1 = "p1" ;
45
46
private static final String P1_LOCAL_PROPS_VAL = "p1LocalPropsVal" ;
46
47
private static final String P1_SYSTEM_PROPS_VAL = "p1SystemPropsVal" ;
47
48
48
- private DefaultListableBeanFactory bf ;
49
- private PropertyPlaceholderConfigurer ppc ;
50
- private Properties ppcProperties ;
49
+ private final DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
51
50
52
- private AbstractBeanDefinition p1BeanDef ;
51
+ private final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer () ;
53
52
53
+ private final Properties ppcProperties = new Properties ();
54
54
55
- @ BeforeEach
56
- public void setup () {
57
- p1BeanDef = rootBeanDefinition (TestBean .class )
58
- .addPropertyValue ("name" , "${" + P1 + "}" )
59
- .getBeanDefinition ();
55
+ private AbstractBeanDefinition p1BeanDef = rootBeanDefinition (TestBean .class )
56
+ .addPropertyValue ("name" , "${" + P1 + "}" )
57
+ .getBeanDefinition ();
60
58
61
- bf = new DefaultListableBeanFactory ();
62
59
63
- ppcProperties = new Properties ();
60
+ @ BeforeEach
61
+ void setup () {
64
62
ppcProperties .setProperty (P1 , P1_LOCAL_PROPS_VAL );
65
63
System .setProperty (P1 , P1_SYSTEM_PROPS_VAL );
66
- ppc = new PropertyPlaceholderConfigurer ();
67
64
ppc .setProperties (ppcProperties );
68
-
69
65
}
70
66
71
67
@ AfterEach
72
- public void cleanup () {
68
+ void cleanup () {
73
69
System .clearProperty (P1 );
70
+ System .clearProperty (P1_SYSTEM_PROPS_VAL );
74
71
}
75
72
76
73
77
74
@ Test
78
- public void localPropertiesViaResource () {
79
- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
75
+ void localPropertiesViaResource () {
80
76
bf .registerBeanDefinition ("testBean" ,
81
77
genericBeanDefinition (TestBean .class )
82
78
.addPropertyValue ("name" , "${my.name}" )
@@ -89,7 +85,7 @@ public void localPropertiesViaResource() {
89
85
}
90
86
91
87
@ Test
92
- public void resolveFromSystemProperties () {
88
+ void resolveFromSystemProperties () {
93
89
System .setProperty ("otherKey" , "systemValue" );
94
90
p1BeanDef = rootBeanDefinition (TestBean .class )
95
91
.addPropertyValue ("name" , "${" + P1 + "}" )
@@ -104,7 +100,7 @@ public void resolveFromSystemProperties() {
104
100
}
105
101
106
102
@ Test
107
- public void resolveFromLocalProperties () {
103
+ void resolveFromLocalProperties () {
108
104
System .clearProperty (P1 );
109
105
registerWithGeneratedName (p1BeanDef , bf );
110
106
ppc .postProcessBeanFactory (bf );
@@ -113,15 +109,15 @@ public void resolveFromLocalProperties() {
113
109
}
114
110
115
111
@ Test
116
- public void setSystemPropertiesMode_defaultIsFallback () {
112
+ void setSystemPropertiesMode_defaultIsFallback () {
117
113
registerWithGeneratedName (p1BeanDef , bf );
118
114
ppc .postProcessBeanFactory (bf );
119
115
TestBean bean = bf .getBean (TestBean .class );
120
116
assertThat (bean .getName ()).isEqualTo (P1_LOCAL_PROPS_VAL );
121
117
}
122
118
123
119
@ Test
124
- public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties () {
120
+ void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties () {
125
121
registerWithGeneratedName (p1BeanDef , bf );
126
122
ppc .setSystemPropertiesMode (PropertyPlaceholderConfigurer .SYSTEM_PROPERTIES_MODE_OVERRIDE );
127
123
ppc .postProcessBeanFactory (bf );
@@ -130,7 +126,7 @@ public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemPropert
130
126
}
131
127
132
128
@ Test
133
- public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse () {
129
+ void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse () {
134
130
registerWithGeneratedName (p1BeanDef , bf );
135
131
System .clearProperty (P1 ); // will now fall all the way back to system environment
136
132
ppc .setSearchSystemEnvironment (false );
@@ -145,7 +141,7 @@ public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironme
145
141
* settings regarding resolving properties from the environment.
146
142
*/
147
143
@ Test
148
- public void twoPlaceholderConfigurers_withConflictingSettings () {
144
+ void twoPlaceholderConfigurers_withConflictingSettings () {
149
145
String P2 = "p2" ;
150
146
String P2_LOCAL_PROPS_VAL = "p2LocalPropsVal" ;
151
147
String P2_SYSTEM_PROPS_VAL = "p2SystemPropsVal" ;
@@ -184,12 +180,10 @@ public void twoPlaceholderConfigurers_withConflictingSettings() {
184
180
}
185
181
186
182
@ Test
187
- public void customPlaceholderPrefixAndSuffix () {
188
- PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer ();
183
+ void customPlaceholderPrefixAndSuffix () {
189
184
ppc .setPlaceholderPrefix ("@<" );
190
185
ppc .setPlaceholderSuffix (">" );
191
186
192
- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
193
187
bf .registerBeanDefinition ("testBean" ,
194
188
rootBeanDefinition (TestBean .class )
195
189
.addPropertyValue ("name" , "@<key1>" )
@@ -207,11 +201,9 @@ public void customPlaceholderPrefixAndSuffix() {
207
201
}
208
202
209
203
@ Test
210
- public void nullValueIsPreserved () {
211
- PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer ();
204
+ void nullValueIsPreserved () {
212
205
ppc .setNullValue ("customNull" );
213
206
System .setProperty ("my.name" , "customNull" );
214
- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
215
207
bf .registerBeanDefinition ("testBean" , rootBeanDefinition (TestBean .class )
216
208
.addPropertyValue ("name" , "${my.name}" )
217
209
.getBeanDefinition ());
@@ -221,10 +213,8 @@ public void nullValueIsPreserved() {
221
213
}
222
214
223
215
@ Test
224
- public void trimValuesIsOffByDefault () {
225
- PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer ();
216
+ void trimValuesIsOffByDefault () {
226
217
System .setProperty ("my.name" , " myValue " );
227
- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
228
218
bf .registerBeanDefinition ("testBean" , rootBeanDefinition (TestBean .class )
229
219
.addPropertyValue ("name" , "${my.name}" )
230
220
.getBeanDefinition ());
@@ -234,11 +224,9 @@ public void trimValuesIsOffByDefault() {
234
224
}
235
225
236
226
@ Test
237
- public void trimValuesIsApplied () {
238
- PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer ();
227
+ void trimValuesIsApplied () {
239
228
ppc .setTrimValues (true );
240
229
System .setProperty ("my.name" , " myValue " );
241
- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
242
230
bf .registerBeanDefinition ("testBean" , rootBeanDefinition (TestBean .class )
243
231
.addPropertyValue ("name" , "${my.name}" )
244
232
.getBeanDefinition ());
0 commit comments