RendererSelector implements IsWidget { public void init(DisplayerSettings displayerSettings, SelectorType selectorType, int width, Command onSelectCommand) { switch (selectorType) { case LIST: view = listBoxView; break; case RADIO: view = radioListView; break; case TAB: view = tabListView; break; } this.view.init(this); this.selectCommand = onSelectCommand; RendererLibrary rendererLibrary = rendererManager.getRendererForDisplayer(displayerSettings); List<RendererLibrary> renderers = rendererManager.getRenderersForType(displayerSettings.getType(), displayerSettings.getSubtype()); if (renderers != null && renderers.size() > 1) { view.setVisible(true); view.setWidth(width); view.clearRendererSelector(); for (int i=0; i<renderers.size(); i++) { RendererLibrary rendererLib = renderers.get(i); view.addRendererItem(rendererLib.getName()); if (rendererLibrary != null && rendererLib.equals(rendererLibrary)) { view.setSelectedRendererIndex(i); } } } else { view.setVisible(false); } } @Inject  RendererSelector(TabListView tabListView,
                            ListBoxView listBoxView,
                            RadioListView radioListView,
                            RendererManager rendererManager); @Override Widget asWidget(); RendererLibrary getRendererLibrary(); void init(DisplayerSettings displayerSettings,
                     SelectorType selectorType, int width,
                     Command onSelectCommand);  }
@Test public void testSingleRenderer() { List<RendererLibrary> rendererLibs = Arrays.asList((RendererLibrary) d3Lib); when(rendererManager.getRenderersForType(any(DisplayerType.class), any(DisplayerSubType.class))).thenReturn(rendererLibs); when(rendererManager.getRendererForDisplayer(settings)).thenReturn(d3Lib); presenter.init(settings, RendererSelector.SelectorType.TAB, 300, selectCommand); verify(tabListView).setVisible(false); verify(tabListView, never()).setWidth(anyInt()); verify(tabListView, never()).clearRendererSelector(); verify(tabListView, never()).addRendererItem(anyString()); verify(tabListView, never()).setSelectedRendererIndex(anyInt()); verifyZeroInteractions(listBoxView, radioListView); }
@Test public void testMultipleRenderers() { List<RendererLibrary> rendererLibs = Arrays.asList((RendererLibrary) gwtLib, d3Lib, lienzoLib); when(rendererManager.getRenderersForType(any(DisplayerType.class), any(DisplayerSubType.class))).thenReturn(rendererLibs); when(rendererManager.getRendererForDisplayer(settings)).thenReturn(d3Lib); presenter.init(settings, RendererSelector.SelectorType.LIST, 300, selectCommand); verify(listBoxView).setVisible(true); verify(listBoxView).setWidth(300); verify(listBoxView).clearRendererSelector(); verify(listBoxView).addRendererItem("gwt"); verify(listBoxView).addRendererItem("d3"); verify(listBoxView).addRendererItem("lienzo"); verify(listBoxView).setSelectedRendererIndex(1); verifyZeroInteractions(tabListView, radioListView); }