LogLevelCompleter implements Completer { @Override public int complete( Session session, CommandLine commandLine, List<String> candidates ) { StringsCompleter delegate = new StringsCompleter( false ); for( Level level : LEVELS ) delegate.getStrings().add( level.toString()); return delegate.complete( session, commandLine, candidates ); }  @Override int complete( Session session, CommandLine commandLine, List<String> candidates ); static String all();  }
@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 ); LogLevelCompleter completer = new LogLevelCompleter(); List<String> candidates = new ArrayList<> (); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( 0, completer.complete( session, commandLine, candidates )); Assert.assertEquals( LogLevelCompleter.LEVELS.length, candidates.size()); candidates = new ArrayList<> (); Mockito.when( commandLine.getCursorArgument()).thenReturn( "I" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( 1 ); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( -1, completer.complete( session, commandLine, candidates )); Assert.assertEquals( 1, candidates.size()); Assert.assertEquals( Level.INFO.toString(), candidates.get( 0 ).trim()); candidates = new ArrayList<> (); Mockito.when( commandLine.getCursorArgument()).thenReturn( "i" ); Mockito.when( commandLine.getArgumentPosition()).thenReturn( 1 ); Assert.assertEquals( 0, candidates.size()); Assert.assertEquals( -1, completer.complete( session, commandLine, candidates )); Assert.assertEquals( 1, candidates.size()); Assert.assertEquals( Level.INFO.toString(), 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 )); }