SystemEnvironmentPropertySource uses actual SecurityManager check and direct keySet access

Issue: SPR-12224
This commit is contained in:
Juergen Hoeller
2014-09-24 17:56:38 +02:00
parent 0934751d7a
commit 587a81617c
2 changed files with 42 additions and 39 deletions

View File

@@ -17,7 +17,9 @@
package org.springframework.core.env;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
@@ -29,19 +31,23 @@ import static org.junit.Assert.*;
* Unit tests for {@link SystemEnvironmentPropertySource}.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
*/
public class SystemEnvironmentPropertySourceTests {
private Map<String, Object> envMap;
private PropertySource<?> ps;
@Before
public void setUp() {
envMap = new HashMap<String, Object>();
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);
}
@Test
public void none() {
assertThat(ps.containsProperty("a.key"), equalTo(false));
@@ -107,9 +113,20 @@ public class SystemEnvironmentPropertySourceTests {
public boolean containsKey(Object key) {
throw new UnsupportedOperationException();
}
@Override
public Set<String> keySet() {
return new HashSet<String>(super.keySet());
}
};
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);
envMap.put("A_KEY", "a_value");
ps = new SystemEnvironmentPropertySource("sysEnv", envMap) {
@Override
protected boolean isSecurityManagerPresent() {
return true;
}
};
assertThat(ps.containsProperty("A_KEY"), equalTo(true));
assertThat(ps.getProperty("A_KEY"), equalTo((Object)"a_value"));
}