ConfigUtils { public static Config applySubstitutions(Config config) { return ConfigFactory.defaultOverrides() .withFallback(config) .resolve(); }  static Config configFromPath(String path); static Config configFromResource(String resource); static Config applySubstitutions(Config config); static Config applySubstitutions(Config config, String substitutionsString); static Config getApplicationConfig(Config config); static Config mergeLoadedConfiguration(Config config); static Config findReplaceStringValues(Config config, String findRegex, Object replace); static boolean canBeCoerced(Config config, String path, ConfigValueType type); static T getOrElse(Config config, String path, T orElse); static T getOrNull(Config config, String path); static final String JAR_FILE_EXCEPTION_MESSAGE; }
@Test public void testApplySubstitutionsWithArguments() { Config baseConfig = ConfigFactory.parseString("key_a = ${a}, key_b = ${b}, key_c = ${c}, key_d = ${substitution.test}"); String substitutions = "a=1,b=X,c=Y"; Config substitutedConfig = ConfigUtils.applySubstitutions(baseConfig, substitutions); assertEquals(substitutedConfig.getInt("key_a"), 1); assertEquals(substitutedConfig.getString("key_b"), "X"); assertEquals(substitutedConfig.getString("key_c"), "Y"); assertEquals(substitutedConfig.getString("key_d"), "substitution value"); }
@Test public void testApplySubstitutionsNoArguments() { Config baseConfig = ConfigFactory.parseString("key_a = A, key_b = ${substitution.test}, key_c = ${key_a}"); Config substitutedConfig = ConfigUtils.applySubstitutions(baseConfig); assertEquals(substitutedConfig.getString("key_a"), "A"); assertEquals(substitutedConfig.getString("key_b"), "substitution value"); assertEquals(substitutedConfig.getString("key_c"), "A"); }