TableAttemptVisitor implements AttemptVisitor { @Override public RobotCompletionProposalSet visitAttempt(String attempt, IRegion replacementRegion) { assert attempt.equals(attempt.toLowerCase()); Map<String, RobotCompletionProposal> ourProposals = new LinkedHashMap<String, RobotCompletionProposal>(); String tableArgument = ParserUtil.parseTable(attempt); for (Entry<String, String> e : tableNameToFull.entrySet()) { if (e.getKey().startsWith(tableArgument)) { String proposal = e.getValue(); Image image = null; String displayString = e.getValue(); String additionalProposalInfo = null; String informationDisplayString = null; RobotCompletionProposal rcp = new RobotCompletionProposal(proposal, null, replacementRegion, image, displayString, informationDisplayString, additionalProposalInfo); rcp.setCursorPositionAdjustment(1); ourProposals.put(e.getValue(), rcp); } } RobotCompletionProposalSet ourProposalSet = new RobotCompletionProposalSet(); ourProposalSet.getProposals().addAll(ourProposals.values()); return ourProposalSet; } TableAttemptVisitor(IPreferenceStore preferenceStore); @Override RobotCompletionProposalSet visitAttempt(String attempt, IRegion replacementRegion);  }
@Test public void should_not_return_a_high_priority_proposalSet() { RobotCompletionProposalSet proposalSet = visitor.visitAttempt("", replacementRegion); assertThat(proposalSet.isPriorityProposal(), is(false)); }
@Test public void should_not_set_basedOnInput_property() { RobotCompletionProposalSet proposalSet = visitor.visitAttempt("", replacementRegion); try { proposalSet.isBasedOnInput(); fail("basedOnInput property was unexpectedly set"); } catch (IllegalStateException e) { } }
@Test public void should_return_all_for_empty_input() { String attempt = ""; RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, VARIABLES_PROPOSAL, SETTINGS_PROPOSAL, TEST_CASES_PROPOSAL, KEYWORDS_PROPOSAL); }
@Test public void should_return_all_for_purely_ignored_input() { String attempt = "* * *"; RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, VARIABLES_PROPOSAL, SETTINGS_PROPOSAL, TEST_CASES_PROPOSAL, KEYWORDS_PROPOSAL); }
@Test public void should_return_Variables_proposal_for_relevant_prefixes() { for (String attempt : new String[] { "v", "* vari", "*** variables ***", VARIABLES_PROPOSAL.toLowerCase() }) { RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, VARIABLES_PROPOSAL); } }
@Test public void should_return_Settings_proposal_for_relevant_prefixes() { for (String attempt : new String[] { "s", "* sett", "*** settings ***", "m", "* meta", "*** metadata ***", SETTINGS_PROPOSAL.toLowerCase() }) { RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, SETTINGS_PROPOSAL); } }
@Test public void should_return_Test_Cases_proposal_for_relevant_prefixes() { for (String attempt : new String[] { "t", "* test", "*** test cases ***", TEST_CASES_PROPOSAL.toLowerCase() }) { RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, TEST_CASES_PROPOSAL); } }
@Test public void should_return_Keywords_proposal_for_relevant_prefixes() { for (String attempt : new String[] { "k", "* key", "*** keywords ***", "u", "* use", "*** user keywords ***", KEYWORDS_PROPOSAL.toLowerCase() }) { RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet, KEYWORDS_PROPOSAL); } }
@Test public void should_not_return_any_proposals_for_irrelevant_prefixes() { for (char ch = 33; ch <= 126; ++ch) { if ("vsmtku*".indexOf(ch) != -1 || Character.isUpperCase(ch)) { continue; } String attempt = Character.toString(ch); RobotCompletionProposalSet proposalSet = visitor.visitAttempt(attempt, replacementRegion); verifyExpectedProposals(attempt, proposalSet); } }