Sample worker code :
@JobWorker(type = "addAttachmentDecision",autoComplete = false)
public void addAttachmentDecision(ActivatedJob job, JobClient client){
log.info("add Attachments to Decision");
Map<String, Object> variableMap = job.getVariablesAsMap();
variableMap.put(ProcessVariableConstants.MANUAL_DECISION,true);
client.newCompleteCommand(job).variables(variableMap).send().join();
}
@hitu9909 Can you share the test cases and client config?
@Mock
private JobClient client;
@Mock
private ActivatedJob job;
private MakeDecisionWorker worker;
@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
worker = new MakeDecisionWorker();
}
@Test
public void testAddAttachmentDecision() {
Map<String, Object> variables = new HashMap<>();
when(job.getVariablesAsMap()).thenReturn(variables);
worker.addAttachmentDecision(job, client);
assertTrue(variables.containsKey(ProcessVariableConstants.MANUAL_DECISION));
assertEquals(true, variables.get(ProcessVariableConstants.MANUAL_DECISION));
verify(client).newCompleteCommand(job);
}
@hitu9909 You can try something like below. Here’s the unit test using Mockito deep stubs.
class MakeDecisionWorkerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private JobClient client;
@Mock
private ActivatedJob job;
private MakeDecisionWorker worker;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
worker = new MakeDecisionWorker();
}
@Test
void testAddAttachmentDecision() {
Map<String, Object> variables = new HashMap<>();
when(job.getVariablesAsMap()).thenReturn(variables);
when(client.newCompleteCommand(job).variables(variables).send())
.thenReturn(CompletableFuture.completedFuture(null));
worker.addAttachmentDecision(job, client);
assertTrue(variables.containsKey(ProcessVariableConstants.MANUAL_DECISION));
assertEquals(true, variables.get(ProcessVariableConstants.MANUAL_DECISION));
verify(client.newCompleteCommand(job).variables(variables)).send();
}
}