UserCreationWorkflow extends BaseUserEditorWorkflow { @Override protected void afterSave(String id) { confirmBox.show(UsersManagementWidgetsConstants.INSTANCE.confirmAction(), UsersManagementWidgetsConstants.INSTANCE.doSetPasswordNow(), new Command() { @Override public void execute() { showPasswordPopup(new ChangePassword.ChangePasswordCallback() { @Override public void onPasswordUpdated() { doAfterSave(user.getIdentifier()); } @Override public void onError(Throwable throwable) { showError(throwable); onCancel(); } }); } }, new Command() { @Override public void execute() { doAfterSave(user.getIdentifier()); } }); } @Inject  UserCreationWorkflow(final ClientUserSystemManager userSystemManager,
                                final Event<OnErrorEvent> errorEvent,
                                final Event<NotificationEvent> workbenchNotification,
                                final Event<DeleteUserEvent> deleteUserEvent,
                                final Event<SaveUserEvent> saveUserEvent,
                                final Event<CreateUserEvent> createUserEvent,
                                final ConfirmBox confirmBox,
                                final CreateEntity createEntity,
                                final UserEditor userEditor,
                                final UserEditorDriver userEditorDriver,
                                final ChangePassword changePassword,
                                final LoadingBox loadingBox,
                                final EntityWorkflowView view); @PostConstruct void init(); void create(); @Override void clear();  }
@Test public void testAfterSaveSetPassword() { tested.user = user; doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { final Command callback = (Command) invocationOnMock.getArguments()[2]; callback.execute(); return null; } }).when(confirmBox).show(anyString(), anyString(), any(Command.class), any(Command.class)); final String id = "user1"; tested.afterSave(id); verify(confirmBox, times(1)).show(anyString(), anyString(), any(Command.class), any(Command.class)); verify(changePassword, times(1)).show(anyString(), any(ChangePassword.ChangePasswordCallback.class)); }
@Test public void testAfterSaveSkipSetPassword() { tested.user = user; doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { final Command callback = (Command) invocationOnMock.getArguments()[3]; callback.execute(); return null; } }).when(confirmBox).show(anyString(), anyString(), any(Command.class), any(Command.class)); final String id = "user1"; tested.afterSave(id); verify(confirmBox, times(1)).show(anyString(), anyString(), any(Command.class), any(Command.class)); verify(changePassword, times(0)).show(anyString(), any(ChangePassword.ChangePasswordCallback.class)); verify(workbenchNotification, times(1)).fire(any(NotificationEvent.class)); verify(createUserEvent, times(1)).fire(any(CreateUserEvent.class)); verify(createEntity, times(1)).show(anyString(), anyString()); }