Hendrik
Hendrik

Reputation: 360

Java JUnit 5 AssertAll Stream

I'm having

ArrayList<Executable>( () -> assertTrue(true), ... )

now I'm trying to convert it into an Stream<Executable> to use assertAll Method.

  public static void assertAll(Stream<Executable> executables)
                                                   throws MultipleFailuresError

How can I convert a ArrayList<Executable>(if there is no cleaner way than ArrayList) into a Stream<Executable>?

Reference: http://junit.org/junit5/docs/current/api/org/junit/jupiter/api/Assertions.html#assertAll-org.junit.jupiter.api.function.Executable...-

Upvotes: 2

Views: 3072

Answers (1)

M A
M A

Reputation: 72854

Just call the stream() method which is inherited by all classes implementing Collection:

assertAll(executableList.stream());

Note that if you already have the elements of the ArrayList readily available, you can already pass them to assertAll, as there is an overloaded method that takes varargs input:

assertAll(() -> assertTrue(true), ...)

This way there is no need to create an ArrayList or Stream.

Upvotes: 4

Related Questions