### Question:
ProcessUpdatedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessUpdatedEvent updatedEvent = (CloudProcessUpdatedEvent) event; ProcessInstance eventProcessInstance = updatedEvent.getEntity(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(eventProcessInstance.getId()) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + eventProcessInstance.getId()) ); processInstanceEntity.setBusinessKey(eventProcessInstance.getBusinessKey()); processInstanceEntity.setName(eventProcessInstance.getName()); processInstanceEntity.setLastModified(new Date(updatedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } ProcessUpdatedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }### Answer:
@Test public void handleShouldUpdateCurrentProcessInstance() { CloudProcessUpdatedEvent event = buildProcessUpdatedEvent(); ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class); given(processInstanceRepository.findById(event.getEntity().getId())).willReturn(Optional.of(currentProcessInstanceEntity)); handler.handle(event); verify(processInstanceRepository).save(currentProcessInstanceEntity); verify(currentProcessInstanceEntity).setBusinessKey(event.getEntity().getBusinessKey()); verify(currentProcessInstanceEntity).setName(event.getEntity().getName()); verify(currentProcessInstanceEntity).setLastModified(any(Date.class)); verifyNoMoreInteractions(currentProcessInstanceEntity); }
@Test public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() { CloudProcessUpdatedEvent event = buildProcessUpdatedEvent(); String id = event.getEntity().getId(); given(processInstanceRepository.findById(id)).willReturn(Optional.empty()); expectedException.expect(QueryException.class); expectedException.expectMessage("Unable to find process instance with the given id: "); handler.handle(event); }