ToTimerCancelledConverter implements EventConverter<BPMNTimerCancelledEvent, ActivitiEvent> { @Override public Optional<BPMNTimerCancelledEvent> from(ActivitiEvent internalEvent) { BPMNTimerCancelledEventImpl event = null; if (bpmnTimerConverter.isTimerRelatedEvent(internalEvent)) { event = new BPMNTimerCancelledEventImpl(bpmnTimerConverter.convertToBPMNTimer((ActivitiEntityEvent) internalEvent)); event.setProcessInstanceId(internalEvent.getProcessInstanceId()); event.setProcessDefinitionId(internalEvent.getProcessDefinitionId()); } return Optional.ofNullable(event); } ToTimerCancelledConverter(BPMNTimerConverter bpmnTimerConverter); @Override Optional<BPMNTimerCancelledEvent> 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); BPMNTimerCancelledEvent timerCancelledEvent = toTimerCancelledConverter.from(internalEvent).orElse(null); assertThat(timerCancelledEvent).isNotNull(); assertThat(timerCancelledEvent.getProcessInstanceId()).isEqualTo("procInstId"); assertThat(timerCancelledEvent.getProcessDefinitionId()).isEqualTo("procDefId"); assertThat(timerCancelledEvent.getEntity()).isEqualTo(bpmnTimer); }
@Test public void shouldReturnEmptyOptionalWhenInternalEventIsNotRelatedToTimers() { given(bpmnTimerConverter.isTimerRelatedEvent(mock(ActivitiEntityEvent.class))).willReturn(false); Optional<BPMNTimerCancelledEvent> optional = toTimerCancelledConverter.from(mock(ActivitiEntityEvent.class)); assertThat(optional).isEmpty(); }