LiveSearchDropDown implements IsWidget { public void setSelectedItem(final TYPE key) { searchService.searchEntry(key, results -> { if(results.size() == 1) { LiveSearchEntry<TYPE> entry = results.get(0); changeCallbackEnabled = false; LiveSearchSelectorItem<TYPE> item = getSelectorItemForEntry(entry); selectionHandler.selectItem(item); item.select(); view.clearItems(); lastSearch = null; changeCallbackEnabled = true; } }); } @Inject  LiveSearchDropDown(View view,
                              ManagedInstance<LiveSearchSelectorItem<TYPE>> liveSearchSelectorItems); @Override Widget asWidget(); boolean isSearchEnabled(); void setSearchEnabled(boolean searchEnabled); void setClearSelectionEnabled(boolean clearSelectionEnabled); void setSelectorHint(String text); void setSearchHint(String text); void setNotFoundMessage(String noItemsMessage); void init(LiveSearchService<TYPE> searchService,
                     LiveSearchSelectionHandler<TYPE> selectionHandler); boolean isSearchCacheEnabled(); void setSearchCacheEnabled(boolean searchCacheEnabled); int getMaxItems(); void setMaxItems(int maxItems); void setWidth(int minWidth); void clear(); String getLastSearch(); void search(String pattern); void setSelectedItem(final TYPE key); void showResults(LiveSearchResults<TYPE> results); LiveSearchSelectorItem<TYPE> getSelectorItemForEntry(LiveSearchEntry<TYPE> entry); void setOnChange(Command onChange); void setEnabled(boolean enabled); void clearSelection(); void showNewItem(); @PreDestroy void destroy();  }
@Test public void testItemSelected() { doAnswer(invocationOnMock -> { LiveSearchResults results = new LiveSearchResults(1); results.add("1", "a"); LiveSearchCallback callback = (LiveSearchCallback) invocationOnMock.getArguments()[1]; callback.afterSearch(results); return null; }).when(searchService).searchEntry(anyString(), any()); presenter.setSelectedItem("1"); assertEquals("1", selectionHandler.getSelectedKey()); verify(view).setDropDownText("a"); verify(onChangeCommand, never()).execute(); }