TrafficOptionsPanel extends OptionsPanel implements OptionItem.OnChangedListener { public void setDynamicPenalty(final DynamicPenalty penalty) { mDynamicPenalty = penalty; select(mDynamicPenalty.getTrafficPenaltyMode()); } TrafficOptionsPanel(final Context context);  TrafficOptionsPanel(final Context context, final AttributeSet attrs);  TrafficOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  TrafficOptionsPanel(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes); DynamicPenalty getDynamicPenalty(); void setDynamicPenalty(final DynamicPenalty penalty); void populateDynamicPenalty(); @Override void onChanged(OptionItem item);  }
@Test public void testSettingDynamicPenalty() { DynamicPenalty dynamicPenalty = MockUtils.getDynamicPenality(Route.TrafficPenaltyMode.AVOID_LONG_TERM_CLOSURES); mTrafficOptionsPanel.setDynamicPenalty(dynamicPenalty); final List<OptionItem> items = mTrafficOptionsPanel.getOptionItems(); assertThat(items.size(), equalTo(1)); SingleChoiceOptionItem item = (SingleChoiceOptionItem) items.get(0); final List<String> labels = item.getLabels(); assertThat(labels.size(), equalTo(3)); String selectedId = item.getSelectedItemLabel(); assertThat(selectedId, equalTo(getString(R.string.msdkui_avoid_long_term_closures))); dynamicPenalty = MockUtils.getDynamicPenality(Route.TrafficPenaltyMode.DISABLED); mTrafficOptionsPanel.setDynamicPenalty(dynamicPenalty); selectedId = item.getSelectedItemLabel(); assertThat(selectedId, equalTo(getString(R.string.msdkui_disabled))); }
@Test public void testChangeListener() { DynamicPenalty dynamicPenalty = MockUtils.getDynamicPenality(Route.TrafficPenaltyMode.DISABLED); mTrafficOptionsPanel.setDynamicPenalty(dynamicPenalty); mTrafficOptionsPanel.setListener(new OptionsPanel.Listener() { @Override public void onOptionCreated(List<OptionItem> item) { mCallbackCalled = false; } @Override public void onOptionChanged(OptionItem item) { mCallbackCalled = true; } }); dynamicPenalty = MockUtils.getDynamicPenality(Route.TrafficPenaltyMode.AVOID_LONG_TERM_CLOSURES); mTrafficOptionsPanel.setDynamicPenalty(dynamicPenalty); assertThat(mCallbackCalled, is(true)); }