protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) { StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel); if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) { output.println().append(getEventPath(descriptor)); output.withStyle(getStyle(event)).println(event.toString()); } lastSeenTestDescriptor = descriptor; lastSeenTestEvent = event; if (details != null) { output.append(TextUtil.toPlatformLineSeparators(details)); } }
private StyledTextOutput.Style getStyle(TestLogEvent event) { switch (event) { case PASSED: return StyledTextOutput.Style.Identifier; case FAILED: return StyledTextOutput.Style.Failure; case SKIPPED: return StyledTextOutput.Style.Info; default: return StyledTextOutput.Style.Normal; } }
@Override public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) { if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut && isLoggedEventType(TestLogEvent.STANDARD_OUT)) { logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n"); } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) { logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n"); } }
private void after(TestDescriptor descriptor, TestResult result) { TestLogEvent event = getEvent(result); if (shouldLogEvent(descriptor, event)) { String details = shouldLogExceptions(result) ? exceptionFormatter.format(descriptor, result.getExceptions()) : null; logEvent(descriptor, event, details); } }
private TestLogEvent getEvent(TestResult result) { switch (result.getResultType()) { case SUCCESS: return TestLogEvent.PASSED; case FAILURE: return TestLogEvent.FAILED; case SKIPPED: return TestLogEvent.SKIPPED; default: throw new AssertionError(); } }
public void onOutput(TestDescriptor descriptor, TestOutputEvent outputEvent) { if (outputEvent.getDestination() == TestOutputEvent.Destination.StdOut && isLoggedEventType(TestLogEvent.STANDARD_OUT)) { logEvent(descriptor, TestLogEvent.STANDARD_OUT, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n"); } else if (outputEvent.getDestination() == TestOutputEvent.Destination.StdErr && isLoggedEventType(TestLogEvent.STANDARD_ERROR)) { logEvent(descriptor, TestLogEvent.STANDARD_ERROR, TextUtil.indent(outputEvent.getMessage(), INDENT) + "\n"); } }
protected void logEvent(TestDescriptor descriptor, TestLogEvent event) { logEvent(descriptor, event, null); }
private void before(TestDescriptor descriptor) { if (shouldLogEvent(descriptor, TestLogEvent.STARTED)) { logEvent(descriptor, TestLogEvent.STARTED); } }
private boolean shouldLogEvent(TestDescriptor descriptor, TestLogEvent event) { return isLoggedGranularity(descriptor) && isLoggedEventType(event); }
private boolean isLoggedEventType(TestLogEvent event) { return testLogging.getEvents().contains(event); }