### Question:
PrefixTrieMap { public Optional<PrefixMatch<T>> getPrefix(final CharSequence seq) { if (seq.length() == 0) { return Optional.empty(); } final States<T> states = trieMap.get(seq); final State<T> fullMatch = states.getStateForCompleteSequence(); if (fullMatch.isFinal()) { return Optional.of(new PrefixMatch<>(fullMatch.index + 1, fullMatch.value)); } final List<State<T>> prefixMatches = states.getPrefixes(); if (prefixMatches != null && !prefixMatches.isEmpty()) { final State<T> prefixMaxMatch = Collections.max(states.getPrefixes(), COMPARE_STATE_BY_INDEX_DESC); final int exclusiveEnd = prefixMaxMatch.index + 1; return Optional.of(new PrefixMatch<>( exclusiveEnd, seq.subSequence(exclusiveEnd, seq.length()), prefixMaxMatch.value)); } return Optional.empty(); } PrefixTrieMap(); void putPrefix(final CharSequence seq, final T value); void putPrefix(final CharSequence seq, final T value, boolean includeExactMatch); Optional<PrefixMatch<T>> getPrefix(final CharSequence seq);  }### Answer:
@Test public void testPartialMatch() { PrefixTrieMap<String> prefixMap = createprefixMap( matchSuffix, shorterSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<PrefixMatch<String>> prefixMatchOptional; prefixMatchOptional = prefixMap.getPrefix(partialTermMatch); assertThat(prefixMatchOptional).isEmpty(); }
@Test public void testNoPrefixMatch() { PrefixTrieMap<String> prefixMap = createprefixMap( matchSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<PrefixMatch<String>> prefixMatchOptional; prefixMatchOptional = prefixMap.getPrefix(termNoMatch); assertThat(prefixMatchOptional).isEmpty(); }
@Test public void testShorterPrefixMatch() { PrefixTrieMap<String> prefixMap = createprefixMap( shorterSuffix, similarSuffix, longerSimilarSuffix); Optional<PrefixMatch<String>> prefixMatchOptional; PrefixMatch<String> PrefixMatch; prefixMatchOptional = prefixMap.getPrefix(termMatch); assertThat(prefixMatchOptional).isNotEmpty(); PrefixMatch = prefixMatchOptional.get(); assertThat(PrefixMatch.match).isEqualTo(shorterSuffix.toString().toUpperCase()); assertThat(PrefixMatch.exclusiveEnd).isEqualTo(4); assertThat(PrefixMatch.wildcardMatch).isEqualTo("exxxx"); }
@Test public void testPrefixMatch() { PrefixTrieMap<String> prefixMap = createprefixMap( matchSuffix, shorterSuffix, similarSuffix, longerSimilarSuffix); Optional<PrefixMatch<String>> prefixMatchOptional; PrefixMatch<String> PrefixMatch; prefixMatchOptional = prefixMap.getPrefix(termMatch); assertThat(prefixMatchOptional).isNotEmpty(); PrefixMatch = prefixMatchOptional.get(); assertThat(PrefixMatch.match).isEqualTo(matchSuffix.toString().toUpperCase()); assertThat(PrefixMatch.exclusiveEnd).isEqualTo(5); assertThat(PrefixMatch.wildcardMatch).isEqualTo("xxxx"); }
@Test public void testPerfectMatch() { PrefixTrieMap<String> prefixMap = createprefixMap( matchSuffix, shorterSuffix, similarSuffix, longerSuffix, longerSimilarSuffix); Optional<PrefixMatch<String>> prefixMatchOptional; PrefixMatch<String> PrefixMatch; prefixMatchOptional = prefixMap.getPrefix(matchSuffix); assertThat(prefixMatchOptional).isNotEmpty(); PrefixMatch = prefixMatchOptional.get(); assertThat(PrefixMatch.match).isEqualTo(matchSuffix.toString().toUpperCase()); assertThat(PrefixMatch.exclusiveEnd).isEqualTo(matchSuffix.length()); assertThat(PrefixMatch.wildcardMatch).isEqualTo(""); }
@Test public void testGetWithEmptyString() { assertThat(new PrefixTrieMap<>().getPrefix("")).isEmpty(); }