@Test public void removeTest() { final Contributor contributor1 = new Contributor("admin", ContributorType.OWNER); final Contributor contributor2 = new Contributor("other", ContributorType.CONTRIBUTOR); final ContributorsListService contributorsListService = mock(ContributorsListService.class); doAnswer(invocationOnMock -> { final List<Contributor> contributors = new ArrayList<>(); contributors.add(contributor1); contributors.add(contributor2); invocationOnMock.getArgumentAt(0, Consumer.class).accept(contributors); return null; }).when(contributorsListService).getContributors(any()); final ContributorsListPresenter parentPresenter = mock(ContributorsListPresenter.class); doReturn(promises.resolve(true)).when(parentPresenter).canEditContributors(any()); presenter.setup(contributor2, parentPresenter, contributorsListService); presenter.remove(); verify(view).showBusyIndicator(anyString()); verify(contributorsListService).saveContributors(any(), any(), any()); }
public void remove() { canRemoveContributor().then(canRemoveContributor -> { if (canRemoveContributor) { contributorsListService.getContributors(contributors -> { if (isLastOwner(persistedContributor, contributors)) { notificationEvent.fire(new NotificationEvent(view.getSingleOwnerIsMandatoryMessage(), NotificationEvent.NotificationType.ERROR)); } else { contributors.remove(persistedContributor); view.showBusyIndicator(view.getSavingMessage()); contributorsListService.saveContributors(contributors, () -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getRemoveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); view.removeContributor(); parentPresenter.refresh(); }, new HasBusyIndicatorDefaultErrorCallback(view)); } }); } return promises.resolve(); }); }
ContributorsListItemPresenter { public void remove() { canRemoveContributor().then(canRemoveContributor -> { if (canRemoveContributor) { contributorsListService.getContributors(contributors -> { if (isLastOwner(persistedContributor, contributors)) { notificationEvent.fire(new NotificationEvent(view.getSingleOwnerIsMandatoryMessage(), NotificationEvent.NotificationType.ERROR)); } else { contributors.remove(persistedContributor); view.showBusyIndicator(view.getSavingMessage()); contributorsListService.saveContributors(contributors, () -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getRemoveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); view.removeContributor(); parentPresenter.refresh(); }, new HasBusyIndicatorDefaultErrorCallback(view)); } }); } return promises.resolve(); }); } }
ContributorsListItemPresenter { public void remove() { canRemoveContributor().then(canRemoveContributor -> { if (canRemoveContributor) { contributorsListService.getContributors(contributors -> { if (isLastOwner(persistedContributor, contributors)) { notificationEvent.fire(new NotificationEvent(view.getSingleOwnerIsMandatoryMessage(), NotificationEvent.NotificationType.ERROR)); } else { contributors.remove(persistedContributor); view.showBusyIndicator(view.getSavingMessage()); contributorsListService.saveContributors(contributors, () -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getRemoveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); view.removeContributor(); parentPresenter.refresh(); }, new HasBusyIndicatorDefaultErrorCallback(view)); } }); } return promises.resolve(); }); } @Inject  ContributorsListItemPresenter(final View view,
                                         final LibraryPlaces libraryPlaces,
                                         final Event<NotificationEvent> notificationEvent,
                                         final Promises promises); }
ContributorsListItemPresenter { public void remove() { canRemoveContributor().then(canRemoveContributor -> { if (canRemoveContributor) { contributorsListService.getContributors(contributors -> { if (isLastOwner(persistedContributor, contributors)) { notificationEvent.fire(new NotificationEvent(view.getSingleOwnerIsMandatoryMessage(), NotificationEvent.NotificationType.ERROR)); } else { contributors.remove(persistedContributor); view.showBusyIndicator(view.getSavingMessage()); contributorsListService.saveContributors(contributors, () -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getRemoveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); view.removeContributor(); parentPresenter.refresh(); }, new HasBusyIndicatorDefaultErrorCallback(view)); } }); } return promises.resolve(); }); } @Inject  ContributorsListItemPresenter(final View view,
                                         final LibraryPlaces libraryPlaces,
                                         final Event<NotificationEvent> notificationEvent,
                                         final Promises promises); void setupNew(final ContributorsListPresenter parentPresenter,
                         final ContributorsListService contributorsListService); void setup(final Contributor contributor,
                      final ContributorsListPresenter parentPresenter,
                      final ContributorsListService contributorsListService); void edit(); void save(); void remove(); void cancel(); void showActions(); void hideActions(); Contributor getContributor(); List<String> getUserNames(); Promise<Boolean> canRemoveContributor(); Promise<Boolean> canEditContributors(); View getView(); }
ContributorsListItemPresenter { public void remove() { canRemoveContributor().then(canRemoveContributor -> { if (canRemoveContributor) { contributorsListService.getContributors(contributors -> { if (isLastOwner(persistedContributor, contributors)) { notificationEvent.fire(new NotificationEvent(view.getSingleOwnerIsMandatoryMessage(), NotificationEvent.NotificationType.ERROR)); } else { contributors.remove(persistedContributor); view.showBusyIndicator(view.getSavingMessage()); contributorsListService.saveContributors(contributors, () -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getRemoveSuccessMessage(), NotificationEvent.NotificationType.SUCCESS)); view.removeContributor(); parentPresenter.refresh(); }, new HasBusyIndicatorDefaultErrorCallback(view)); } }); } return promises.resolve(); }); } @Inject  ContributorsListItemPresenter(final View view,
                                         final LibraryPlaces libraryPlaces,
                                         final Event<NotificationEvent> notificationEvent,
                                         final Promises promises); void setupNew(final ContributorsListPresenter parentPresenter,
                         final ContributorsListService contributorsListService); void setup(final Contributor contributor,
                      final ContributorsListPresenter parentPresenter,
                      final ContributorsListService contributorsListService); void edit(); void save(); void remove(); void cancel(); void showActions(); void hideActions(); Contributor getContributor(); List<String> getUserNames(); Promise<Boolean> canRemoveContributor(); Promise<Boolean> canEditContributors(); View getView();  }