### Question:
Runnables { public static void runAll( String message, Runnable... runnables ) { Throwable exceptions = null; for ( Runnable runnable : runnables ) { try { runnable.run(); } catch ( Throwable t ) { exceptions = Exceptions.chain( exceptions, t ); } } if ( exceptions != null ) { throw new RuntimeException( message, exceptions ); } }  static void runAll( String message, Runnable... runnables ); static final Runnable EMPTY_RUNNABLE; }### Answer:
@Test void runAllMustRunAll() { Task task1 = new Task(); Task task2 = new Task(); Task task3 = new Task(); Runnables.runAll( "", task1, task2, task3 ); assertRun( task1, task2, task3 ); }
@Test void runAllMustRunAllAndPropagateError() { Task task1 = new Task(); Task task2 = new Task(); Task task3 = new Task(); Error expectedError = new Error( "Killroy was here" ); Runnable throwingTask = error( expectedError ); List<Runnable> runnables = Arrays.asList( task1, task2, task3, throwingTask ); Collections.shuffle(runnables ); String failureMessage = "Something wrong, Killroy must be here somewhere."; RuntimeException actual = assertThrows( RuntimeException.class, () -> Runnables.runAll( failureMessage, runnables.toArray( new Runnable[0] ) ) ); assertRun( task1, task2, task3 ); assertTrue( Exceptions.findCauseOrSuppressed( actual, t -> t == expectedError ).isPresent() ); assertEquals( failureMessage, actual.getMessage() ); }
@Test void runAllMustRunAllAndPropagateMultipleErrors() { Task task1 = new Task(); Task task2 = new Task(); Task task3 = new Task(); Error expectedError = new Error( "Killroy was here" ); Runnable throwingTask1 = error( expectedError ); RuntimeException expectedException = new RuntimeException( "and here" ); Runnable throwingTask2 = runtimeException( expectedException ); List<Runnable> runnables = Arrays.asList( task1, task2, task3, throwingTask1, throwingTask2 ); Collections.shuffle(runnables ); String failureMessage = "Something wrong, Killroy must be here somewhere."; RuntimeException actual = assertThrows( RuntimeException.class, () -> Runnables.runAll( failureMessage, runnables.toArray( new Runnable[0] ) ) ); assertRun( task1, task2, task3 ); assertTrue( Exceptions.findCauseOrSuppressed( actual, t -> t == expectedError ).isPresent() ); assertTrue( Exceptions.findCauseOrSuppressed( actual, t -> t == expectedException ).isPresent() ); assertEquals( failureMessage, actual.getMessage() ); }