ToMessageSentConverter implements EventConverter<BPMNMessageSentEvent, ActivitiMessageEvent> { @Override public Optional<BPMNMessageSentEvent> from(ActivitiMessageEvent internalEvent) { BPMNMessageSentEventImpl event = new BPMNMessageSentEventImpl(bpmnMessageConverter.convertToBPMNMessage(internalEvent)); event.setProcessInstanceId(internalEvent.getProcessInstanceId()); event.setProcessDefinitionId(internalEvent.getProcessDefinitionId()); return Optional.of(event); } ToMessageSentConverter(BPMNMessageConverter bpmnMessageConverter); @Override Optional<BPMNMessageSentEvent> from(ActivitiMessageEvent internalEvent);  }
@Test public void fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId() { ActivitiMessageEvent internalEvent = mock(ActivitiMessageEvent.class); given(internalEvent.getProcessDefinitionId()).willReturn("procDefId"); given(internalEvent.getProcessInstanceId()).willReturn("procInstId"); BPMNMessageImpl bpmnMessage = new BPMNMessageImpl("myMessage"); given(bpmnMessageConverter.convertToBPMNMessage(internalEvent)).willReturn(bpmnMessage); BPMNMessageSentEvent messageEvent = toMessageConverter.from(internalEvent).orElse(null); assertThat(messageEvent).isNotNull(); assertThat(messageEvent.getProcessInstanceId()).isEqualTo("procInstId"); assertThat(messageEvent.getProcessDefinitionId()).isEqualTo("procDefId"); assertThat(messageEvent.getEntity()).isEqualTo(bpmnMessage); }