ConfigUtil { public static <T> Optional<T> either(Optional<T> original, Optional<T> alternative) { return original.isPresent() ? original : alternative; } 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 optionalOrShouldReturnFirstIfPresent() throws Exception { assertThat(ConfigUtil.either(Optional.of("hi"), Optional.of("there")), is(Optional.of("hi"))); }
@Test public void optionalOrShouldReturnAlternativeIfFirstMissing() throws Exception { assertThat(ConfigUtil.either(Optional.empty(), Optional.of("there")), is(Optional.of("there"))); }