Resolve or eliminate Environment-related TODOs

Issue: SPR-8031, SPR-7508
This commit is contained in:
Chris Beams
2011-03-15 12:57:12 +00:00
parent d471266d44
commit b50ac7489b
7 changed files with 34 additions and 18 deletions

View File

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

View File

@@ -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));