Skip to content

Commit 23249cd

Browse files
committed
Added test for SpringProperties setFlag method
Issue: SPR-9014 Issue: SPR-11297
1 parent 341d645 commit 23249cd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
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: 8 additions & 1 deletion
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.
@@ -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)