@Test public void doesNotLoadSourceLocationNone() { ValidationEvent event = ValidationEvent.builder() .id("foo") .severity(Severity.ERROR) .message("This is the message") .sourceLocation(SourceLocation.NONE) .build(); String format = new ContextualValidationEventFormatter().format(event); format = format.replace("\r\n", "\n"); assertThat(format, equalTo( "ERROR: - (foo)" + "\n = This is the message" + "\n")); }
@Override public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", event.getSeverity(), event.getShapeId().map(ShapeId::toString).orElse("-"), event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); String contextualLine = null; try { contextualLine = loadContextualLine(event.getSourceLocation()); } catch (IOException e) { } if (contextualLine == null) { formatter.format(" @ %s%n", event.getSourceLocation()); } else { formatter.format(" @ %s%n", humanReadableFilename); formatter.format(" |%n"); formatter.format("%4d | %s%n", event.getSourceLocation().getLine(), contextualLine); formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } } formatter.format(" = %s%n", event.getMessage().replace("\n", " \n")); formatter.flush(); return writer.toString(); }
ContextualValidationEventFormatter implements ValidationEventFormatter { @Override public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", event.getSeverity(), event.getShapeId().map(ShapeId::toString).orElse("-"), event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); String contextualLine = null; try { contextualLine = loadContextualLine(event.getSourceLocation()); } catch (IOException e) { } if (contextualLine == null) { formatter.format(" @ %s%n", event.getSourceLocation()); } else { formatter.format(" @ %s%n", humanReadableFilename); formatter.format(" |%n"); formatter.format("%4d | %s%n", event.getSourceLocation().getLine(), contextualLine); formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } } formatter.format(" = %s%n", event.getMessage().replace("\n", " \n")); formatter.flush(); return writer.toString(); } }
ContextualValidationEventFormatter implements ValidationEventFormatter { @Override public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", event.getSeverity(), event.getShapeId().map(ShapeId::toString).orElse("-"), event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); String contextualLine = null; try { contextualLine = loadContextualLine(event.getSourceLocation()); } catch (IOException e) { } if (contextualLine == null) { formatter.format(" @ %s%n", event.getSourceLocation()); } else { formatter.format(" @ %s%n", humanReadableFilename); formatter.format(" |%n"); formatter.format("%4d | %s%n", event.getSourceLocation().getLine(), contextualLine); formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } } formatter.format(" = %s%n", event.getMessage().replace("\n", " \n")); formatter.flush(); return writer.toString(); }  }
ContextualValidationEventFormatter implements ValidationEventFormatter { @Override public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", event.getSeverity(), event.getShapeId().map(ShapeId::toString).orElse("-"), event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); String contextualLine = null; try { contextualLine = loadContextualLine(event.getSourceLocation()); } catch (IOException e) { } if (contextualLine == null) { formatter.format(" @ %s%n", event.getSourceLocation()); } else { formatter.format(" @ %s%n", humanReadableFilename); formatter.format(" |%n"); formatter.format("%4d | %s%n", event.getSourceLocation().getLine(), contextualLine); formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } } formatter.format(" = %s%n", event.getMessage().replace("\n", " \n")); formatter.flush(); return writer.toString(); }  @Override String format(ValidationEvent event); }
ContextualValidationEventFormatter implements ValidationEventFormatter { @Override public String format(ValidationEvent event) { StringWriter writer = new StringWriter(); Formatter formatter = new Formatter(writer); formatter.format("%s: %s (%s)%n", event.getSeverity(), event.getShapeId().map(ShapeId::toString).orElse("-"), event.getId()); if (event.getSourceLocation() != SourceLocation.NONE) { String humanReadableFilename = getHumanReadableFilename(event.getSourceLocation()); String contextualLine = null; try { contextualLine = loadContextualLine(event.getSourceLocation()); } catch (IOException e) { } if (contextualLine == null) { formatter.format(" @ %s%n", event.getSourceLocation()); } else { formatter.format(" @ %s%n", humanReadableFilename); formatter.format(" |%n"); formatter.format("%4d | %s%n", event.getSourceLocation().getLine(), contextualLine); formatter.format(" | %" + event.getSourceLocation().getColumn() + "s%n", "^"); } } formatter.format(" = %s%n", event.getMessage().replace("\n", " \n")); formatter.flush(); return writer.toString(); }  @Override String format(ValidationEvent event);  }