@@ -0,0 +1,2262 @@
+/*%0A * Copyright 2015-2016 the original author or authors.%0A *%0A * All rights reserved. This program and the accompanying materials are%0A * made available under the terms of the Eclipse Public License v1.0 which%0A * accompanies this distribution and is available at%0A *%0A * http://www.eclipse.org/legal/epl-v10.html%0A */%0A%0Apackage org.junit.gen5.engine.junit5.descriptor;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport org.junit.gen5.api.Executable;%0Aimport org.junit.gen5.commons.util.Preconditions;%0A%0A/**%0A * Simple component that can be used to collect one or more instances of%0A * %7B@link Throwable%7D.%0A *%0A * @since 5.0%0A */%0Aclass ThrowableCollector %7B%0A%0A%09private final List%3CThrowable%3E throwables = new ArrayList%3C%3E();%0A%0A%09/**%0A%09 * Execute the supplied %7B@link Executable%7D and %7B@link #add collect%7D any%0A%09 * %7B@link Throwable%7D thrown during the execution.%0A%09 *%0A%09 * @param executable the %7B@code Executable%7D to execute%0A%09 * @see #add(Throwable)%0A%09 * @see #getThrowables()%0A%09 * @see #assertEmpty()%0A%09 */%0A%09void execute(Executable executable) %7B%0A%09%09try %7B%0A%09%09%09executable.execute();%0A%09%09%7D%0A%09%09catch (Throwable t) %7B%0A%09%09%09add(t);%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * Add the supplied %7B@link Throwable%7D to this collector.%0A%09 *%0A%09 * @param t the %7B@code Throwable%7D to add%0A%09 * @see #execute(Executable)%0A%09 * @see #getThrowables()%0A%09 * @see #assertEmpty()%0A%09 */%0A%09void add(Throwable t) %7B%0A%09%09Preconditions.notNull(t, %22Throwable must not be null%22);%0A%09%09this.throwables.add(t);%0A%09%7D%0A%0A%09/**%0A%09 * Get the list of %7B@link Throwable Throwables%7D collected by this%0A%09 * %7B@code ThrowableCollector%7D.%0A%09 *%0A%09 * @return an unmodifiable list of throwables%0A%09 */%0A%09List%3CThrowable%3E getThrowables() %7B%0A%09%09return Collections.unmodifiableList(this.throwables);%0A%09%7D%0A%0A%09/**%0A%09 * Assert that this %7B@code ThrowableCollector%7D is %3Cem%3Eempty%3C/em%3E.%0A%09 *%0A%09 * %3Cp%3EIf this collector is not empty, the first collected %7B@link Throwable%7D%0A%09 * will be thrown with any additional throwables%0A%09 * %7B@linkplain Throwable#addSuppressed(Throwable) suppressed%7D in the%0A%09 * first %7B@code Throwable%7D.%0A%09 *%0A%09 * @throws Throwable if this collector is not empty%0A%09 */%0A%09void assertEmpty() throws Throwable %7B%0A%09%09if (!this.throwables.isEmpty()) %7B%0A%09%09%09Throwable t = this.throwables.get(0);%0A%09%09%09this.throwables.stream().skip(1).forEach(t::addSuppressed);%0A%09%09%09throw t;%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Introduce ThrowableCollector