ToTaskCompletedConverter implements EventConverter<TaskCompletedEvent, ActivitiEntityEvent> { @Override public Optional<TaskCompletedEvent> from(ActivitiEntityEvent internalEvent) { String completedBy = securityManager.getAuthenticatedUserId(); return Optional.of(new TaskCompletedImpl(converter.fromWithCompletedBy((Task) internalEvent.getEntity(), org.activiti.api.task.model.Task.TaskStatus.COMPLETED, completedBy))); } ToTaskCompletedConverter(APITaskConverter converter, SecurityManager securityManager); @Override Optional<TaskCompletedEvent> from(ActivitiEntityEvent internalEvent);  }
@Test public void fromShouldReturnAPIEventContainingConvertedTask() { Task internalTask = mock(Task.class); org.activiti.api.task.model.Task apiTask = mock(org.activiti.api.task.model.Task.class); String loginUser="hruser"; given(securityManager.getAuthenticatedUserId()).willReturn(loginUser); given(taskConverter.fromWithCompletedBy(internalTask, org.activiti.api.task.model.Task.TaskStatus.COMPLETED, loginUser)).willReturn(apiTask); ActivitiEntityEvent internalEvent = mock(ActivitiEntityEvent.class); given(internalEvent.getEntity()).willReturn(internalTask); TaskCompletedEvent taskCompletedEvent = toTaskCompletedConverter.from(internalEvent).orElse(null); assertThat(taskCompletedEvent).isNotNull(); assertThat(taskCompletedEvent.getEntity()).isEqualTo(apiTask); }