@Test public void verifyNothingHappensTrashSelected_onAddCategorySelected() { AddCategorySelected eventMock = mock(AddCategorySelected.class); final AppCategory selectedParentCategoryMock = mock(AppCategory.class); when(selectedParentCategoryMock.getId()).thenReturn(mockTrashCategoryId); when(selectedParentCategoryMock.getName()).thenReturn("mock name"); when(selectedParentCategoryMock.getAppCount()).thenReturn(0); when(selectedParentCategoryMock.getCategories()).thenReturn(Collections.<AppCategory>emptyList()); when(eventMock.getAppCategories()).thenReturn(Lists.newArrayList(selectedParentCategoryMock)); uut.onAddCategorySelected(eventMock); verify(eventMock, times(2)).getAppCategories(); verifyZeroInteractions(adminAppServiceMock, appServiceMock, treeStoreMock, viewMock); }
@Override public void onAddCategorySelected(final AddCategorySelected event) { Preconditions.checkArgument(event.getAppCategories().size() == 1); final AppCategory selectedParentCategory = event.getAppCategories().iterator().next(); final boolean isTrashCategory = properties.getDefaultTrashAppCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isBetaCategory = properties.getDefaultBetaCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isPublicApps = selectedParentCategory.getName().contains("Public Apps"); final boolean hasNoChildCategories = selectedParentCategory.getCategories() != null && selectedParentCategory.getCategories().size() == 0; if(isTrashCategory || isBetaCategory) { announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } else if (!isPublicApps && hasNoChildCategories && selectedParentCategory.getAppCount() > 0){ announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } final String newCategoryName = event.getNewCategoryName(); view.mask(appearance.addCategoryLoadingMask()); adminAppService.addCategory(newCategoryName, selectedParentCategory, new AsyncCallback<AppCategory>() { @Override public void onFailure(Throwable caught) { view.unmask(); announcer.schedule(new ErrorAnnouncementConfig(appearance.addAppCategoryError(newCategoryName))); } @Override public void onSuccess(AppCategory result) { view.unmask(); treeStore.add(selectedParentCategory, result); } }); }
AdminAppsCategoriesPresenterImpl implements AdminCategoriesView.Presenter,
                                                         AppCategoriesView.AppCategoryHierarchyProvider { @Override public void onAddCategorySelected(final AddCategorySelected event) { Preconditions.checkArgument(event.getAppCategories().size() == 1); final AppCategory selectedParentCategory = event.getAppCategories().iterator().next(); final boolean isTrashCategory = properties.getDefaultTrashAppCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isBetaCategory = properties.getDefaultBetaCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isPublicApps = selectedParentCategory.getName().contains("Public Apps"); final boolean hasNoChildCategories = selectedParentCategory.getCategories() != null && selectedParentCategory.getCategories().size() == 0; if(isTrashCategory || isBetaCategory) { announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } else if (!isPublicApps && hasNoChildCategories && selectedParentCategory.getAppCount() > 0){ announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } final String newCategoryName = event.getNewCategoryName(); view.mask(appearance.addCategoryLoadingMask()); adminAppService.addCategory(newCategoryName, selectedParentCategory, new AsyncCallback<AppCategory>() { @Override public void onFailure(Throwable caught) { view.unmask(); announcer.schedule(new ErrorAnnouncementConfig(appearance.addAppCategoryError(newCategoryName))); } @Override public void onSuccess(AppCategory result) { view.unmask(); treeStore.add(selectedParentCategory, result); } }); } }
AdminAppsCategoriesPresenterImpl implements AdminCategoriesView.Presenter,
                                                         AppCategoriesView.AppCategoryHierarchyProvider { @Override public void onAddCategorySelected(final AddCategorySelected event) { Preconditions.checkArgument(event.getAppCategories().size() == 1); final AppCategory selectedParentCategory = event.getAppCategories().iterator().next(); final boolean isTrashCategory = properties.getDefaultTrashAppCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isBetaCategory = properties.getDefaultBetaCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isPublicApps = selectedParentCategory.getName().contains("Public Apps"); final boolean hasNoChildCategories = selectedParentCategory.getCategories() != null && selectedParentCategory.getCategories().size() == 0; if(isTrashCategory || isBetaCategory) { announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } else if (!isPublicApps && hasNoChildCategories && selectedParentCategory.getAppCount() > 0){ announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } final String newCategoryName = event.getNewCategoryName(); view.mask(appearance.addCategoryLoadingMask()); adminAppService.addCategory(newCategoryName, selectedParentCategory, new AsyncCallback<AppCategory>() { @Override public void onFailure(Throwable caught) { view.unmask(); announcer.schedule(new ErrorAnnouncementConfig(appearance.addAppCategoryError(newCategoryName))); } @Override public void onSuccess(AppCategory result) { view.unmask(); treeStore.add(selectedParentCategory, result); } }); } @Inject  AdminAppsCategoriesPresenterImpl(final AppCategoriesViewFactory viewFactory,
                                     final TreeStore<AppCategory> treeStore); }
