RelevantProposalsFilter implements IRelevantProposalsFilter { @Override public ICompletionProposal[] extractMostRelevantProposals(List<RobotCompletionProposalSet> proposalSets2) { PriorityDeque<RobotCompletionProposalSet> proposalSets = removeEmptyProposalSets(proposalSets2); int lowestPriority = proposalSets.peekLowestPriority(); boolean isEmpty = lowestPriority == -1; if (isEmpty) { return null; } if (lowestPriority < NOT_BASED_ON_INPUT_MASK) { proposalSets.clear(NOT_BASED_ON_INPUT_MASK, proposalSets.getNumberOfPriorityLevels() - 1); } List<RobotCompletionProposal> proposals = new ArrayList<RobotCompletionProposal>(); for (RobotCompletionProposalSet proposalSet : proposalSets) { proposals.addAll(proposalSet.getProposals()); } return proposals.toArray(new ICompletionProposal[proposals.size()]); }  @Override ICompletionProposal[] extractMostRelevantProposals(List<RobotCompletionProposalSet> proposalSets2);  }
@Test public void should_return_null_when_no_proposalSets_given() throws Exception { List<RobotCompletionProposalSet> sets = new ArrayList<RobotCompletionProposalSet>(); ICompletionProposal[] actual = filter.extractMostRelevantProposals(sets); assertNull(actual); }
@Test public void should_ignore_empty_proposalSets_when_nothing_else() throws Exception { List<RobotCompletionProposalSet> sets = new ArrayList<RobotCompletionProposalSet>(); sets.add(new RobotCompletionProposalSet()); sets.add(new RobotCompletionProposalSet()); ICompletionProposal[] actual = filter.extractMostRelevantProposals(sets); assertNull(actual); }
@Test public void should_ignore_empty_proposalSets_when_something_else() throws Exception { RobotCompletionProposalSet empty = new RobotCompletionProposalSet(); RobotCompletionProposalSet notEmpty = new RobotCompletionProposalSet(); notEmpty.setBasedOnInput(false); ICompletionProposal[] expected = addProposalsTo(notEmpty, 2, "notEmpty"); List<RobotCompletionProposalSet> sets = new ArrayList<RobotCompletionProposalSet>(); sets.add(empty); sets.add(notEmpty); ICompletionProposal[] actual = filter.extractMostRelevantProposals(sets); assertArrayEquals(expected, actual); }
@Test public void should_return_single_proposalSet_in_different_states() throws Exception { RobotCompletionProposalSet set1 = new RobotCompletionProposalSet(); set1.setBasedOnInput(false); RobotCompletionProposalSet set2 = new RobotCompletionProposalSet(); set2.setBasedOnInput(false); set2.setPriorityProposal(); RobotCompletionProposalSet set3 = new RobotCompletionProposalSet(); set3.setBasedOnInput(true); RobotCompletionProposalSet set4 = new RobotCompletionProposalSet(); set4.setBasedOnInput(true); set4.setPriorityProposal(); for (RobotCompletionProposalSet set : new RobotCompletionProposalSet[] { set1, set2, set3, set4 }) { ICompletionProposal[] expected = addProposalsTo(set, 3, "set"); List<RobotCompletionProposalSet> sets = new ArrayList<RobotCompletionProposalSet>(); sets.add(set); ICompletionProposal[] actual = filter.extractMostRelevantProposals(sets); assertArrayEquals(expected, actual); } }
@Test public void should_only_return_proposals_based_on_input_regardless_of_high_priority() throws Exception { RobotCompletionProposalSet setHighPriorityNotBasedOnInput = new RobotCompletionProposalSet(); setHighPriorityNotBasedOnInput.setBasedOnInput(false); setHighPriorityNotBasedOnInput.setPriorityProposal(); RobotCompletionProposalSet setNormalPriorityBasedOnInput = new RobotCompletionProposalSet(); setNormalPriorityBasedOnInput.setBasedOnInput(true); addProposalsTo(setHighPriorityNotBasedOnInput, 3, "setHighPriorityNotBasedOnInput"); ICompletionProposal[] expectedNormalPriorityBasedOnInput = addProposalsTo(setNormalPriorityBasedOnInput, 3, "setNormalPriorityBasedOnInput"); List<RobotCompletionProposalSet> sets = new ArrayList<RobotCompletionProposalSet>(); sets.add(setHighPriorityNotBasedOnInput); sets.add(setNormalPriorityBasedOnInput); ICompletionProposal[] actual = filter.extractMostRelevantProposals(sets); assertArrayEquals(expectedNormalPriorityBasedOnInput, actual); }