Searcher { public SearchResult<T> buildResult(final List<T> wordList, final T currentWord, final String searchText) { if (StringUtils.isBlank(searchText)) { return new SearchResult<>(); } else { Predicate<SequencedWord> matcher = matchMaker.apply(searchText); List<T> matches = wordList.stream() .filter(matcher) .collect(toList()); if (matches.isEmpty()) { return searchResult(true, null, null, null, SEARCH_MATCH_NONE); } else { return updateForMatch(matches, currentWord); } } } Searcher(final I18nManager i18nManager, final Function<String, Predicate<SequencedWord>> matchMaker); SearchResult<T> buildResult(final List<T> wordList, final T currentWord, final String searchText);  }
@Test public void testEmptyList() { SearchResult<TestSequencedWord> result = target.buildResult(EMPTY_WORDS, WORD_AA, "AA"); validateNoMatch(result); }
@Test public void testEmptySearchText() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AA, ""); validateEmptySearch(result); }
@Test public void testNoMatch() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AA, "no-match"); validateNoMatch(result); }
@Test public void testMatchFirstWord() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AA, "A"); validateMatch(result, "1 of 3 matches", null, WORD_AB, WORD_AB); }
@Test public void testMatchSecondWord() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AB, "A"); validateMatch(result, "2 of 3 matches", WORD_AA, WORD_AC, WORD_AC); }
@Test public void testMatchThirdWord() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AC, "A"); validateMatch(result, "3 of 3 matches", WORD_AB, null, WORD_AA); }
@Test public void testBeforeFirstWord() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AA, "B"); validateMatch(result, "2 matches", null, WORD_AB, WORD_AB); }
@Test public void testBetweenMatches() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_AC, "B"); validateMatch(result, "2 matches", WORD_AB, WORD_BC, WORD_BC); }
@Test public void testAfterMatches() { SearchResult<TestSequencedWord> result = target.buildResult(WORDS, WORD_BC, "A"); validateMatch(result, "3 matches", WORD_AC, null, WORD_AA); }