ConfigurationUtil { public static <T extends HadoopConfigurationProperty<?>> String getMandatoryConfig( Configuration config, T property) throws IOException { String value = config.get(property.getKey()); if (Strings.isNullOrEmpty(value)) { throw new IOException("Must supply a value for configuration setting: " + property.getKey()); } return value; }  static String getMandatoryConfig(
      Configuration config, T property); static Map<String, String> getMandatoryConfig(
      Configuration config, List<T> properties);  }
@Test public void testSingleStringGetMandatoryConfig() throws IOException { Configuration config = new Configuration(); assertThrows(IOException.class, () -> getMandatoryConfig(config, PROPERTY_ONE)); config.set(PROPERTY_ONE.getKey(), ""); assertThrows(IOException.class, () -> getMandatoryConfig(config, PROPERTY_ONE)); config.set(PROPERTY_ONE.getKey(), VALUE_ONE); assertThat(getMandatoryConfig(config, PROPERTY_ONE)).isEqualTo(VALUE_ONE); }
@Test public void testListGetMandatoryConfig() throws IOException { Configuration config = new Configuration(); config.set(PROPERTY_ONE.getKey(), VALUE_ONE); assertThrows( IOException.class, () -> getMandatoryConfig(config, Lists.newArrayList(PROPERTY_ONE, PROPERTY_TWO))); config.set(PROPERTY_TWO.getKey(), ""); assertThrows( IOException.class, () -> getMandatoryConfig(config, Lists.newArrayList(PROPERTY_ONE, PROPERTY_TWO))); config.set(PROPERTY_TWO.getKey(), VALUE_TWO); Map<String, String> expectedMap = new HashMap<>(); expectedMap.put(PROPERTY_ONE.getKey(), VALUE_ONE); expectedMap.put(PROPERTY_TWO.getKey(), VALUE_TWO); assertThat(getMandatoryConfig(config, Lists.newArrayList(PROPERTY_ONE, PROPERTY_TWO))) .isEqualTo(expectedMap); }