@Test public void testSimple() throws Exception { String input = "good1;\n" + "good2;\n"; NonInteractiveShellRunner runner = new NonInteractiveShellRunner( FailBehavior.FAIL_FAST, cmdExecuter, logger, statementParser, new ByteArrayInputStream(input.getBytes())); int code = runner.runUntilEnd(); assertEquals("Exit code incorrect", 0, code); verify(logger, times(0)).printError(anyString()); }
@Test public void testFailAtEnd() throws Exception { String input = "good1;\n" + "bad;\n" + "good2;\n" + "bad;\n"; NonInteractiveShellRunner runner = new NonInteractiveShellRunner( FailBehavior.FAIL_AT_END, cmdExecuter, logger, statementParser, new ByteArrayInputStream(input.getBytes())); int code = runner.runUntilEnd(); assertEquals("Exit code incorrect", 1, code); verify(logger, times(2)).printError(badLineError); }
@Test public void testFailFast() throws Exception { String input = "good1;\n" + "bad;\n" + "good2;\n" + "bad;\n"; NonInteractiveShellRunner runner = new NonInteractiveShellRunner( FailBehavior.FAIL_FAST, cmdExecuter, logger, statementParser, new ByteArrayInputStream(input.getBytes())); int code = runner.runUntilEnd(); assertEquals("Exit code incorrect", 1, code); verify(logger).printError(badLineError); }
@Test public void runUntilEndExitsImmediatelyOnParseError() throws Exception { // given StatementParser statementParser = mock(StatementParser.class); RuntimeException boom = new RuntimeException("BOOM"); doThrow(boom).when(statementParser).parseMoreText(anyString()); String input = "good1;\n" + "bad;\n" + "good2;\n" + "bad;\n"; NonInteractiveShellRunner runner = new NonInteractiveShellRunner( FailBehavior.FAIL_AT_END, cmdExecuter, logger, statementParser, new ByteArrayInputStream(input.getBytes())); // when int code = runner.runUntilEnd(); // then assertEquals(1, code); verify(logger).printError(boom); }
@Test public void runUntilEndExitsImmediatelyOnExitCommand() throws Exception { // given String input = "good1;\n" + "bad;\n" + "good2;\n" + "bad;\n"; NonInteractiveShellRunner runner = new NonInteractiveShellRunner( FailBehavior.FAIL_AT_END, cmdExecuter, logger, statementParser, new ByteArrayInputStream(input.getBytes())); // when doThrow(new ExitException(99)).when(cmdExecuter).execute(anyString()); int code = runner.runUntilEnd(); // then assertEquals(99, code); verify(cmdExecuter).execute("good1;"); verifyNoMoreInteractions(cmdExecuter); }