TargetCompleter implements Completer { @Override public int complete( Session session, CommandLine commandLine, List<String> candidates ) { StringsCompleter delegate = new StringsCompleter( false ); delegate.getStrings().addAll( SupportedTarget.allString()); return delegate.complete( session, commandLine, candidates ); }  @Override int complete( Session session, CommandLine commandLine, List<String> candidates );  }
@Test public void testComplete() { Session session = Mockito.mock( Session.class ); CommandLine commandLine = Mockito.mock( CommandLine.class ); Mockito.when( commandLine.getCursorArgument()).thenReturn( "" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( 0 ); TargetCompleter completer = new TargetCompleter(); List<String> candidates = new ArrayList<> (); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( 0, completer.complete( session, commandLine, candidates )); Assert.assertEquals( SupportedTarget.allString().size(), candidates.size()); candidates = new ArrayList<> (); Mockito.when( commandLine.getCursorArgument()).thenReturn( "opens" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( 5 ); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( -5, completer.complete( session, commandLine, candidates )); Assert.assertEquals( 1, candidates.size()); Assert.assertEquals( SupportedTarget.OPENSTACK.toString().toLowerCase(), candidates.get( 0 ).trim()); candidates = new ArrayList<> (); Mockito.when( commandLine.getCursorArgument()).thenReturn( "opeNs" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( 5 ); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( -5, completer.complete( session, commandLine, candidates )); Assert.assertEquals( 1, candidates.size()); Assert.assertEquals( SupportedTarget.OPENSTACK.toString().toLowerCase(), candidates.get( 0 ).trim()); candidates = new ArrayList<> (); Mockito.when( commandLine.getCursorArgument()).thenReturn( "unknown" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( "unknown".length()); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( -1, completer.complete( session, commandLine, candidates )); }