ServerTemplateSelectorMenuBuilder implements MenuFactory.CustomMenuBuilder { @PostConstruct public void init() { widgetView.setServerTemplateChangeHandler(e -> { view.updateSelectedValue(e); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(serverTemplateMap.get(e))); }); view.setServerTemplateChangeHandler(e -> { widgetView.updateSelectedValue(e); serverTemplateSelectedEvent.fire(new ServerTemplateSelected(serverTemplateMap.get(e))); }); loadServerTemplates(); }  @PostConstruct void init(); @Override void push(MenuFactory.CustomMenuBuilder element); @Override MenuItem build(); ServerTemplateSelectorElementView getView(); void onServerTemplateDeleted(@Observes final ServerTemplateDeleted serverTemplateDeleted); void onServerTemplateUpdated(@Observes final ServerTemplateUpdated serverTemplateUpdated); void onKieServerDataSetRegistered(@Observes final KieServerDataSetRegistered kieServerDataSetRegistered); @Inject void setSpecManagementService(final Caller<SpecManagementService> specManagementService); ServerTemplate getSelectedServerTemplate(); String getSelectedServerTemplateId();  }
@Test public void testOneServerTemplate() { final String serverTemplateId = "id1"; final ServerTemplate st1 = new ServerTemplate(serverTemplateId, "kie-server-template1"); st1.addServerInstance(new ServerInstanceKey()); when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(singletonList(st1))); serverTemplateSelectorMenuBuilder.init(); verify(specManagementService).listServerTemplates(); verify(view).setServerTemplateChangeHandler(any(ParameterizedCommand.class)); verify(view).removeAllServerTemplates(); verify(view).addServerTemplate(serverTemplateId); verify(view).selectServerTemplate(serverTemplateId); verify(view).setVisible(false); verifyNoMoreInteractions(view); }
@Test public void testServerTemplateChangeHandler(){ final String serverTemplateId = "id1"; when(specManagementService.listServerTemplates()).thenReturn(new ServerTemplateList(emptyList())); doAnswer(invocation -> { ParameterizedCommand<String> command = (ParameterizedCommand)invocation.getArguments()[0]; command.execute(serverTemplateId); return null; }).when(view).setServerTemplateChangeHandler(any()); doAnswer(invocation -> { ParameterizedCommand<String> command = (ParameterizedCommand)invocation.getArguments()[0]; command.execute(serverTemplateId); return null; }).when(viewWidget).setServerTemplateChangeHandler(any()); serverTemplateSelectorMenuBuilder.init(); InOrder inOrder = inOrder(view, viewWidget, serverTemplateSelectedEvent); inOrder.verify(view).updateSelectedValue(serverTemplateId); inOrder.verify(serverTemplateSelectedEvent).fire(any()); inOrder.verify(viewWidget).updateSelectedValue(serverTemplateId); inOrder.verify(serverTemplateSelectedEvent).fire(any()); }