diff --git a/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/acceptance/GitConsoleInputPDETest.java b/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/acceptance/GitConsoleInputPDETest.java index 1e720493..89a2dedb 100644 --- a/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/acceptance/GitConsoleInputPDETest.java +++ b/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/acceptance/GitConsoleInputPDETest.java @@ -137,6 +137,19 @@ public void testEnterUnrecognizedCommandWithGitPrefix() { .containsLines( line( "repo", "git foo" ), "Unrecognized command: foo", line( "repo" ) ); } + @Test + public void testEnterUnrecognizedCommandWhileNoRepositoryInUse() { + console.open( configurer.createConfigurer() ); + + console.enterCommandLine( "foo" ); + + assertThat( console ) + .hasProcessedCommandLine() + .caretIsAtEnd() + .containsLines( line( "no repository", "foo" ), "Unrecognized command: foo", line( "no repository" ) ); + + } + @Test public void testType() { console.open( configurer.createConfigurer( "repo" ) ); diff --git a/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreterPDETest.java b/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreterPDETest.java index b38a11f3..2cce5629 100644 --- a/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreterPDETest.java +++ b/com.codeaffine.gonsole.pdetest/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreterPDETest.java @@ -22,10 +22,17 @@ public class GitCommandInterpreterPDETest { @Rule public final RunInThreadRule runInThreadRule = new RunInThreadRule(); @Rule public final GitConsoleHelper configurer = new GitConsoleHelper(); - private GitCommandInterpreter interpreter; + private CompositeRepositoryProvider repositoryProvider; + @Before + public void setUp() { + File gitDirectory = configurer.createRepositories( "repo" )[ 0 ]; + repositoryProvider = createWithSingleChildProvider( gitDirectory ); + } @Test public void testIsRecognizedForKnownCommand() { + GitCommandInterpreter interpreter = createInterpreter(); + boolean recognized = interpreter.isRecognized( "status" ); assertThat( recognized ).isTrue(); @@ -33,6 +40,8 @@ public void testIsRecognizedForKnownCommand() { @Test public void testIsRecognizedForKnownCommandWithInvalidArguments() { + GitCommandInterpreter interpreter = createInterpreter(); + boolean recognized = interpreter.isRecognized( "status", "invalid", "argument" ); assertThat( recognized ).isTrue(); @@ -40,6 +49,18 @@ public void testIsRecognizedForKnownCommandWithInvalidArguments() { @Test public void testIsRecognizedForUnknownCommand() { + GitCommandInterpreter interpreter = createInterpreter(); + + boolean recognized = interpreter.isRecognized( "unknown" ); + + assertThat( recognized ).isFalse(); + } + + @Test + public void testIsRecognizedForUnknownCommandWhileNoRepositoryInUse() { + repositoryProvider.setCurrentRepositoryLocation( null ); + GitCommandInterpreter interpreter = createInterpreter(); + boolean recognized = interpreter.isRecognized( "unknown" ); assertThat( recognized ).isFalse(); @@ -48,6 +69,8 @@ public void testIsRecognizedForUnknownCommand() { @Test @RunInThread public void testIsRecognizedFromBackgroundThread() { + GitCommandInterpreter interpreter = createInterpreter(); + boolean recognized = interpreter.isRecognized( "status" ); assertThat( recognized ).isTrue(); @@ -55,6 +78,8 @@ public void testIsRecognizedFromBackgroundThread() { @Test public void testExecuteForKnownCommand() { + GitCommandInterpreter interpreter = createInterpreter(); + String executionResult = interpreter.execute( "status" ); assertThat( executionResult ).isNull(); @@ -62,6 +87,8 @@ public void testExecuteForKnownCommand() { @Test public void testExecuteForKnownCommandWithInvalidArguments() { + GitCommandInterpreter interpreter = createInterpreter(); + String executionResult = interpreter.execute( "status", "invalid", "argument" ); assertThat( executionResult ).isNull(); @@ -70,15 +97,17 @@ public void testExecuteForKnownCommandWithInvalidArguments() { @Test @RunInThread public void testExecuteFromBackgroundThread() { + GitCommandInterpreter interpreter = createInterpreter(); + String executionResult = interpreter.execute( "status" ); assertThat( executionResult ).isNull(); } - @Before - public void setUp() { - File gitDirectory = configurer.createRepositories( "repo" )[ 0 ]; - CompositeRepositoryProvider repositoryProvider = createWithSingleChildProvider( gitDirectory ); - interpreter = new GitCommandInterpreter( mock( ConsoleOutput.class ), repositoryProvider ); + private GitCommandInterpreter createInterpreter() { + ConsoleOutput consoleOutput = mock( ConsoleOutput.class ); + File currentRepositoryLocation = repositoryProvider.getCurrentRepositoryLocation(); + CommandExecutor commandExecutor = new CommandExecutor( consoleOutput, currentRepositoryLocation ); + return new GitCommandInterpreter( commandExecutor, new CommandLineParser() ); } } diff --git a/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreter.java b/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreter.java index 15c81922..7f8ad21b 100644 --- a/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreter.java +++ b/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/interpreter/GitCommandInterpreter.java @@ -44,7 +44,7 @@ public String execute( String... commandLine ) { private String[] resolveAlias( String[] commandLine ) { String[] result = commandLine.clone(); - if( result.length >= 1 ) { + if( result.length >= 1 && commandExecutor.getRepositoryLocation() != null ) { AliasConfig aliasConfig = new AliasConfig( commandExecutor.getRepositoryLocation() ); String command = aliasConfig.getCommand( commandLine[ 0 ] ); if( command != null ) {