ConfigUtils { public static <T> T getOrElse(Config config, String path, T orElse) { if (config.hasPath(path)) { if (config.getValue(path).valueType() == ConfigValueType.OBJECT) { return (T) config.getConfig(path); } else { return (T) config.getAnyRef(path); } } else { return orElse; } }  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 getOrElseExists() { Config config = ConfigFactory.empty().withValue("hello", ConfigValueFactory.fromAnyRef(true)); assertEquals(true, ConfigUtils.getOrElse(config, "hello", false)); }
@Test public void getOrElseNotExists() { Config config = ConfigFactory.empty().withValue("hello", ConfigValueFactory.fromAnyRef(true)); assertEquals(false, ConfigUtils.getOrElse(config, "world", false)); }