public String getErrorMessage(RecognitionException e) { if (null == walker) { return e.toString(); } else { return getErrorMessage(walker, e); } }
@Test public void testTheKitty() { try { runTestWithString("sduhfdkufdhkjs;"); fail("Should have thrownb an exception"); } catch (RecognitionException e) { System.out.println("Expected " + e.toString()); } catch (Exception e) { System.out.println("UnExpected " + e.toString()); fail(e.getMessage()); } }
@Test public void duplicatedAliasTestFrom() { String statement = "SELECT * FROM T1 MyAlias JOIN T2 AS MyAlias"; try { traverseStatement(statement); fail("Parsing statement " + statement + " should fail."); } catch (RecognitionException e) { assertTrue(e instanceof FailedPredicateException); LOG.debug("duplicatedAliasTestFrom(), exception: " + e); // walker.reportError(e); String errorMessage = queryUtil.getErrorMessage(e); LOG.debug(""); LOG.debug("duplicatedAliasTestFrom(), error message: " + errorMessage); assertTrue(e.toString().contains("more than once as alias in a from")); assertTrue(errorMessage.contains("more than once as alias in a from")); } catch (Exception e) { fail( "Parsing statement " + statement + " should fail with RecognitionException, but was: " + e.getClass()); } }