TunnelOptionsPanel extends OptionsPanel implements OptionItem.OnChangedListener { public void setRouteOptions(final RouteOptions routeOptions) { if (routeOptions == null) { throw new IllegalArgumentException(getString(R.string.msdkui_exception_route_options_null)); } mRouteOptions = routeOptions; select(mRouteOptions.getTruckTunnelCategory()); } TunnelOptionsPanel(final Context context);  TunnelOptionsPanel(final Context context, final AttributeSet attrs);  TunnelOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  TunnelOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes); RouteOptions getRouteOptions(); void setRouteOptions(final RouteOptions routeOptions); void populateRouteOptions(); @Override void onChanged(OptionItem item);  }
@Test public void testSettingRouteOptions() { final MockUtils.MockRouteOptionsBuilder builder = new MockUtils.MockRouteOptionsBuilder(); mTunnelOptionsPanel.setRouteOptions(builder.withTunnelOptions() .build()); final List<OptionItem> items = mTunnelOptionsPanel.getOptionItems(); assertThat(items.size(), equalTo(1)); SingleChoiceOptionItem item = (SingleChoiceOptionItem) items.get(0); final List<String> labels = item.getLabels(); assertThat(labels.size(), equalTo(5)); String selectedIds = item.getSelectedItemLabel(); assertThat(selectedIds, equalTo(getString(R.string.msdkui_tunnel_cat_c))); mTunnelOptionsPanel.setRouteOptions(builder.withNoTunnelOptions() .build()); selectedIds = item.getSelectedItemLabel(); assertThat(selectedIds, equalTo(getString(R.string.msdkui_undefined))); }
@Test public void testChangeListener() { final MockUtils.MockRouteOptionsBuilder builder = new MockUtils.MockRouteOptionsBuilder(); RouteOptions options = builder.withTunnelOptions().build(); mTunnelOptionsPanel.setRouteOptions(options); mTunnelOptionsPanel.setListener(new OptionsPanel.Listener() { @Override public void onOptionCreated(List<OptionItem> item) { mCallbackCalled = false; } @Override public void onOptionChanged(OptionItem item) { mCallbackCalled = true; } }); options = builder.withNoTunnelOptions().build(); mTunnelOptionsPanel.setRouteOptions(options); assertThat(mCallbackCalled, is(true)); }