6

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; ..."

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
pme
  • 14,156
  • 3
  • 52
  • 95
  • 1
    Are you on scala 2.12+? Can't check right now but `receiveTask.defer("P1D", e => receiveTask.receive(e))` shuld work. Also when it comes to Java interop you can just write `receiveTask.defer("P1D", new Deferred { override void execute ... })` and then ask IDE for suggestions how to make it less verbose. – simpadjo Sep 03 '19 at 08:19

1 Answers1

5

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.

pme
  • 14,156
  • 3
  • 52
  • 95