### Question:
SuffixTrieMap { public Optional<SuffixMatch<T>> getBySuffix(final CharSequence seq) { if (seq.length() == 0) { return Optional.empty(); } final ReverseComparableCharSequence revSeq = new ReverseComparableCharSequence(seq); final States<T> states = trieMap.get(revSeq); final State<T> fullMatch = states.getStateForCompleteSequence(); if (fullMatch.isFinal()) { return Optional.of(new SuffixMatch<>(0, fullMatch.value)); } final List<State<T>> suffixMatches = states.getPrefixes(); if (suffixMatches != null && !suffixMatches.isEmpty()) { final State<T> suffixMaxMatch = Collections.max(states.getPrefixes(), COMPARE_STATE_BY_INDEX_DESC); final int startSubstring = seq.length() - (suffixMaxMatch.index + 1); return Optional.of(new SuffixMatch<>( startSubstring, seq.subSequence(0, startSubstring), suffixMaxMatch.value)); } return Optional.empty(); } SuffixTrieMap(); void putSuffix(final CharSequence seq, final T value); void putSuffix(final CharSequence seq, final T value, final boolean includeExactMatch); Optional<SuffixMatch<T>> getBySuffix(final CharSequence seq);  }### Answer:
@Test public void testPartialMatch() { SuffixTrieMap<String> suffixMap = createSuffixMap( matchSuffix, shorterSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<SuffixMatch<String>> suffixMatchOptional; suffixMatchOptional = suffixMap.getBySuffix(partialTermMatch); assertThat(suffixMatchOptional).isEmpty(); }
@Test public void testNoSuffixMatch() { SuffixTrieMap<String> suffixMap = createSuffixMap( matchSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<SuffixMatch<String>> suffixMatchOptional; suffixMatchOptional = suffixMap.getBySuffix(termNoMatch); assertThat(suffixMatchOptional).isEmpty(); }
@Test public void testShorterSuffixMatch() { SuffixTrieMap<String> suffixMap = createSuffixMap( shorterSuffix, similarSuffix, longerSimilarSuffix); Optional<SuffixMatch<String>> suffixMatchOptional; SuffixMatch<String> suffixMatch; suffixMatchOptional = suffixMap.getBySuffix(termMatch); assertThat(suffixMatchOptional).isNotEmpty(); suffixMatch = suffixMatchOptional.get(); assertThat(suffixMatch.match).isEqualTo(shorterSuffix.toString().toUpperCase()); assertThat(suffixMatch.startSubstring).isEqualTo(11); assertThat(suffixMatch.wildcardMatch).isEqualTo("digitalkame"); }
@Test public void testSuffixMatch() { SuffixTrieMap<String> suffixMap = createSuffixMap( matchSuffix, shorterSuffix, similarSuffix, longerSimilarSuffix); Optional<SuffixMatch<String>> suffixMatchOptional; SuffixMatch<String> suffixMatch; suffixMatchOptional = suffixMap.getBySuffix(termMatch); assertThat(suffixMatchOptional).isNotEmpty(); suffixMatch = suffixMatchOptional.get(); assertThat(suffixMatch.match).isEqualTo(matchSuffix.toString().toUpperCase()); assertThat(suffixMatch.startSubstring).isEqualTo(7); assertThat(suffixMatch.wildcardMatch).isEqualTo("digital"); }
@Test public void testPerfectMatch() { SuffixTrieMap<String> suffixMap = createSuffixMap( matchSuffix, shorterSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<SuffixMatch<String>> suffixMatchOptional; SuffixMatch<String> suffixMatch; suffixMatchOptional = suffixMap.getBySuffix(matchSuffix); assertThat(suffixMatchOptional).isNotEmpty(); suffixMatch = suffixMatchOptional.get(); assertThat(suffixMatch.match).isEqualTo(matchSuffix.toString().toUpperCase()); assertThat(suffixMatch.startSubstring).isEqualTo(0); assertThat(suffixMatch.wildcardMatch).isEqualTo(""); }
@Test public void testGetWithEmptyString() { assertThat(new SuffixTrieMap<>().getBySuffix("")).isEmpty(); }