DefaultExactMatchPolicy extends AbstractPolicy implements ExactMatchPolicy { @Override public Search findExactMatch(SearchResult searchResult) { if(this.isExactMatchForSingleSuccess() && searchResult.successCount() == 1) { List<Search> searches = searchResult.getSearches(); for (Search search : searches) { if(!search.isRejected()) { return search; } } } List<Search> searches = searchResult.successfulSearchesEqualOrLessThan(exactMatchMaxLevel); if(!searches.isEmpty()) { return searches.get(0); } return null; }  int getExactMatchMaxLevel(); void setExactMatchMaxLevel(int exactMatchThreshold); boolean isExactMatchForSingleSuccess(); void setExactMatchForSingleSuccess(boolean exactMatchForSingleSuccess); @Override Search findExactMatch(SearchResult searchResult); @Override String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); static final int DEFAULT_EXACT_MATCH_MAX_LEVEL; static final boolean DEFAULT_EXACT_MATCH_FOR_SINGLE_SUCCESS; }
@Test public void testFindExactMatch_choosesFirstSuccessResultOfTheRightLevel() { Search searchOne = new Search(fix.requestLevelOne, fix.responseSuccess); fix.searchResult.add(searchOne); assertThat(policy.findExactMatch(fix.searchResult)).isNull(); Search searchZero = new Search(fix.requestLevelZero, fix.responseSuccess); fix.searchResult.add(searchZero); assertThat(policy.findExactMatch(fix.searchResult)).isEqualTo(searchZero); }
@Test public void testMarkExactMatch_singleSuccessDisabled() { Search searchZero = new Search(fix.requestLevelZero, fix.responseReject); fix.searchResult.add(searchZero); assertThat(policy.findExactMatch(fix.searchResult)).isNull(); Search searchOne = new Search(fix.requestLevelOne, fix.responseSuccess); fix.searchResult.add(searchOne); assertThat(policy.findExactMatch(fix.searchResult)).isNull(); }