EnvironmentPropertySource extends BasePropertySource { @Override public PropertyValue get(String key) { if (isDisabled()) { return null; } String effectiveKey = hasPrefix() ? getPrefix() + "." + key : key; String value = getPropertiesProvider().getenv(effectiveKey); if(value==null){ effectiveKey = effectiveKey.replaceAll("\\W", "_"); value = getPropertiesProvider().getenv(effectiveKey); } if(value==null){ effectiveKey = effectiveKey.toUpperCase(); value = getPropertiesProvider().getenv(effectiveKey); } if(value==null){ return null; } return PropertyValue.createValue(key, value).setMeta("source", getName()); } EnvironmentPropertySource();  EnvironmentPropertySource(int ordinal);  EnvironmentPropertySource(String prefix, int ordinal);  EnvironmentPropertySource(String prefix); @Override int getDefaultOrdinal(); @Override String getName(); @Override PropertyValue get(String key); @Override Map<String, PropertyValue> getProperties(); String getPrefix(); boolean isDisabled(); @Override ChangeSupport getChangeSupport(); static final int DEFAULT_ORDINAL; }
@Test public void testSingleCharacterNull() { assertThat(envPropertySource.get("a")).isNull(); }
@Test public void testGet() throws Exception { for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) { assertThat(envEntry.getValue()).isEqualTo(envPropertySource.get(envEntry.getKey()).getValue()); } }