PluginSearch { public static <T extends SearchablePlugin> List<T> search(Collection<T> searchablePlugins, String query) { return searchablePlugins.stream() .filter(plugin -> Text.matchesSearchTerms(SPLITTER.split(query.toLowerCase()), plugin.getKeywords())) .sorted(comparator(query)) .collect(Collectors.toList()); }  static List<T> search(Collection<T> searchablePlugins, String query);  }
@Test public void emptyQueryReturnsPluginsInAlphabeticalOrderWithPinnedItemsFirst() { List<SearchablePlugin> results = PluginSearch.search(plugins.values(), " "); assertThat(results, containsInAnyOrder(plugins.values().toArray(new SearchablePlugin[] {}))); }
@Test public void searchReturnsMatchingPlugins() { List<SearchablePlugin> results = PluginSearch.search(plugins.values(), "sTATus"); assertThat(results, hasSize(2)); assertThat(results, containsInAnyOrder(plugins.get("Discord"), plugins.get("Status Bars"))); }
@Test public void searchOrdersItemsWithMatchesInTitleFirst() { List<SearchablePlugin> results = PluginSearch.search(plugins.values(), "STATUS"); assertThat(results.get(0), equalTo(plugins.get("Status Bars"))); }
@Test public void searchOrdersPinnedItemsFirstIfThereAreNoExactMatches() { List<SearchablePlugin> results = PluginSearch.search(plugins.values(), "integrat"); assertThat(results, contains(plugins.get("Grand Exchange"), plugins.get("Discord"))); }