### Question:
ProcessCancelledEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCancelledEvent cancelledEvent = (CloudProcessCancelledEvent) event; LOGGER.debug("Handling cancel of process Instance " + cancelledEvent.getEntity().getId()); updateProcessInstanceStatus( processInstanceRepository .findById(cancelledEvent.getEntity().getId()) .orElseThrow(() -> new QueryException( "Unable to find process instance with the given id: " + cancelledEvent.getEntity().getId())), cancelledEvent.getTimestamp()); } ProcessCancelledEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }### Answer:
@Test public void testUpdateExistingProcessInstanceWhenCancelled() { ProcessInstanceEntity processInstanceEntity = mock(ProcessInstanceEntity.class); given(processInstanceRepository.findById("200")).willReturn(Optional.of(processInstanceEntity)); handler.handle(createProcessCancelledEvent("200" )); verify(processInstanceRepository).save(processInstanceEntity); verify(processInstanceEntity).setStatus(ProcessInstance.ProcessInstanceStatus.CANCELLED); verify(processInstanceEntity).setLastModified(any(Date.class)); }
@Test public void testThrowExceptionWhenProcessInstanceNotFound() { given(processInstanceRepository.findById("200")).willReturn(Optional.empty()); expectedException.expect(QueryException.class); expectedException.expectMessage("Unable to find process instance with the given id: "); handler.handle(createProcessCancelledEvent("200")); }