HazardousMaterialsOptionsPanel extends OptionsPanel implements OptionItem.OnChangedListener { public void setRouteOptions(final RouteOptions routeOptions) { mRouteOptions = routeOptions; final EnumSet<RouteOptions.HazardousGoodType> materialsOptions = mRouteOptions.getTruckShippedHazardousGoods(); select(materialsOptions); } HazardousMaterialsOptionsPanel(final Context context);  HazardousMaterialsOptionsPanel(final Context context, final AttributeSet attrs);  HazardousMaterialsOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  HazardousMaterialsOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes); RouteOptions getRouteOptions(); void setRouteOptions(final RouteOptions routeOptions); @Override void onChanged(OptionItem item);  }
@Test public void testSettingRouteOptions() { final MockUtils.MockRouteOptionsBuilder builder = new MockUtils.MockRouteOptionsBuilder(); mHazardousMaterialsOptionsPanel.setRouteOptions(builder.withFullHazardousOptions() .build()); final List<OptionItem> items = mHazardousMaterialsOptionsPanel.getOptionItems(); assertThat(items.size(), equalTo(1)); MultipleChoiceOptionItem item = (MultipleChoiceOptionItem) items.get(0); final List<String> labels = item.getLabels(); assertThat(labels.size(), equalTo(11)); List<String> selectedIds = item.getSelectedLabels(); assertThat(selectedIds.size(), equalTo(11)); mHazardousMaterialsOptionsPanel.setRouteOptions(builder.withFewHazardousOptions() .build()); selectedIds = item.getSelectedLabels(); assertThat(selectedIds.size(), equalTo(1)); }
@Test public void testGettingRouteOptionsWhenMainItemIsUnselected() { final MockUtils.MockRouteOptionsBuilder builder = new MockUtils.MockRouteOptionsBuilder(); final RouteOptions mockRouteOptions = builder.withFullHazardousOptions() .build(); mHazardousMaterialsOptionsPanel.setRouteOptions(mockRouteOptions); doAnswer(new NoGoodTypesAnswer()).when(mockRouteOptions) .setTruckShippedHazardousGoods(any(EnumSet.class)); mHazardousMaterialsOptionsPanel.getOptionItems(); }
@Test public void testChangeListener() { final MockUtils.MockRouteOptionsBuilder builder = new MockUtils.MockRouteOptionsBuilder(); final RouteOptions options = builder.withFewHazardousOptions().build(); mHazardousMaterialsOptionsPanel.setRouteOptions(options); mHazardousMaterialsOptionsPanel.setListener(new OptionsPanel.Listener() { @Override public void onOptionCreated(List<OptionItem> item) { mCallbackCalled = false; } @Override public void onOptionChanged(OptionItem item) { mCallbackCalled = true; } }); when(options.getTruckShippedHazardousGoods()).thenReturn(EnumSet.noneOf(RouteOptions.HazardousGoodType.class)); mHazardousMaterialsOptionsPanel.setRouteOptions(options); assertThat(mCallbackCalled, is(true)); }