### Question:
FunctionSearchService implements LiveSearchService<String> { @Override public void search(final String pattern, final int maxResults, final LiveSearchCallback<String> callback) { LiveSearchResults<String> results = new LiveSearchResults<>(maxResults); options.entrySet().stream() .filter(entry -> entry.getValue().toLowerCase().contains(pattern.toLowerCase())) .forEach(entry -> results.add(entry.getKey(), entry.getValue())); callback.afterSearch(results); } @Inject  FunctionSearchService(final ConditionEditorAvailableFunctionsService availableFunctionsService,
                                 final FunctionNamingService functionNamingService); void init(final ClientSession session); void reload(final String type,
                       final Command onSuccess); void clear(); @Override void search(final String pattern,
                       final int maxResults,
                       final LiveSearchCallback<String> callback); @Override void searchEntry(final String key,
                            final LiveSearchCallback<String> callback); FunctionDef getFunction(final String function);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testSearchWithResults() { loadTestFunctions(); searchService.search("FUNCTION", 10, searchCallback); verify(searchCallback).afterSearch(searchResultsCaptor.capture()); LiveSearchResults<String> results = searchResultsCaptor.getValue(); verifyContains(results, new Pair<>(FUNCTION1, FUNCTION1_NAME), new Pair<>(FUNCTION2, FUNCTION2_NAME)); searchService.search("FUNCTION1", 10, searchCallback); verify(searchCallback, times(2)).afterSearch(searchResultsCaptor.capture()); results = searchResultsCaptor.getValue(); verifyContains(results, new Pair<>(FUNCTION1, FUNCTION1_NAME)); verifyNotContains(results, new Pair<>(FUNCTION2, FUNCTION2_NAME)); searchService.search("FUNCTION2", 10, searchCallback); verify(searchCallback, times(3)).afterSearch(searchResultsCaptor.capture()); results = searchResultsCaptor.getValue(); verifyContains(results, new Pair<>(FUNCTION2, FUNCTION2_NAME)); verifyNotContains(results, new Pair<>(FUNCTION1, FUNCTION1_NAME)); }
@Test public void testSearchWithoutResults() { loadTestFunctions(); searchService.search("SOME_OTHER_FUNCTION", 10, searchCallback); verify(searchCallback).afterSearch(searchResultsCaptor.capture()); LiveSearchResults<String> results = searchResultsCaptor.getValue(); assertEquals(0, results.size()); }