ErrorReporter { static String toString(ParseErrorDetails details, Location location) { StringBuilder buf = new StringBuilder(); if (location != null) { buf.append("line " + location.line + ", column " + location.column); } if (details != null) { buf.append(":\n"); if (details.getFailureMessage() != null) { buf.append(details.getFailureMessage()); } else if (!details.getExpected().isEmpty()) { reportList(buf, details.getExpected()); buf.append(" expected, "); buf.append(details.getEncountered()).append(" encountered."); } else if (details.getUnexpected() != null) { buf.append("unexpected ").append(details.getUnexpected()).append('.'); } } return buf.toString(); }    }
@Test public void testToString_null() { assertEquals("", ErrorReporter.toString(null, null)); }
@Test public void testToString_nullError() { assertEquals("line 3, column 5", ErrorReporter.toString(null, new Location(3, 5))); }
@Test public void testToString_failure() { expect(error.getFailureMessage()).andReturn("failure").atLeastOnce(); replay(); assertEquals("line 3, column 5:\nfailure", ErrorReporter.toString(error, new Location(3, 5))); }
@Test public void testToString_expected() { expect(error.getFailureMessage()).andReturn(null).atLeastOnce(); expect(error.getExpected()).andReturn(Arrays.asList("foo", "bar")).atLeastOnce(); expect(error.getEncountered()).andReturn("baz"); replay(); assertEquals("line 3, column 5:\nfoo or bar expected, baz encountered." , ErrorReporter.toString(error, new Location(3, 5))); }
@Test public void testToString_unexpected() { expect(error.getFailureMessage()).andReturn(null).atLeastOnce(); expect(error.getExpected()).andReturn(Arrays.<String>asList()); expect(error.getUnexpected()).andReturn("foo").atLeastOnce(); replay(); assertEquals("line 3, column 5:\nunexpected foo." , ErrorReporter.toString(error, new Location(3, 5))); }