Resolve or eliminate Environment-related TODOs
Issue: SPR-8031, SPR-7508
This commit is contained in:
@@ -41,7 +41,6 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultEnvironment}.
|
||||
*
|
||||
@@ -230,7 +229,7 @@ public class EnvironmentTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSystemEnvironment_withAndWithoutSecurityManager() throws Exception {
|
||||
public void getSystemEnvironment_withAndWithoutSecurityManager() {
|
||||
getModifiableSystemEnvironment().put(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);
|
||||
getModifiableSystemEnvironment().put(DISALLOWED_PROPERTY_NAME, DISALLOWED_PROPERTY_VALUE);
|
||||
|
||||
@@ -270,17 +269,20 @@ public class EnvironmentTests {
|
||||
getModifiableSystemEnvironment().remove(DISALLOWED_PROPERTY_NAME);
|
||||
}
|
||||
|
||||
// TODO SPR-7508: duplicated from EnvironmentPropertyResolutionSearchTests
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String> getModifiableSystemEnvironment() throws Exception {
|
||||
private static Map<String, String> getModifiableSystemEnvironment() {
|
||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||
Map<String, String> systemEnv = System.getenv();
|
||||
Map<String, String> env = System.getenv();
|
||||
for (Class<?> cl : classes) {
|
||||
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
||||
Field field = cl.getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
Object obj = field.get(systemEnv);
|
||||
return (Map<String, String>) obj;
|
||||
try {
|
||||
Field field = cl.getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
Object obj = field.get(env);
|
||||
return (Map<String, String>) obj;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
|
||||
@@ -72,7 +72,6 @@ public class PropertySourceTests {
|
||||
assertThat(propertySources.contains(ps1), is(true));
|
||||
assertThat(propertySources.contains(PropertySource.named("ps1")), is(true));
|
||||
|
||||
// TODO SPR-7508: consider disallowing duplicates somehow (in the actual data structure used by environment)
|
||||
PropertySource<?> ps1replacement = new MapPropertySource("ps1", map2); // notice - different map
|
||||
assertThat(propertySources.add(ps1replacement), is(true)); // true because linkedlist allows duplicates
|
||||
assertThat(propertySources.size(), is(2));
|
||||
|
||||
Reference in New Issue
Block a user