I want to use camunda-bpm-assert-scenario in my ScalaTests.
There I have this code with receiveTask::receive
:
when(documentRequest.waitsAtReceiveTask("ReceiveTaskWaitForDocuments")).thenReturn((receiveTask) -> {
receiveTask.defer("P1DT1M", receiveTask::receive);
});
According to answer in Is it possible to use a Java 8 style method references in Scala? I can translate this quite easily to:
receiveTask.defer("P1D", receiveTask.receive _)
But this gives me:
Error:(84, 45) type mismatch;
found : Unit
required: org.camunda.bpm.scenario.defer.Deferred
receiveTask.defer("P1D", receiveTask.receive _)
This is the receive
function:
void receive();
And here is the expected interface:
public interface Deferred {
void execute() throws Exception;
}
How can I achieve this in Scala? This is not a duplicate of Is it possible to use a Java 8 style method references in Scala?, there is no solution to "Error:(84, 45) type mismatch; ..."
After reading this stackoverflow answer, I could solve it to:
receiveTask.defer("P1D", new Deferred{
def execute(): Unit = receiveTask.receive()
})
Intellij proposed then to convert it to a Single Abstract Method:
receiveTask.defer("P1D", () => receiveTask.receive())
The problem was that receive
had also an overloaded function that takes a parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With