DefaultSearchDepthPolicy extends AbstractPolicy implements SearchDepthPolicy { @Override public List<Search> inputForSubSearches(SearchResult searchResult) { List<Search> subSearchable = new ArrayList<>(); int currentLevel = searchResult.getCurrentLevel(); for (Search search : searchResult.getSearches()) { if (search.getLevel() == currentLevel && search.isRejected() && nextLevelEnabled(search.getRequest())) { subSearchable.add(search); } } return subSearchable; }  boolean continueSearch(SearchResult searchResult); int getMaximumDepth(); @Override List<Search> inputForSubSearches(SearchResult searchResult); @Override String getDescription(); boolean levelEnabled(int level); boolean nextLevelEnabled(Request request); void setMaximumDepth(int maximumDepth); boolean isAssignedValueRequestsCanSpawnSubsearch(); void setAssignedValueRequestsCanSpawnSubsearch(boolean assignedValueRequestsCanSpawnSubsearch); @Override int hashCode(); @Override boolean equals(Object obj); static final boolean DEFAULT_ASSIGNED_VALUE_REQUESTS_CAN_SPAWN_SUBSEARCH; static final int DEFAULT_MAX_DEPTH; }
@Test public void testInputForSubSearches_emptySearchResultProducesNoSubSearches() { assertTrue(this.policy.inputForSubSearches(fix.searchResult).isEmpty()); }
@Test public void testInputForSubSearches_currentLevelContainsOnlySuccess() { fix.searchResult.add(new Search(fix.requestLevelOne, fix.responseSuccess)); assertTrue(this.policy.inputForSubSearches(fix.searchResult).isEmpty()); }
@Test public void testInputForSubSearches_currentLevelFailureButNextLevelDisabled() { fix.searchResult.add(new Search(fix.requestLevelFour, fix.responseSuccess)); fix.searchResult.add(new Search(fix.requestLevelFour, fix.responseReject)); assertTrue(this.policy.inputForSubSearches(fix.searchResult).isEmpty()); }
@Test public void testInputForSubSearches_currentLevelContainsSuccessAndFailure() { fix.searchResult.add(new Search(fix.requestLevelOne, fix.responseSuccess)); Search rejectedLevelOneSearch = new Search(fix.requestLevelOne, fix.responseReject); fix.searchResult.add(rejectedLevelOneSearch); assertThat(this.policy.inputForSubSearches(fix.searchResult).size()).isEqualTo(1); assertTrue(this.policy.inputForSubSearches(fix.searchResult).contains(rejectedLevelOneSearch)); }