Junit Test cases for Camunda External Task Client

Hello,
I’m stuck with writing the Junit for the below code, could you please help me on this.

    @Bean
    public void ExtClient() {
        ExternalTaskClient client = ExternalTaskClient.create().baseUrl(baseUrl)
            .addInterceptor(new NotificationClientRequestInterceptor()).asyncResponseTimeout(asyncTimeOut)
            .workerId(workerId).maxTasks(maxTasks).build();
        client.subscribe(topicName).lockDuration(100000L).handler((externalTask, externalTaskService) -> {
		externalTaskService.complete(externalTask);
		}).open();
public class NotificationClientRequestInterceptor implements ClientRequestInterceptor {
        @Override
        public void intercept(ClientRequestContext requestContext) {
            requestContext.addHeader("AuthToken", tokenAccessor.getAccessToken());
        }
    }

I’m new to Camunda, can anyone please help me on this.

@Ingo_Richtsmeier Could you please help me on this.

Hi @Ramanaiah,

a JUnit test for an external task client should test the handler, all other parts are tested by the external task client library.

If you separate the Lambda function into a method, you can call it in your test and provide mock objects for the task and the service and do assertions on your mocks.

Hope this helps, Ingo

@Ingo_Richtsmeier , Do we have any code snippets for it like example ,…?

Hi @Ramanaiah,

sorry, I don’t have any working code snippet available.

@Ingo_Richtsmeier , Thank you, I’m able to extract lambda expression and able to cover the code.