### Question:
ProcessCompletedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } } ProcessCompletedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }### Answer:
@Test public void handleShouldUpdateCurrentProcessInstanceStateToCompleted() { CloudProcessCompletedEvent event = createProcessCompletedEvent(); ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class); given(processInstanceRepository.findById(event.getEntity().getId())).willReturn(Optional.of(currentProcessInstanceEntity)); handler.handle(event); verify(processInstanceRepository).save(currentProcessInstanceEntity); verify(currentProcessInstanceEntity).setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); verify(currentProcessInstanceEntity).setLastModified(any(Date.class)); }
@Test public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() { CloudProcessCompletedEvent event = createProcessCompletedEvent(); given(processInstanceRepository.findById("200")).willReturn(Optional.empty()); expectedException.expect(QueryException.class); expectedException.expectMessage("Unable to find process instance with the given id: "); handler.handle(event); }