@Test public void testIOException() { final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list()); final Parser parser = new DummyParser(testResult, "some source", "some string"); try { final ParseResult resultDoc = parser.parse(new Source() { @Override public BufferedReader createReader() { return new BufferedReader(new Reader() { @Override public int read(char[] cbuf, int off, int len) throws IOException { throw new IOException("eat me"); } @Override public void close() throws IOException { } }); } @Override public String getSrcInfo() { return "some source"; } }); fail("did not get exception, got " + resultDoc); } catch (RuntimeException e) { } }
@Override public ParseResult parse(Source source) { if (!testSrcInfo.equals(source.getSrcInfo())) { throw new RuntimeException("testSrcInfo and source.getSrcInfo were not equal. testSrcInfo = " + testSrcInfo + ", source.getSrcInfo = " + source.getSrcInfo()); } try { BufferedReader reader = source.createReader(); try { if (!testString.equals(reader.readLine())) { throw new RuntimeException("testString and reader.readLine() were not equal"); } final String secondLine = reader.readLine(); if (secondLine != null) { throw new RuntimeException("got a second line '" + secondLine + "' from the reader"); } } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } return testResult; }
DummyParser implements Parser { @Override public ParseResult parse(Source source) { if (!testSrcInfo.equals(source.getSrcInfo())) { throw new RuntimeException("testSrcInfo and source.getSrcInfo were not equal. testSrcInfo = " + testSrcInfo + ", source.getSrcInfo = " + source.getSrcInfo()); } try { BufferedReader reader = source.createReader(); try { if (!testString.equals(reader.readLine())) { throw new RuntimeException("testString and reader.readLine() were not equal"); } final String secondLine = reader.readLine(); if (secondLine != null) { throw new RuntimeException("got a second line '" + secondLine + "' from the reader"); } } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } return testResult; } }
DummyParser implements Parser { @Override public ParseResult parse(Source source) { if (!testSrcInfo.equals(source.getSrcInfo())) { throw new RuntimeException("testSrcInfo and source.getSrcInfo were not equal. testSrcInfo = " + testSrcInfo + ", source.getSrcInfo = " + source.getSrcInfo()); } try { BufferedReader reader = source.createReader(); try { if (!testString.equals(reader.readLine())) { throw new RuntimeException("testString and reader.readLine() were not equal"); } final String secondLine = reader.readLine(); if (secondLine != null) { throw new RuntimeException("got a second line '" + secondLine + "' from the reader"); } } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } return testResult; } DummyParser(ParseResult testResult, String testSrcInfo, String testString); }
DummyParser implements Parser { @Override public ParseResult parse(Source source) { if (!testSrcInfo.equals(source.getSrcInfo())) { throw new RuntimeException("testSrcInfo and source.getSrcInfo were not equal. testSrcInfo = " + testSrcInfo + ", source.getSrcInfo = " + source.getSrcInfo()); } try { BufferedReader reader = source.createReader(); try { if (!testString.equals(reader.readLine())) { throw new RuntimeException("testString and reader.readLine() were not equal"); } final String secondLine = reader.readLine(); if (secondLine != null) { throw new RuntimeException("got a second line '" + secondLine + "' from the reader"); } } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } return testResult; } DummyParser(ParseResult testResult, String testSrcInfo, String testString); @Override ParseResult parse(Source source); }
DummyParser implements Parser { @Override public ParseResult parse(Source source) { if (!testSrcInfo.equals(source.getSrcInfo())) { throw new RuntimeException("testSrcInfo and source.getSrcInfo were not equal. testSrcInfo = " + testSrcInfo + ", source.getSrcInfo = " + source.getSrcInfo()); } try { BufferedReader reader = source.createReader(); try { if (!testString.equals(reader.readLine())) { throw new RuntimeException("testString and reader.readLine() were not equal"); } final String secondLine = reader.readLine(); if (secondLine != null) { throw new RuntimeException("got a second line '" + secondLine + "' from the reader"); } } finally { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } return testResult; } DummyParser(ParseResult testResult, String testSrcInfo, String testString); @Override ParseResult parse(Source source);  }