GroupCreationWorkflow implements IsWidget { protected void createGroup(final String name) { final Group _group = userSystemManager.createGroup(name); createEntity.clear(); loadingBox.show(); userSystemManager.groups(new RemoteCallback<Group>() { @Override public void callback(Group group) { GroupCreationWorkflow.this.group = group; final boolean isEmptyUsersAllowed = userSystemManager.getGroupManagerSettings().allowEmpty(); loadingBox.hide(); if (!isEmptyUsersAllowed) { showUsersAssignment(name); } else { confirmBox.show(UsersManagementWidgetsConstants.INSTANCE.confirmAction(), UsersManagementWidgetsConstants.INSTANCE.assignUsersToGroupName() + " " + name, new Command() { @Override public void execute() { showUsersAssignment(name); } }, new Command() { @Override public void execute() { fireGroupCreated(name); create(); } }); } } }, errorCallback).create(_group); } @Inject  GroupCreationWorkflow(final ClientUserSystemManager userSystemManager,
                                 final Caller<AuthorizationService> authorizationService,
                                 final PermissionManager permissionManager,
                                 final Event<OnErrorEvent> errorEvent,
                                 final ConfirmBox confirmBox,
                                 final LoadingBox loadingBox,
                                 final Event<NotificationEvent> workbenchNotification,
                                 final CreateEntity createEntity,
                                 final GroupUsersAssignment groupUsersAssignment,
                                 final Event<CreateGroupEvent> onCreateGroupEvent,
                                 final EntityWorkflowView view); @PostConstruct void init(); void create(); void clear(); @Override Widget asWidget();  }
@Test public void testCreateGroup() { final CreateGroupEvent onCreateEvent = mock(CreateGroupEvent.class); when(onCreateEvent.getName()).thenReturn("group1"); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Command noCommand = (Command) invocationOnMock.getArguments()[3]; noCommand.execute(); return null; } }).when(confirmBox).show(anyString(), anyString(), any(Command.class), any(Command.class)); tested.createGroup("group1"); tested.onCreateGroupEvent(onCreateEvent); verify(createEntity, times(2)).clear(); verify(loadingBox, times(1)).show(); verify(loadingBox, times(1)).hide(); verify(confirmBox, times(1)).show(anyString(), anyString(), any(Command.class), any(Command.class)); verify(workbenchNotification, times(1)).fire(any(NotificationEvent.class)); verify(onCreateGroupEvent, times(1)).fire(any(CreateGroupEvent.class)); }