ToTimerFiredConverter implements EventConverter<BPMNTimerFiredEvent, ActivitiEvent> { @Override public Optional<BPMNTimerFiredEvent> from(ActivitiEvent internalEvent) { BPMNTimerFiredEventImpl event = null; if (bpmnTimerConverter.isTimerRelatedEvent(internalEvent)) { event = new BPMNTimerFiredEventImpl(bpmnTimerConverter.convertToBPMNTimer((ActivitiEntityEvent) internalEvent)); event.setProcessInstanceId(internalEvent.getProcessInstanceId()); event.setProcessDefinitionId(internalEvent.getProcessDefinitionId()); } return Optional.ofNullable(event); } ToTimerFiredConverter(BPMNTimerConverter bpmnTimerConverter); @Override Optional<BPMNTimerFiredEvent> from(ActivitiEvent internalEvent);  }
@Test public void shouldReturnConvertedEventsWhenInternalEvenIsRelatedToTimers() { ActivitiEntityEvent internalEvent = mock(ActivitiEntityEvent.class); given(internalEvent.getProcessDefinitionId()).willReturn("procDefId"); given(internalEvent.getProcessInstanceId()).willReturn("procInstId"); BPMNTimerImpl bpmnTimer = new BPMNTimerImpl("myTimer"); given(bpmnTimerConverter.convertToBPMNTimer(internalEvent)).willReturn(bpmnTimer); given(bpmnTimerConverter.isTimerRelatedEvent(internalEvent)).willReturn(true); BPMNTimerFiredEvent timerEvent = toTimerConverter.from(internalEvent).orElse(null); assertThat(timerEvent).isNotNull(); assertThat(timerEvent.getProcessInstanceId()).isEqualTo("procInstId"); assertThat(timerEvent.getProcessDefinitionId()).isEqualTo("procDefId"); assertThat(timerEvent.getEntity()).isEqualTo(bpmnTimer); }
@Test public void shouldReturnEmptyOptionalWhenInternalEventIsNotRelatedToTimers() { given(bpmnTimerConverter.isTimerRelatedEvent(mock(ActivitiEntityEvent.class))).willReturn(false); Optional<BPMNTimerFiredEvent> optional = toTimerConverter.from(mock(ActivitiEntityEvent.class)); assertThat(optional).isEmpty(); }