Skip to content

Commit cebda46

Browse files
committed
Polish PropertyPlaceholderConfigurerTests
1 parent f01fb19 commit cebda46

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurerTests.java

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -37,46 +37,42 @@
3737
* Unit tests for {@link PropertyPlaceholderConfigurer}.
3838
*
3939
* @author Chris Beams
40+
* @author Sam Brannen
4041
*/
4142
@SuppressWarnings("deprecation")
42-
public class PropertyPlaceholderConfigurerTests {
43+
class PropertyPlaceholderConfigurerTests {
4344

4445
private static final String P1 = "p1";
4546
private static final String P1_LOCAL_PROPS_VAL = "p1LocalPropsVal";
4647
private static final String P1_SYSTEM_PROPS_VAL = "p1SystemPropsVal";
4748

48-
private DefaultListableBeanFactory bf;
49-
private PropertyPlaceholderConfigurer ppc;
50-
private Properties ppcProperties;
49+
private final DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
5150

52-
private AbstractBeanDefinition p1BeanDef;
51+
private final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
5352

53+
private final Properties ppcProperties = new Properties();
5454

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();
6058

61-
bf = new DefaultListableBeanFactory();
6259

63-
ppcProperties = new Properties();
60+
@BeforeEach
61+
void setup() {
6462
ppcProperties.setProperty(P1, P1_LOCAL_PROPS_VAL);
6563
System.setProperty(P1, P1_SYSTEM_PROPS_VAL);
66-
ppc = new PropertyPlaceholderConfigurer();
6764
ppc.setProperties(ppcProperties);
68-
6965
}
7066

7167
@AfterEach
72-
public void cleanup() {
68+
void cleanup() {
7369
System.clearProperty(P1);
70+
System.clearProperty(P1_SYSTEM_PROPS_VAL);
7471
}
7572

7673

7774
@Test
78-
public void localPropertiesViaResource() {
79-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
75+
void localPropertiesViaResource() {
8076
bf.registerBeanDefinition("testBean",
8177
genericBeanDefinition(TestBean.class)
8278
.addPropertyValue("name", "${my.name}")
@@ -89,7 +85,7 @@ public void localPropertiesViaResource() {
8985
}
9086

9187
@Test
92-
public void resolveFromSystemProperties() {
88+
void resolveFromSystemProperties() {
9389
System.setProperty("otherKey", "systemValue");
9490
p1BeanDef = rootBeanDefinition(TestBean.class)
9591
.addPropertyValue("name", "${" + P1 + "}")
@@ -104,7 +100,7 @@ public void resolveFromSystemProperties() {
104100
}
105101

106102
@Test
107-
public void resolveFromLocalProperties() {
103+
void resolveFromLocalProperties() {
108104
System.clearProperty(P1);
109105
registerWithGeneratedName(p1BeanDef, bf);
110106
ppc.postProcessBeanFactory(bf);
@@ -113,15 +109,15 @@ public void resolveFromLocalProperties() {
113109
}
114110

115111
@Test
116-
public void setSystemPropertiesMode_defaultIsFallback() {
112+
void setSystemPropertiesMode_defaultIsFallback() {
117113
registerWithGeneratedName(p1BeanDef, bf);
118114
ppc.postProcessBeanFactory(bf);
119115
TestBean bean = bf.getBean(TestBean.class);
120116
assertThat(bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
121117
}
122118

123119
@Test
124-
public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties() {
120+
void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties() {
125121
registerWithGeneratedName(p1BeanDef, bf);
126122
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
127123
ppc.postProcessBeanFactory(bf);
@@ -130,7 +126,7 @@ public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemPropert
130126
}
131127

132128
@Test
133-
public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse() {
129+
void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse() {
134130
registerWithGeneratedName(p1BeanDef, bf);
135131
System.clearProperty(P1); // will now fall all the way back to system environment
136132
ppc.setSearchSystemEnvironment(false);
@@ -145,7 +141,7 @@ public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironme
145141
* settings regarding resolving properties from the environment.
146142
*/
147143
@Test
148-
public void twoPlaceholderConfigurers_withConflictingSettings() {
144+
void twoPlaceholderConfigurers_withConflictingSettings() {
149145
String P2 = "p2";
150146
String P2_LOCAL_PROPS_VAL = "p2LocalPropsVal";
151147
String P2_SYSTEM_PROPS_VAL = "p2SystemPropsVal";
@@ -184,12 +180,10 @@ public void twoPlaceholderConfigurers_withConflictingSettings() {
184180
}
185181

186182
@Test
187-
public void customPlaceholderPrefixAndSuffix() {
188-
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
183+
void customPlaceholderPrefixAndSuffix() {
189184
ppc.setPlaceholderPrefix("@<");
190185
ppc.setPlaceholderSuffix(">");
191186

192-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
193187
bf.registerBeanDefinition("testBean",
194188
rootBeanDefinition(TestBean.class)
195189
.addPropertyValue("name", "@<key1>")
@@ -207,11 +201,9 @@ public void customPlaceholderPrefixAndSuffix() {
207201
}
208202

209203
@Test
210-
public void nullValueIsPreserved() {
211-
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
204+
void nullValueIsPreserved() {
212205
ppc.setNullValue("customNull");
213206
System.setProperty("my.name", "customNull");
214-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
215207
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
216208
.addPropertyValue("name", "${my.name}")
217209
.getBeanDefinition());
@@ -221,10 +213,8 @@ public void nullValueIsPreserved() {
221213
}
222214

223215
@Test
224-
public void trimValuesIsOffByDefault() {
225-
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
216+
void trimValuesIsOffByDefault() {
226217
System.setProperty("my.name", " myValue ");
227-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
228218
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
229219
.addPropertyValue("name", "${my.name}")
230220
.getBeanDefinition());
@@ -234,11 +224,9 @@ public void trimValuesIsOffByDefault() {
234224
}
235225

236226
@Test
237-
public void trimValuesIsApplied() {
238-
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
227+
void trimValuesIsApplied() {
239228
ppc.setTrimValues(true);
240229
System.setProperty("my.name", " myValue ");
241-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
242230
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
243231
.addPropertyValue("name", "${my.name}")
244232
.getBeanDefinition());

0 commit comments

Comments
 (0)