@Test
public void testComplete() throws Exception {

	TestApplication app = new TestApplication();
	app.directory( this.folder.newFolder());
	ManagedApplication ma = new ManagedApplication( app );
	// Mock what is required
	Session session = Mockito.mock( Session.class );
	CommandLine commandLine = Mockito.mock( CommandLine.class );
	Mockito.when( commandLine.getCursorArgument()).thenReturn( "" );
	Mockito.when( commandLine.getCursorArgumentIndex()).thenReturn( 0 );
	Mockito.when( commandLine.getArgumentPosition()).thenReturn( 0 );
	Mockito.when( commandLine.getArguments()).thenReturn( new String[ 0 ]);
	IApplicationMngr applicationMngr = Mockito.mock( IApplicationMngr.class );
	Mockito.when( applicationMngr.findManagedApplicationByName( app.getName())).thenReturn( ma );
	Manager manager = Mockito.mock( Manager.class );
	Mockito.when( manager.applicationMngr()).thenReturn( applicationMngr );
	// Nothing typed in yet
	ScopedInstanceCompleter completer = new ScopedInstanceCompleter();
	completer.manager = manager;
	List<String> candidates = new ArrayList<> ();
	Assert.assertEquals( 0, candidates.size());
	Assert.assertEquals( -1, completer.complete( session, commandLine, candidates ));
	Assert.assertEquals( 0, candidates.size());
	// Completion but no application
	candidates = new ArrayList<> ();
	Mockito.when( commandLine.getCursorArgument()).thenReturn( "/my" );
	Mockito.when( commandLine.getArgumentPosition()).thenReturn( 3 );	// "/my".length()
	Assert.assertEquals( 0, candidates.size());
	Assert.assertEquals( -1, completer.complete( session, commandLine, candidates ));
	Assert.assertEquals( 0, candidates.size());
	// Completion with an invalid application
	Mockito.when( commandLine.getArguments()).thenReturn( new String[] { "inalid" });
	Mockito.when( commandLine.getCursorArgumentIndex()).thenReturn( 1 );
	Assert.assertEquals( 0, candidates.size());
	Assert.assertEquals( -1, completer.complete( session, commandLine, candidates ));
	Assert.assertEquals( 0, candidates.size());
	// Completion with an application
	Mockito.when( commandLine.getArguments()).thenReturn( new String[] { app.getName()});
	Mockito.when( commandLine.getCursorArgumentIndex()).thenReturn( 1 );
	Assert.assertEquals( -3, completer.complete( session, commandLine, candidates ));
	Assert.assertEquals( 1, candidates.size());
	Assert.assertEquals( "/mysql-vm", candidates.get( 0 ).trim());
	// Complete "i" (case insensitive)
	candidates = new ArrayList<> ();
	Mockito.when( commandLine.getCursorArgument()).thenReturn( "/MY" );
	Mockito.when( commandLine.getArgumentPosition()).thenReturn( 3 );	// "/MY".length()
	Assert.assertEquals( 0, candidates.size());
	Assert.assertEquals( -3, completer.complete( session, commandLine, candidates ));
	Assert.assertEquals( 1, candidates.size());
	Assert.assertEquals( "/mysql-vm", candidates.get( 0 ).trim());
	// Unknown
	candidates = new ArrayList<> ();
	Mockito.when( commandLine.getCursorArgument()).thenReturn( "unknown" );
	Assert.assertEquals( 0, candidates.size());
	Assert.assertEquals( -1, completer.complete( session, commandLine, candidates ));
}