Mock JavaDelegate

Hello!

I try test my process, but I cannot mock my JavaDelegate.

I try like in this guide Testing process definitions | Camunda Platform 8 Docs

But I dont use any frameworks like spring or any CDI.

My Service Task have Java Class implementation.

Can I mock any objects in JavaDelegate or ExecutionListener if I use vanilla java.

I hope I use word “vanilla” correctly =) and sorry for my english!

Hi @Vasily,

Implementation Java class is the tightest coupling between a service task and the code called by the engine.

The process engine uses reflection internally for this. I think there is no way to hook a mock into the call without the help of a framework.

How do you run your process engine? Maybe there is a way that you can use the implementation DelegateExpression?

Hope this helps, Ingo

I pack my process in war and deploy to tomcat with camunda.

Thanks!
One more reason to use spring)

Spring is the easiest one. Then you have SpEL and it will give you component naming.
Then you can use Mocks.register("expression", instance) if you do anything manually.

A better approach is to use the extension called camunda-bpm-mockito which provides you a helper for mocking… In general it is CamundaMockito.registerJavaDelegateMock("expression").

If you want to give it behavior in your test, you would do CamundaMockito.getJavaDelegateMock("expression").onExecutionSetVariables() or CamundaMockito.getJavaDelegateMock("expression").onExecutionThrowBpmnError()

Hope this helps,