### Question:
SubstitutionPropertiesProvider extends CompositePropertiesProvider { @Override public Object getProperty(String key) { return getProperty(key, null); } SubstitutionPropertiesProvider(PropertiesProvider... delegates); @Override Object getProperty(String key); @Override Object getProperty(String key, Object defaultValue);  }### Answer:
@Test public void testGetProperty() throws Exception { SubstitutionPropertiesProvider provider = new SubstitutionPropertiesProvider(new MapPropertiesProvider(config)); Assert.assertEquals(null, provider.getProperty("")); Assert.assertEquals("value1", provider.getProperty("key1")); Assert.assertEquals("value2", provider.getProperty("key3")); Assert.assertEquals("value1-value2", provider.getProperty("key6")); Assert.assertEquals("value1-", provider.getProperty("key7")); Assert.assertEquals(null, provider.getProperty("key5")); Assert.assertEquals(null, provider.getProperty("env1")); Assert.assertEquals(null, provider.getProperty("env2")); }
@Test public void testWithSystemProperties() throws Exception { SubstitutionPropertiesProvider provider = new SubstitutionPropertiesProvider(new MapPropertiesProvider(config), new SystemPropertiesProvider()); Assert.assertEquals(null, provider.getProperty("")); Assert.assertEquals("value1", provider.getProperty("key1")); Assert.assertEquals("value2", provider.getProperty("key3")); Assert.assertEquals("value1-value2", provider.getProperty("key6")); Assert.assertEquals("value1-", provider.getProperty("key7")); Assert.assertEquals(null, provider.getProperty("key5")); Assert.assertEquals("system.value1", provider.getProperty("env1")); Assert.assertEquals(null, provider.getProperty("env2")); }
@Test public void testWithSystemAndEnvProperties() throws Exception { SubstitutionPropertiesProvider provider = new SubstitutionPropertiesProvider(new MapPropertiesProvider(config), new SystemPropertiesProvider(), new EnvPropertiesProvider()); Assert.assertEquals(null, provider.getProperty("")); Assert.assertEquals("value1", provider.getProperty("key1")); Assert.assertEquals("value2", provider.getProperty("key3")); Assert.assertEquals("value1-value2", provider.getProperty("key6")); Assert.assertEquals("value1-", provider.getProperty("key7")); Assert.assertEquals(null, provider.getProperty("key5")); Assert.assertEquals("system.value1", provider.getProperty("env1")); Assert.assertEquals("gravia.value2", provider.getProperty("env2")); }
@Test public void testWithSystemAndEnvWithCustomPrefixProperties() throws Exception { Map<String, Object> envConf = new HashMap<>(); envConf.put(EnvPropertiesProvider.ENV_PREFIX_KEY, "CUSTOM_"); SubstitutionPropertiesProvider provider = new SubstitutionPropertiesProvider(new MapPropertiesProvider(config), new SystemPropertiesProvider(), new EnvPropertiesProvider(new MapPropertiesProvider(envConf))); Assert.assertEquals(null, provider.getProperty("")); Assert.assertEquals("value1", provider.getProperty("key1")); Assert.assertEquals("value2", provider.getProperty("key3")); Assert.assertEquals("value1-value2", provider.getProperty("key6")); Assert.assertEquals("value1-", provider.getProperty("key7")); Assert.assertEquals(null, provider.getProperty("key5")); Assert.assertEquals("system.value1", provider.getProperty("env1")); Assert.assertEquals("custom.value2", provider.getProperty("env2")); }