AdminAppsCategoriesPresenterImpl implements AdminCategoriesView.Presenter,
                                                         AppCategoriesView.AppCategoryHierarchyProvider { @Override public void onAddCategorySelected(final AddCategorySelected event) { Preconditions.checkArgument(event.getAppCategories().size() == 1); final AppCategory selectedParentCategory = event.getAppCategories().iterator().next(); final boolean isTrashCategory = properties.getDefaultTrashAppCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isBetaCategory = properties.getDefaultBetaCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isPublicApps = selectedParentCategory.getName().contains("Public Apps"); final boolean hasNoChildCategories = selectedParentCategory.getCategories() != null && selectedParentCategory.getCategories().size() == 0; if(isTrashCategory || isBetaCategory) { announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } else if (!isPublicApps && hasNoChildCategories && selectedParentCategory.getAppCount() > 0){ announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } final String newCategoryName = event.getNewCategoryName(); view.mask(appearance.addCategoryLoadingMask()); adminAppService.addCategory(newCategoryName, selectedParentCategory, new AsyncCallback<AppCategory>() { @Override public void onFailure(Throwable caught) { view.unmask(); announcer.schedule(new ErrorAnnouncementConfig(appearance.addAppCategoryError(newCategoryName))); } @Override public void onSuccess(AppCategory result) { view.unmask(); treeStore.add(selectedParentCategory, result); } }); } @Inject  AdminAppsCategoriesPresenterImpl(final AppCategoriesViewFactory viewFactory,
                                     final TreeStore<AppCategory> treeStore); @Override List<String> getGroupHierarchy(AppCategory appCategory); @Override AppCategoriesView getView(); @Override void go(final HasId selectedAppCategory); @Override void onAddCategorySelected(final AddCategorySelected event); @Override void onAppSearchResultLoad(AppSearchResultLoadEvent event); @Override void onCategorizeAppSelected(final CategorizeAppSelected event); @Override void onDeleteCategorySelected(final DeleteCategorySelected event); @Override void onMoveCategorySelected(MoveCategorySelected event); @Override void onRemove(StoreRemoveEvent<App> event); @Override void onRenameCategorySelected(final RenameCategorySelected event); }
AdminAppsCategoriesPresenterImpl implements AdminCategoriesView.Presenter,
                                                         AppCategoriesView.AppCategoryHierarchyProvider { @Override public void onAddCategorySelected(final AddCategorySelected event) { Preconditions.checkArgument(event.getAppCategories().size() == 1); final AppCategory selectedParentCategory = event.getAppCategories().iterator().next(); final boolean isTrashCategory = properties.getDefaultTrashAppCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isBetaCategory = properties.getDefaultBetaCategoryId().equalsIgnoreCase(selectedParentCategory.getId()); final boolean isPublicApps = selectedParentCategory.getName().contains("Public Apps"); final boolean hasNoChildCategories = selectedParentCategory.getCategories() != null && selectedParentCategory.getCategories().size() == 0; if(isTrashCategory || isBetaCategory) { announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } else if (!isPublicApps && hasNoChildCategories && selectedParentCategory.getAppCount() > 0){ announcer.schedule(new ErrorAnnouncementConfig(appearance.addCategoryPermissionError())); return; } final String newCategoryName = event.getNewCategoryName(); view.mask(appearance.addCategoryLoadingMask()); adminAppService.addCategory(newCategoryName, selectedParentCategory, new AsyncCallback<AppCategory>() { @Override public void onFailure(Throwable caught) { view.unmask(); announcer.schedule(new ErrorAnnouncementConfig(appearance.addAppCategoryError(newCategoryName))); } @Override public void onSuccess(AppCategory result) { view.unmask(); treeStore.add(selectedParentCategory, result); } }); } @Inject  AdminAppsCategoriesPresenterImpl(final AppCategoriesViewFactory viewFactory,
                                     final TreeStore<AppCategory> treeStore); @Override List<String> getGroupHierarchy(AppCategory appCategory); @Override AppCategoriesView getView(); @Override void go(final HasId selectedAppCategory); @Override void onAddCategorySelected(final AddCategorySelected event); @Override void onAppSearchResultLoad(AppSearchResultLoadEvent event); @Override void onCategorizeAppSelected(final CategorizeAppSelected event); @Override void onDeleteCategorySelected(final DeleteCategorySelected event); @Override void onMoveCategorySelected(MoveCategorySelected event); @Override void onRemove(StoreRemoveEvent<App> event); @Override void onRenameCategorySelected(final RenameCategorySelected event);  }