VariableCreatedListenerDelegate implements ActivitiEventListener { @Override public void onEvent(ActivitiEvent event) { if (event instanceof ActivitiVariableEvent) { ActivitiVariableEvent internalEvent = (ActivitiVariableEvent) event; if (variableEventFilter.shouldEmmitEvent(internalEvent)) { converter.from(internalEvent) .ifPresent(convertedEvent -> { if (listeners != null) { for (VariableEventListener<VariableCreatedEvent> listener : listeners) { listener.onEvent(convertedEvent); } } }); } } } VariableCreatedListenerDelegate(
        List<VariableEventListener<VariableCreatedEvent>> listeners,
        ToVariableCreatedConverter converter,
        VariableEventFilter variableEventFilter); @Override void onEvent(ActivitiEvent event); @Override boolean isFailOnException();  }
@Test public void onEvent_should_callListenersWhenItsVariableEventAndItsNotFiltered() { ActivitiVariableEventImpl internalEvent = new ActivitiVariableEventImpl( ActivitiEventType.VARIABLE_CREATED); given(variableEventFilter.shouldEmmitEvent(internalEvent)).willReturn(true); VariableCreatedEvent apiEvent = mock(VariableCreatedEvent.class); given(converter.from(internalEvent)).willReturn(Optional.of( apiEvent)); variableCreatedListenerDelegate.onEvent(internalEvent); verify(firstListener).onEvent(apiEvent); verify(secondListener).onEvent(apiEvent); }
@Test public void onEvent_shouldNot_callListenersWhenItsNotAVariableEvent() { ActivitiEvent internalEvent = mock(ActivitiEvent.class); variableCreatedListenerDelegate.onEvent(internalEvent); verifyNoInteractions(firstListener); verifyNoInteractions(secondListener); }
@Test public void onEvent_shouldNot_callListenersWhenItsFiltered() { ActivitiVariableEventImpl internalEvent = new ActivitiVariableEventImpl( ActivitiEventType.VARIABLE_CREATED); given(variableEventFilter.shouldEmmitEvent(internalEvent)).willReturn(false); VariableCreatedEvent apiEvent = mock(VariableCreatedEvent.class); given(converter.from(internalEvent)).willReturn(Optional.of( apiEvent)); variableCreatedListenerDelegate.onEvent(internalEvent); verifyNoInteractions(firstListener); verifyNoInteractions(secondListener); }