OptionsBundle implements Config { @Override public <ValueT> ValueT retrieveOption(Option<ValueT> id) { ValueT value = retrieveOption(id, null); if (value == null) { throw new IllegalArgumentException("Option does not exist: " + id); } return value; } OptionsBundle(TreeMap<Option<?>, Object> options); static OptionsBundle from(Config otherConfig); static OptionsBundle emptyBundle(); @Override Set<Option<?>> listOptions(); @Override boolean containsOption(Option<?> id); @Override ValueT retrieveOption(Option<ValueT> id); @Nullable @Override ValueT retrieveOption(Option<ValueT> id, @Nullable ValueT valueIfMissing); @Override void findOptions(String idStem, OptionMatcher matcher);  }
@Test public void canRetrieveValue() { assertThat(mAllOpts.retrieveOption(OPTION_1)).isSameInstanceAs(VALUE_1); assertThat(mAllOpts.retrieveOption(OPTION_1_A)).isSameInstanceAs(VALUE_1_A); assertThat(mAllOpts.retrieveOption(OPTION_2)).isSameInstanceAs(VALUE_2); }
@Test public void canRetrieveListOfIntegers() { List<Integer> list = mAllOpts.retrieveOption(OPTION_INTEGER_LIST); assertThat(list).isSameInstanceAs(VALUE_INTEGER_LIST); }
@Test public void willReturnDefault_ifOptionIsMissing() { Object value = mAllOpts.retrieveOption(OPTION_MISSING, VALUE_MISSING); assertThat(value).isSameInstanceAs(VALUE_MISSING); }
@Test public void willReturnStoredValue_whenGivenDefault() { Object value = mAllOpts.retrieveOption(OPTION_1, VALUE_MISSING); assertThat(value).isSameInstanceAs(VALUE_1); }
@Test(expected = IllegalArgumentException.class) public void retrieveMissingOption_willThrow() { mAllOpts.retrieveOption(OPTION_MISSING); }