AdminAppsGridPresenterImpl implements AdminAppsGridView.Presenter,
                                                   AppInfoSelectedEvent.AppInfoSelectedEventHandler,
                                                   SaveAppSelected.SaveAppSelectedHandler { @Override public void onRestoreAppSelected(final RestoreAppSelected event) { Preconditions.checkArgument(event.getApps().size() == 1); final App selectedApp = event.getApps().iterator().next(); Preconditions.checkArgument(selectedApp.isDeleted()); view.mask(appearance.restoreAppLoadingMask()); adminAppService.restoreApp(selectedApp, new AsyncCallback<App>() { @Override public void onFailure(Throwable caught) { view.unmask(); JSONObject obj = JSONParser.parseStrict(caught.getMessage()).isObject(); String reason = jsonUtil.trim(obj.get("reason").toString()); if (reason.contains("orphaned")) { announcer.schedule(new ErrorAnnouncementConfig(appearance.restoreAppFailureMsg(selectedApp.getName()))); } else { announcer.schedule(new ErrorAnnouncementConfig(reason)); } } @Override public void onSuccess(App result) { view.unmask(); List<String> categoryNames = Lists.newArrayList(); for(AppCategory category : result.getGroups()){ categoryNames.add(category.getName()); } String joinedCatNames = Joiner.on(",").join(categoryNames); announcer.schedule(new SuccessAnnouncementConfig(appearance.restoreAppSuccessMsgTitle() + "\n" + appearance.restoreAppSuccessMsg(result.getName(), joinedCatNames))); } }); } @Inject  AdminAppsGridPresenterImpl(final AdminAppsGridViewFactory viewFactory,
                               final ListStore<App> listStore); @Override HandlerRegistration addStoreRemoveHandler(StoreRemoveEvent.StoreRemoveHandler<App> handler); @Override void fireEvent(GwtEvent<?> event); @Override AdminAppsGridView getView(); @Override App getAppFromElement(Element eventTarget); @Override List<App> getSelectedApps(); @Override void onAppCategorySelectionChanged(AppCategorySelectionChangedEvent event); @Override void onAppInfoSelected(final AppInfoSelectedEvent event); @Override void onAppSearchResultLoad(AppSearchResultLoadEvent event); @Override void onDeleteAppsSelected(final DeleteAppsSelected event); @Override void onRestoreAppSelected(final RestoreAppSelected event); @Override void onSaveAppSelected(SaveAppSelected event); void updateBetaStatus(final App app);  }
@Test public void verifyServiceCalled_onRestoreAppSelected() { verify(viewMock).addAppInfoSelectedEventHandler(Matchers.<AppInfoSelectedEvent.AppInfoSelectedEventHandler>any()); RestoreAppSelected eventMock = mock(RestoreAppSelected.class); final App appMock = mock(App.class); when(appMock.isDeleted()).thenReturn(true); when(eventMock.getApps()).thenReturn(Lists.newArrayList(appMock)); uut.onRestoreAppSelected(eventMock); verify(viewMock).mask(anyString()); verify(adminAppServiceMock).restoreApp(eq(appMock), appCallbackCaptor.capture()); App resultMock = mock(App.class); appCallbackCaptor.getValue().onSuccess(resultMock); verify(viewMock).unmask(); verifyNoMoreInteractions(viewMock); }