ParsingProcessOutputHandler extends BaseProcessOutputHandler { @Override public void handleOutput(@NonNull ProcessOutput processOutput) throws ProcessException { if (!(processOutput instanceof BaseProcessOutput)) { throw new IllegalArgumentException("processOutput was not created by this handler."); } BaseProcessOutput impl = (BaseProcessOutput) processOutput; String stdout = impl.getStandardOutputAsString(); if (!stdout.isEmpty()) { outputMessages(mStdoutToolOutputParser.parseToolOutput(stdout)); } String stderr = impl.getErrorOutputAsString(); if (!stderr.isEmpty()) { outputMessages(mErrorToolOutputParser.parseToolOutput(stderr)); } } ParsingProcessOutputHandler(
            @NonNull ToolOutputParser errorToolOutputParser,
            @NonNull ToolOutputParser stdoutToolOutputParser,
            @NonNull MessageReceiver... messageReceivers);  ParsingProcessOutputHandler(
            @NonNull ToolOutputParser toolOutputParser,
            @NonNull MessageReceiver... messageReceivers); @Override void handleOutput(@NonNull ProcessOutput processOutput);  }
@Test public void testRewriteMessages() throws IOException, ProcessException { String original = "error example\ntwo line error\nnext line\nsomething else"; sParsingProcessOutputHandler.handleOutput(processOutputFromErrorString(original)); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.ERROR, "errorText", "originalText", new SourceFilePosition( new SourceFile(FakePatternAwareOutputParser.ERROR_EXAMPLE_FILE), new SourcePosition(1, 2, 3, 4, 5, 6) ))); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.WARNING, "two line warning", new SourceFilePosition( new SourceFile(FakePatternAwareOutputParser.TWO_LINE_ERROR_FILE), new SourcePosition(1, 2, -1) ))); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.SIMPLE, "something else", SourceFilePosition.UNKNOWN)); Mockito.verifyNoMoreInteractions(sMessageReceiver); String expected = "AGPBI: {" + "\"kind\":\"error\"," + "\"text\":\"errorText\"," + "\"sources\":[{" + "\"file\":\"" + FakePatternAwareOutputParser.ERROR_EXAMPLE_FILE.getAbsolutePath() + "\",\"position\":{\"startLine\":1,\"startColumn\":2,\"startOffset\":3," + "\"endLine\":4,\"endColumn\":5,\"endOffset\":6}}]," + "\"original\":\"original_text\"}\n" + "AGPBI: {\"kind\":\"warning\"," + "\"text\":\"two line warning\"," + "\"sources\":[{\"file\":\"" + FakePatternAwareOutputParser.TWO_LINE_ERROR_FILE.getAbsolutePath() + "\"," + "\"position\":{\"startLine\":1,\"startColumn\":2}}]}\n" + "AGPBI: {\"kind\":\"simple\"," + "\"text\":\"something else\"," + "\"sources\":[{}]}"; }
@Test public void parseException() throws IOException, ProcessException { String original = "two line error"; sParsingProcessOutputHandler.handleOutput(processOutputFromErrorString(original)); Mockito.verifyNoMoreInteractions(sMessageReceiver); }
@Test public void testRewriteMessages() throws IOException, ProcessException { String original = "error example\ntwo line error\nnext line\nsomething else"; ProcessOutput processOutput = processOutputFromErrorString(original); processOutput.close(); sParsingProcessOutputHandler.handleOutput(processOutput); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.ERROR, "errorText", "original_text", null, new SourceFilePosition( new SourceFile(FakePatternAwareOutputParser.ERROR_EXAMPLE_FILE), new SourcePosition(1, 2, 3, 4, 5, 6) ))); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.WARNING, "two line warning", new SourceFilePosition( new SourceFile(FakePatternAwareOutputParser.TWO_LINE_ERROR_FILE), new SourcePosition(1, 2, -1) ))); Mockito.verify(sMessageReceiver).receiveMessage(new Message( Message.Kind.SIMPLE, "something else", SourceFilePosition.UNKNOWN)); Mockito.verifyNoMoreInteractions(sMessageReceiver); String expected = "AGPBI: {" + "\"kind\":\"error\"," + "\"text\":\"errorText\"," + "\"sources\":[{" + "\"file\":\"" + FakePatternAwareOutputParser.ERROR_EXAMPLE_FILE.getAbsolutePath() + "\",\"position\":{\"startLine\":1,\"startColumn\":2,\"startOffset\":3," + "\"endLine\":4,\"endColumn\":5,\"endOffset\":6}}]," + "\"original\":\"original_text\"}\n" + "AGPBI: {\"kind\":\"warning\"," + "\"text\":\"two line warning\"," + "\"sources\":[{\"file\":\"" + FakePatternAwareOutputParser.TWO_LINE_ERROR_FILE.getAbsolutePath() + "\"," + "\"position\":{\"startLine\":1,\"startColumn\":2}}]}\n" + "AGPBI: {\"kind\":\"simple\"," + "\"text\":\"something else\"," + "\"sources\":[{}]}"; }
@Test public void parseException() throws IOException, ProcessException { String original = "two line error"; ProcessOutput processOutput = processOutputFromErrorString(original); processOutput.close(); sParsingProcessOutputHandler.handleOutput(processOutput); Mockito.verifyNoMoreInteractions(sMessageReceiver); }