Source:
<code>public void testStartProcessAndAbortThenChangeVariables() { assertNotNull(deploymentService); KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION); deploymentService.deploy(deploymentUnit); units.add(deploymentUnit); Map<String, Object> params = new HashMap<String, Object>(); params.put("approval_document", "test"); params.put("approval_reviewComment", "need review"); long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params); assertNotNull(processInstanceId); processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId); ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId); assertNull(pi); <START> try { <END> processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment"); fail("Process instance was aborted so variables do not exist"); } catch (ProcessInstanceNotFoundException e) { } try { processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment"); fail("Process instance was aborted so variables do not exist"); } catch (ProcessInstanceNotFoundException e) { } params = new HashMap<String, Object>(); params.put("approval_document", "updated document"); params.put("approval_reviewComment", "final review"); try { processService.setProcessVariables(deploymentUnit.getIdentifier(), processInstanceId, params); fail("Process instance was aborted so cannot be changed"); } catch (ProcessInstanceNotFoundException e) { } try { processService.setProcessVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment", "updated review comment"); fail("Process instance was aborted so cannot be changed"); } catch (ProcessInstanceNotFoundException e) { } }</code><technical_language>This try-catch blocks repeat; worth making a utility method(s) of them. Secondly, tip - AssertJ offers nice capabilities for dealing exceptions <LINK_0></technical_language>

Target:
public void testStartProcessAndAbortThenChangeVariables() { assertNotNull(deploymentService); KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION); deploymentService.deploy(deploymentUnit); units.add(deploymentUnit); final Map<String, Object> params = new HashMap<String, Object>(); params.put("approval_document", "test"); params.put("approval_reviewComment", "need review"); long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params); assertNotNull(processInstanceId); processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId); ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId); assertNull(pi); assertThatExceptionOfType(ProcessInstanceNotFoundException.class).isThrownBy(() -> { processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment"); }); params.clear(); params.put("approval_document", "updated document"); params.put("approval_reviewComment", "final review"); assertThatExceptionOfType(ProcessInstanceNotFoundException.class).isThrownBy(() -> { processService.setProcessVariables(deploymentUnit.getIdentifier(), processInstanceId, params); }); assertThatExceptionOfType(ProcessInstanceNotFoundException.class).isThrownBy(() -> { processService.setProcessVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment", "updated review comment"); }); }