Skip to content

Commit 167329c

Browse files
committed
Added test for SpringProperties setFlag method
Issue: SPR-9014 Issue: SPR-11297 (cherry picked from commit 23249cd)
1 parent 2dcbf4d commit 167329c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

spring-core/src/main/java/org/springframework/core/SpringProperties.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -44,6 +44,8 @@
4444
*/
4545
public abstract class SpringProperties {
4646

47+
private static final String PROPERTIES_RESOURCE_LOCATION = "spring.properties";
48+
4749
private static final Log logger = LogFactory.getLog(SpringProperties.class);
4850

4951
private static final Properties localProperties = new Properties();
@@ -52,7 +54,7 @@ public abstract class SpringProperties {
5254
static {
5355
try {
5456
ClassLoader cl = SpringProperties.class.getClassLoader();
55-
URL url = cl.getResource("spring.properties");
57+
URL url = cl.getResource(PROPERTIES_RESOURCE_LOCATION);
5658
if (url != null) {
5759
logger.info("Found 'spring.properties' file in local classpath");
5860
InputStream is = url.openStream();

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -59,15 +59,15 @@ public void merge() {
5959
child.setActiveProfiles("c1", "c2");
6060
child.getPropertySources().addLast(
6161
new MockPropertySource("childMock")
62-
.withProperty("childKey", "childVal")
63-
.withProperty("bothKey", "childBothVal"));
62+
.withProperty("childKey", "childVal")
63+
.withProperty("bothKey", "childBothVal"));
6464

6565
ConfigurableEnvironment parent = new StandardEnvironment();
6666
parent.setActiveProfiles("p1", "p2");
6767
parent.getPropertySources().addLast(
6868
new MockPropertySource("parentMock")
69-
.withProperty("parentKey", "parentVal")
70-
.withProperty("bothKey", "parentBothVal"));
69+
.withProperty("parentKey", "parentVal")
70+
.withProperty("bothKey", "parentBothVal"));
7171

7272
assertThat(child.getProperty("childKey"), is("childVal"));
7373
assertThat(child.getProperty("parentKey"), nullValue());
@@ -354,6 +354,13 @@ public void suppressGetenvAccessThroughSpringProperty() {
354354
SpringProperties.setProperty("spring.getenv.ignore", null);
355355
}
356356

357+
@Test
358+
public void suppressGetenvAccessThroughSpringFlag() {
359+
SpringProperties.setFlag("spring.getenv.ignore");
360+
assertTrue(environment.getSystemEnvironment().isEmpty());
361+
SpringProperties.setProperty("spring.getenv.ignore", null);
362+
}
363+
357364
@Test
358365
public void getSystemProperties_withAndWithoutSecurityManager() {
359366
System.setProperty(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);

0 commit comments

Comments
 (0)