BaseUserEditorWorkflow implements IsWidget { protected void doSave() { assert user != null; final boolean isValid = userEditorDriver.flush(); this.user = userEditorDriver.getValue(); if (isValid) { final RemoteCallback<User> assignGroupsCallback = user1 -> doAssignGroups(() -> doAssignRoles(() -> { hideLoadingBox(); BaseUserEditorWorkflow.this.isDirty = false; final String id = user1.getIdentifier(); afterSave(id); })); showLoadingBox(); doSaveRemoteServiceCall(assignGroupsCallback); } else { throw new RuntimeException("User must be valid before updating it."); } } BaseUserEditorWorkflow(final ClientUserSystemManager userSystemManager,
                                  final Event<OnErrorEvent> errorEvent,
                                  final Event<NotificationEvent> workbenchNotification,
                                  final Event<DeleteUserEvent> deleteUserEvent,
                                  final Event<SaveUserEvent> saveUserEvent,
                                  final ConfirmBox confirmBox,
                                  final UserEditor userEditor,
                                  final UserEditorDriver userEditorDriver,
                                  final ChangePassword changePassword,
                                  final LoadingBox loadingBox,
                                  final EntityWorkflowView view); @Override Widget asWidget(); void clear(); UserEditor getUserEditor(); boolean isDirty(); public EntityWorkflowView view; }
@Test public void testDoSaveWithoutGroupAssignment() { when(userEditorDriver.flush()).thenReturn(true); when(userEditorDriver.getValue()).thenReturn(user); when(userEditor.getValue()).thenReturn(user); when(userEditor.canAssignGroups()).thenReturn(false); when(userEditor.canAssignRoles()).thenReturn(false); tested.user = user; tested.doSave(); verify(userManagerService, times(1)).update(any(User.class)); verify(loadingBox, times(2)).show(); verify(loadingBox, times(2)).hide(); }