AggregateException extends Exception { @Override public void printStackTrace() { printStackTrace(System.err); } AggregateException();  AggregateException(List<Throwable> causes);  AggregateException(String message);  AggregateException(String message, List<Throwable> causes); void addCause(Throwable cause); synchronized List<Throwable> getCauses(); @Override void printStackTrace(); @Override void printStackTrace(PrintStream s); @Override void printStackTrace(PrintWriter s);  }
@Test public void testPrintStack() { int nbEx = 3; String CAUSEPATTERN = "CAUSE"; String SUBCAUSEPATTERN = "SUBCAUSE"; String MESSAGE = "MESSAGE"; List<Throwable> list1 = new ArrayList<Throwable>(); for (int i = 0; i < nbEx; i++) { List<Throwable> list2 = new ArrayList<Throwable>(); for (int j = 0; j < nbEx; j++) { list2.add(new Exception(SUBCAUSEPATTERN + "_" + i + "_" + j)); } AggregateException aggsub = new AggregateException(CAUSEPATTERN + "_" + i, list2); list1.add(aggsub); } AggregateException agg = new AggregateException(MESSAGE, list1); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); agg.printStackTrace(pw); String printedStack = sw.toString(); agg.printStackTrace(); Assert.assertTrue(printedStack.contains(MESSAGE)); for (int i = 0; i < nbEx; i++) { Assert.assertTrue(printedStack.contains(CAUSEPATTERN + "_" + i)); for (int j = 0; j < nbEx; j++) { Assert.assertTrue(printedStack.contains(SUBCAUSEPATTERN + "_" + i + "_" + j)); } } }