SwitcherView extends View { @Override public <T> void addMonitoredGUI(T gui) { if (gui instanceof ViewProvider) { managedView = (ViewProvider) gui; } if (managedView != null) { resetSelection(); if (comboBox != null) { comboBox.setVisible(true); comboBox.setEnabled(true); } } super.addMonitoredGUI(gui); } @SuppressWarnings({ "rawtypes", "unchecked" })  SwitcherView(AbstractComponent ac, ViewInfo vi); @Override void addMonitoredGUI(T gui); @Override void setForeground(Color fg); static final ViewInfo VIEW_INFO; }
@Test (dataProvider = "generateSwitcherTests") public void testSwitcher(boolean addGUI, boolean doChange, boolean acceptChange) { View switcherView = SwitcherView.VIEW_INFO.createView(mockComponent); Mockito.when(mockViewProvider.setHousedViewManifestation(mockViewInfo2)) .thenReturn(acceptChange); if (addGUI) { switcherView.addMonitoredGUI(mockViewProvider); } @SuppressWarnings("rawtypes") JComboBox comboBox = findComponent(switcherView, JComboBox.class); Assert.assertNotNull(comboBox); if (doChange) { comboBox.setSelectedItem(mockViewInfo2); } Mockito.verify(mockViewProvider, Mockito.times(addGUI && doChange ? 1 : 0)) .setHousedViewManifestation(mockViewInfo2); boolean shouldChange = doChange && !(addGUI && !acceptChange); Assert.assertEquals(comboBox.getSelectedItem(), shouldChange ? mockViewInfo2 : mockViewInfo1); }
@Test public void testBadInput() { View switcherView = SwitcherView.VIEW_INFO.createView(mockComponent); switcherView.addMonitoredGUI(null); switcherView.addMonitoredGUI("hello"); Mockito.when(mockViewProvider.getHousedViewManifestation()) .thenReturn(null); switcherView.addMonitoredGUI(mockViewProvider); }