ParsingQualityReporterImpl implements IParsingQualityReporter { @Override public final void lineError(String error, String details, int lineNum, String offendingLine) { String errorMessage = error; if (error == null) { errorMessage = "unknown error"; } final int val = m_errors.add(errorMessage); if (val <= MAX_ERROR_PER_TYPE) { m_out.printf("Error at line %d:%n%s%n%s", lineNum, offendingLine, errorMessage); if (details != null && details.length() > 0) { m_out.printf(" (%s)", details); } m_out.printf("%n%n"); } else if (val == MAX_ERROR_PER_TYPE + 1) { m_out.printf("'%s' repeated %d times. It will no longer be reported.%n%n", errorMessage, val); } } ParsingQualityReporterImpl();  ParsingQualityReporterImpl(PrintStream out); @Override final void open(String fileName); @Override final void addEvent(String name); @Override final void lineError(String error, String details, int lineNum, String offendingLine); final void printSummary(); @Override final void close();  }
@Test public void testLineErrorShowsError() throws UnsupportedEncodingException { reporter.lineError("scary error", "this error is very bad", 5, "I'm an offending line"); String results = bytes.toString("UTF-8"); System.out.println(results); assertThat(results, allOf(containsString("scary error"), containsString("5"), containsString("this error is very bad"), containsString("I'm an offending line"))); }
@Test public void testLineErrorDoesntShowMoreThanMaxOfType() throws UnsupportedEncodingException { String results; for (int i = 0; i < 3; i++) { reporter.lineError("scary error", "this error is very bad", i, "I'm an offending line"); results = bytes.toString("UTF-8"); assertThat(results, allOf(containsString("scary error"), containsString(Integer.toString(i)), containsString("this error is very bad"), containsString("I'm an offending line"))); } reporter.lineError("scary error", "this error is very bad", 34, "I'm the 4th offensive line" ); results = bytes.toString("UTF-8"); assertThat(results, allOf(containsString("It will no longer be reported."), not(containsString("Error at line 34")))); }