Mocking JavaDelegates

We’re not working in the Cloud and not with Spring.
We’re setting the unit tests for our bpmn flows.
At first we were breaking down the flow into it’s activities and have them tested one at a time… (a “unit” test)
But then found a more progressive way to do it with:

processEngineRule.getRuntimeService().createProcessInstanceByKey(“bpmnProcessKey”)
.startBeforeActivity(“startingActivityId”)
.setVariables(executionVariables)
.executeWithVariablesInReturn();

The “problem” is that we cannot stop after that one activity and it runs until the end of the flow.
So, we’ve added a few things which mock the activities on the way.
For service tasks which are connectors:
@BeforeClass
public static void startEnv() {
HttpConnector connector = Connectors.getConnector(HttpConnector.ID);

    connector.addRequestInterceptor(invocation -> {
        ConnectorRequest<?> request = invocation.getRequest();
        final MockHttpResponse mockHttpResponse = new MockHttpResponse(); //a simple class which extends BasicHttpResponse implements CloseableHttpResponse
        String url = request.getRequestParameter("url");

        if (url != null && url.contains(specificURLConditions)) {
            mockHttpResponse.setEntity(new StringEntity(jsonResponse, ContentType.APPLICATION_JSON));
            mockHttpResponse.setStatusCode(200);
            return mockHttpResponse;
        }
        return invocation.proceed();
    });
}

For SubProcesses it’s the easiest way with:
registerCallActivityMock(SUB_PROCESS_ID)
.deploy(processEngineRule);

However I cannot find a way to mock a service which is implemented by a JavaDelegate class.
I saw that there’s an @Inject option which means to duplicate all the JavaDelegate classes… Is there another way?
We’re using the JavaDelegates to make DB calls and this is not covered in a connector or any service yet. In the past we used an in memory DB to have the expected data but I want to mock it altogether like the call to mock a sub process.

Could someone share what could be a solution in my case?
Is there any repository with a similar issue I’m facing?

Thanks,

  • Itamar