ConfigUtilsInternal { public static Map<?,?> setAllConfigKeys(Map<?,?> flags, Iterable<? extends ConfigKey<?>> configKeys, Configurable obj) { Map<?,?> unusedFlags = MutableMap.copyOf(flags); for (ConfigKey<?> key : configKeys) { ConfigValue values = getValue(unusedFlags, key); Maybe<Object> valueToUse = values.preferredValue(); if (valueToUse.isPresent()) { setValue(obj, key, valueToUse.get()); values.logIfDeprecatedValue(obj, key); } } return unusedFlags; }  static Map<?,?> setAllConfigKeys(Map<?,?> flags, Iterable<? extends ConfigKey<?>> configKeys, Configurable obj);  }
@Test public void testSetConfig() throws Exception { Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("key1", "myval"), ImmutableList.of(key1), app); assertEquals(app.config().get(key1), "myval"); assertEquals(remaining, ImmutableMap.of()); }
@Test public void testSetConfigUsingDeprecatedValue() throws Exception { Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("oldKey1", "myval"), ImmutableList.of(key1), app); assertEquals(app.config().get(key1), "myval"); assertEquals(remaining, ImmutableMap.of()); }
@Test public void testSetConfigPrefersNonDeprecated() throws Exception { Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys( ImmutableMap.of("key1", "myval", "oldKey1", "myOldVal1", "oldKey1b", "myOldVal1b"), ImmutableList.of(key1), app); assertEquals(app.config().get(key1), "myval"); assertEquals(remaining, ImmutableMap.of()); }
@Test public void testReturnsUnmatched() throws Exception { Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys(ImmutableMap.of("wrong", "myval"), ImmutableList.of(key1), app); assertEquals(app.config().get(key1), null); assertEquals(remaining, ImmutableMap.of("wrong", "myval")); }