@Test
public void testExceptionHandling() {
final Throwable thrown1 = new RuntimeException("oh yeah");
try {
final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown1));
final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
fail("did not get exception, got " + result);
} catch (RuntimeException caught) {
assertSame("got wrong exception", thrown1, caught);
}
final Throwable thrown2 = new Error("oh yeah");
try {
final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown2));
final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
fail("did not get exception, got " + result);
} catch (Error caught) {
assertSame("got wrong exception", thrown2, caught);
}
final Throwable thrown3 = new Exception("oh yeah");
try {
final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown3));
final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
fail("did not get exception, got " + result);
} catch (RuntimeException caught) {
assertSame("got wrong exception", thrown3, caught.getCause());
}
}