I'm having some difficulty figuring out the correc...
# announcements
j
I'm having some difficulty figuring out the correct syntax for calling a Vararg with lambdas. The Kotlin converter in IDEA gave me what is shown below. But it results in a compile error. What's the syntax I need?
Copy code
public static void assertAll(String heading, Executable... executables)

// "Executable" is an interface with a single "execute()" method

// JAVA
assertAll("test the 'add' method",
          () -> assertEquals(4, calculator.add(2, 2)),
          () -> assertEquals(5, calculator.add(2, 3))
);

// KOTLIN
# the 'assertEquals' is underscored with error "None of the following functions can be called with the arguments supplied."
assertAll("test the 'add' method", 
          { assertEquals(4, calculator.add(2, 2)) },
          { assertEquals(5, calculator.add(2, 3)) }
         )
m
javaru: This is JUnit 5, right?
j
Yes it is
Copy code
fun assertAll(vararg executables: () -> Unit) {
    Assertions.assertAll(
            executables.map { Executable(it) }.stream()
    )
}
This is a function I added before this is implemented in Kotlin.
j
Adding the
Executable
before the lambda works like a charm. Thanks. I'll vote for the feature requesting to simplify the syntax. Thanks for the assist!
m
I'd suggest adding an
assertAll
function to your test code similar to that one I'm using to get it now.
Might take some time before this is actually implemented in Kotlin.
j
A good idea. Thanks.