ResultPrinter { public void print(String record) throws HyracksDataException { printPrefix(); displayRecord(record); printPostfix(); } ResultPrinter(IApplicationContext appCtx, SessionOutput output, Stats stats, ARecordType recordType); void print(String record); void print(ResultReader resultReader);  }
@Test public void exceptionWhilePrinting() throws Exception { final RuntimeException expectedException = new RuntimeException("Error reading result"); final IApplicationContext appCtx = Mockito.mock(IApplicationContext.class); final CompilerProperties compilerProperties = Mockito.mock(CompilerProperties.class); Mockito.when(appCtx.getCompilerProperties()).thenReturn(compilerProperties); Mockito.when(compilerProperties.getFrameSize()).thenReturn(StorageUtil.getIntSizeInBytes(32, KILOBYTE)); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter out = new PrintWriter(baos, true); final SessionOutput sessionOutput = createSessionOutput(out); final ResultPrinter rs = new ResultPrinter(appCtx, sessionOutput, new IStatementExecutor.Stats(), null); final ResultReader resultReader = Mockito.mock(ResultReader.class); Mockito.when(resultReader.getFrameTupleAccessor()).thenThrow(new RuntimeException(expectedException)); out.print("{"); try { rs.print(resultReader); } catch (RuntimeException e) { final ExecutionError error = ExecutionError.of(e); new ErrorsPrinter(Collections.singletonList(error)).print(out); printMetrics(out, 1); } out.print("}"); out.flush(); final String resultStr = new String(baos.toByteArray(), StandardCharsets.UTF_8); boolean exceptionThrown = false; try { ResultExtractor.extract(IOUtils.toInputStream(resultStr, StandardCharsets.UTF_8), StandardCharsets.UTF_8, TestCaseContext.OutputFormat.CLEAN_JSON).getResult(); } catch (Exception e) { exceptionThrown = true; Assert.assertTrue(e.getMessage().contains(expectedException.getMessage())); } Assert.assertTrue(exceptionThrown); }