SLQLFileNameCompletor extends FileNameCompletor { @Override public int complete(String buf, final int cursor, @SuppressWarnings("rawtypes") final List candidates) { for (final Command activeCommand: commands) { int complementCursorPosition = 0; boolean commandAccepted = false; if (activeCommand.getFileCompletionMode() == FileCompletionMode.STARTS_WITH) { if (buf.startsWith(activeCommand.getFileCompletionCommand() + " ")) { buf = buf.substring(activeCommand.getFileCompletionCommand().length() + 1); complementCursorPosition = activeCommand.getFileCompletionCommand().length() + 1; commandAccepted = true; } } else if (activeCommand.getFileCompletionMode() == FileCompletionMode.CONTAINS) { if (buf.contains(activeCommand.getFileCompletionCommand() + " ")) { int indexOfOutputDef = buf.lastIndexOf(activeCommand.getFileCompletionCommand() + " "); buf.substring(indexOfOutputDef); indexOfOutputDef = indexOfOutputDef + activeCommand.getFileCompletionCommand().length() + 1; buf = buf.substring(indexOfOutputDef); complementCursorPosition = indexOfOutputDef; commandAccepted = true; } } if (commandAccepted) { return super.complete(buf, cursor, candidates) + complementCursorPosition; } } return cursor; } SLQLFileNameCompletor(
                                  final Collection<Command> commands); @Override int complete(String buf,
                         final int cursor,
                         @SuppressWarnings("rawtypes") final List candidates);  }
@Test public void testCompletorNonCondidates() { final SLQLFileNameCompletor completor = new SLQLFileNameCompletor(null); final List<?> candidates = new LinkedList<Object>(); completor.complete("get ", 4, candidates); assertThat(candidates.size(), is(0)); }
@Test public void testCompletorNonCondidates2() throws InstantiationException, IllegalAccessException, ClassNotFoundException { final SLQLFileNameCompletor completor = new SLQLFileNameCompletor(DynamicCommandSupport.getRegisteredDynamicCommands()); final List<?> candidates = new LinkedList<Object>(); completor.complete("list ", 4, candidates); assertThat(candidates.size(), is(0)); }
@Test public void testCompletorSomeCondidates() throws InstantiationException, IllegalAccessException, ClassNotFoundException { final SLQLFileNameCompletor completor = new SLQLFileNameCompletor(DynamicCommandSupport.getRegisteredDynamicCommands()); final List<?> candidates = new LinkedList<Object>(); completor.complete("get ", 4, candidates); assertThat(candidates.size(), is(not(0))); }