| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
package org.junit.jupiter.api; |
| 12 |
|
| 13 |
import java.util.Arrays; |
| 14 |
import java.util.Collection; |
| 15 |
import java.util.List; |
| 16 |
import java.util.Objects; |
| 17 |
import java.util.stream.Collectors; |
| 18 |
import java.util.stream.Stream; |
| 19 |
|
| 20 |
import org.junit.jupiter.api.function.Executable; |
| 21 |
import org.junit.platform.commons.util.Preconditions; |
| 22 |
import org.junit.platform.commons.util.UnrecoverableExceptions; |
| 23 |
import org.opentest4j.MultipleFailuresError; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class AssertAll { |
| 32 |
|
| 33 |
private AssertAll() { |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
static void assertAll(Executable... executables) { |
| 38 |
assertAll(null, executables); |
| 39 |
} |
| 40 |
|
| 41 |
static void assertAll(String heading, Executable... executables) { |
| 42 |
Preconditions.notEmpty(executables, "executables array must not be null or empty"); |
| 43 |
Preconditions.containsNoNullElements(executables, "individual executables must not be null"); |
| 44 |
assertAll(heading, Arrays.stream(executables)); |
| 45 |
} |
| 46 |
|
| 47 |
static void assertAll(Collection<Executable> executables) { |
| 48 |
assertAll(null, executables); |
| 49 |
} |
| 50 |
|
| 51 |
static void assertAll(String heading, Collection<Executable> executables) { |
| 52 |
Preconditions.notNull(executables, "executables collection must not be null"); |
| 53 |
Preconditions.containsNoNullElements(executables, "individual executables must not be null"); |
| 54 |
assertAll(heading, executables.stream()); |
| 55 |
} |
| 56 |
|
| 57 |
static void assertAll(Stream<Executable> executables) { |
| 58 |
assertAll(null, executables); |
| 59 |
} |
| 60 |
|
| 61 |
static void assertAll(String heading, Stream<Executable> executables) { |
| 62 |
Preconditions.notNull(executables, "executables stream must not be null"); |
| 63 |
|
| 64 |
List<Throwable> failures = executables |
| 65 |
.map(executable -> { |
| 66 |
Preconditions.notNull(executable, "individual executables must not be null"); |
| 67 |
try { |
| 68 |
executable.execute(); |
| 69 |
return null; |
| 70 |
} |
| 71 |
catch (Throwable t) { |
| 72 |
UnrecoverableExceptions.rethrowIfUnrecoverable(t); |
| 73 |
return t; |
| 74 |
} |
| 75 |
}) |
| 76 |
.filter(Objects::nonNull) |
| 77 |
.collect(Collectors.toList()); |
| 78 |
|
| 79 |
if (!failures.isEmpty()) { |
| 80 |
MultipleFailuresError multipleFailuresError = new MultipleFailuresError(heading, failures); |
| 81 |
failures.forEach(multipleFailuresError::addSuppressed); |
| 82 |
throw multipleFailuresError; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
} |