### Question:
StackImageUpdateActions { @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkPackageVersions() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { CheckResult checkResult = getStackImageUpdateService().checkPackageVersions(context.getStack(), payload.getImage()); if (checkResult.getStatus() == EventStatus.FAILED) { throw new OperationException(checkResult.getMessage()); } sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event(), context.getStack().getId(), payload.getImage())); } }; }  @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkImageVersion(); @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkPackageVersions(); @Bean(name = "UPDATE_IMAGE_STATE") AbstractStackImageUpdateAction<?> updateImage(); @Bean(name = "IMAGE_PREPARE_STATE") AbstractStackImageUpdateAction<?> prepareImageAction(); @Bean(name = "SET_IMAGE_STATE") AbstractStackImageUpdateAction<?> setImageAction(); @Bean(name = "STACK_IMAGE_UPDATE_FINISHED") AbstractStackImageUpdateAction<?> finishAction(); @Bean(name = "STACK_IMAGE_UPDATE_FAILED_STATE") AbstractStackFailureAction<StackImageUpdateState, StackImageUpdateEvent> handleImageUpdateFailure();  }### Answer:
@Test public void checkPackageVersions() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, statedImage); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE); when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.ok()); checkPackageVersionsAction.execute(stateContext); verify(stackImageUpdateService, times(1)).checkPackageVersions(any(Stack.class), any(StatedImage.class)); verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event()), any(Event.class)); }
@Test public void checkPackageVersionsNotOk() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), 1L, statedImage); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.CHECK_PACKAGE_VERSIONS_STATE); when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.failed("")); checkPackageVersionsAction.setFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT); checkPackageVersionsAction.execute(stateContext); verify(stackImageUpdateService, times(1)).checkPackageVersions(any(Stack.class), any(StatedImage.class)); verify(eventBus, times(0)).notify(eq(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event()), any(Event.class)); verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT.event()), any(Event.class)); }