### Question:
KSessionSelector implements IsWidget { public void init(final Path path, final String ksession) { moduleService.call(getSuccessfulResolveModuleCallback(ksession)).resolveModule(path); } @Inject  KSessionSelector(final KSessionSelectorView view,
                            final Caller<KieModuleService> moduleService,
                            final Caller<KModuleService> kModuleService); void init(final Path path,
                     final String ksession); void onKBaseSelected(final String kbaseName); String getSelectedKSessionName(); @Override Widget asWidget(); void onSelectionChange(); void setSelectionChangeHandler(final Command handler);  }### Answer:
@Test public void testSetKBaseAndKSession() throws Exception { selector.init(path, "ksession2"); ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class); verify(view).setKSessions(listArgumentCaptor.capture()); List ksessionNamesList = listArgumentCaptor.getValue(); assertEquals(2, ksessionNamesList.size()); verify(view).setSelected("kbase2", "ksession2"); }
@Test public void testKBaseAndKSessionNotPreviouslySet() throws Exception { selector.init(path, null); verify(view).addKBases("kbase1", "kbase2", "kbase3"); ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class); verify(view).setKSessions(listArgumentCaptor.capture()); List ksessionNamesList = listArgumentCaptor.getValue(); assertEquals(1, ksessionNamesList.size()); verify(view).setSelected("kbase1", "ksession1"); }
@Test public void testEmpty() throws Exception { when(kModuleService.load(kmodulePath)).thenReturn(new KModuleModel()); selector.init(path, null); verify(view).addKBases("defaultKieBase"); ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class); verify(view).setKSessions(listArgumentCaptor.capture()); verify(view).setSelected(eq("defaultKieBase"), eq("defaultKieSession")); List ksessionNamesList = listArgumentCaptor.getValue(); assertEquals(1, ksessionNamesList.size()); assertEquals("defaultKieSession", ksessionNamesList.iterator().next()); }
@Test public void testKSessionDefinedInScenarioNoLongerExists() throws Exception { selector.init(path, "ksessionThatHasBeenRemovedFromKModuleXML"); verify(view).addKBases("kbase1", "kbase2", "kbase3", "---"); ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class); verify(view).setKSessions(listArgumentCaptor.capture()); verify(view).setSelected(eq("---"), eq("ksessionThatHasBeenRemovedFromKModuleXML")); verify(view).showWarningSelectedKSessionDoesNotExist(); List ksessionNamesList = listArgumentCaptor.getValue(); assertEquals(1, ksessionNamesList.size()); assertEquals("ksessionThatHasBeenRemovedFromKModuleXML", ksessionNamesList.get(0)); }
@Test public void testKSessionDefinedInScenarioNoLongerExistsAndKModuleIsEmpty() throws Exception { when(kModuleService.load(kmodulePath)).thenReturn(new KModuleModel()); selector.init(path, "ksessionThatHasBeenRemovedFromKModuleXML"); verify(view).addKBases("defaultKieBase", "---"); ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class); verify(view).setKSessions(listArgumentCaptor.capture()); verify(view).setSelected(eq("---"), eq("ksessionThatHasBeenRemovedFromKModuleXML")); verify(view).showWarningSelectedKSessionDoesNotExist(); List ksessionNamesList = listArgumentCaptor.getValue(); assertEquals(1, ksessionNamesList.size()); assertEquals("ksessionThatHasBeenRemovedFromKModuleXML", ksessionNamesList.get(0)); }