ConfigUtil { public static Optional<Integer> optionalInt(Config config, String path) { return config.hasPath(path) ? Optional.of(config.getInt(path)) : Optional.empty(); } private  ConfigUtil(); static Optional<String> optionalString(Config config, String path); static Optional<Boolean> optionalBoolean(Config config, String path); static Optional<Integer> optionalInt(Config config, String path); static Optional<Double> optionalDouble(Config config, String path); static Optional<Config> optionalConfig(Config config, String path); static Optional<T> either(Optional<T> original, Optional<T> alternative);  }
@Test public void shouldReturnValueForAvailableInt() throws Exception { final Config config = ConfigFactory.parseMap(ImmutableMap.of("hey", 345)); assertThat(ConfigUtil.optionalInt(config, "hey"), is(Optional.of(345))); }
@Test public void shouldReturnEmptyForMissingInt() throws Exception { final Config config = ConfigFactory.parseMap(ImmutableMap.of("hey", 99)); assertThat(ConfigUtil.optionalInt(config, "ho"), is(Optional.empty())); }