DiskResourceServiceFacadeImpl extends TreeStore<Folder> implements
                                                                    DiskResourceServiceFacade { @Override public void refreshFolder(Folder parent, final AsyncCallback<List<Folder>> callback) { final Folder folder = findModel(parent); if (folder == null) { List<Folder> result = Lists.newArrayList(); callback.onSuccess(result); eventBus.fireEvent(new FolderRefreshedEvent(parent)); return; } removeChildren(folder); folder.setFolders(null); getSubFolders(folder, new AsyncCallback<List<Folder>>() { @Override public void onSuccess(List<Folder> result) { eventBus.fireEvent(new FolderRefreshedEvent(folder)); callback.onSuccess(result); } @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } }); } @Inject  DiskResourceServiceFacadeImpl(final DiscEnvApiService deServiceFacade,
                                         final DEProperties deProperties,
                                         final DEClientConstants constants,
                                         final DiskResourceAutoBeanFactory factory,
                                         final UserInfo userInfo,
                                         final EventBus eventBus); @Override DiskResource combineDiskResources(DiskResource from, DiskResource into); @Override Folder convertToFolder(DiskResource diskResource); @Override final void getRootFolders(final AsyncCallback<RootFolders> callback); @Override void getFolderContents(final Folder folder,
                                  final List<InfoType> infoTypeFilterList,
                                  final TYPE entityType,
                                  final FilterPagingLoadConfigBean loadConfig,
                                  final AsyncCallback<Folder> callback); @Override void getSubFolders(final Folder parent, final AsyncCallback<List<Folder>> callback); @Override void createFolder(final Folder parentFolder,
                             final String newFolderName,
                             AsyncCallback<Folder> callback); @Override void createNcbiSraFolderStructure(final Folder parentFolder,
                                             final String[] foldersToCreate,
                                             AsyncCallback<String> callback); @Override final void diskResourcesExist(final HasPaths diskResourcePaths,
                                         final AsyncCallback<DiskResourceExistMap> callback); @Override void moveDiskResources(final Folder sourceFolder,
                                  final Folder destFolder,
                                  final List<DiskResource> diskResources,
                                  final AsyncCallback<DiskResourceMove> callback); @Override void renameDiskResource(final DiskResource src,
                                   String destName,
                                   AsyncCallback<DiskResource> callback); @Override void refreshFolder(Folder parent, final AsyncCallback<List<Folder>> callback); @Override void search(String term, int size, String type, AsyncCallback<String> callback); @Override void importFromUrl(final String url, final DiskResource dest, AsyncCallback<String> callback); @Override String getEncodedSimpleDownloadURL(String path); @Override void deleteDiskResources(final List<T> diskResources,
                                                             final AsyncCallback<HasPaths> callback); @Override final void deleteDiskResources(final HasPaths diskResources,
                                          final AsyncCallback<HasPaths> callback); @Override void getDiskResourceMetaData(DiskResource resource, AsyncCallback<DiskResourceMetadataList> callback); @Override void setDiskResourceMetaData(DiskResource resource,
                                        DiskResourceMetadataList mdList,
                                        AsyncCallback<String> callback); @Override void shareDiskResource(JSONObject body, AsyncCallback<String> callback); @Override void unshareDiskResource(JSONObject body, AsyncCallback<String> callback); @Override void getPermissions(JSONObject body, AsyncCallback<String> callback); @Override final void getStat(final FastMap<TYPE> paths,
                              final AsyncCallback<FastMap<DiskResource>> callback); @Override void restoreDiskResource(HasPaths request, AsyncCallback<String> callback); @Override void emptyTrash(String user, AsyncCallback<String> callback); @Override void createDataLinks(List<String> ticketIdList, AsyncCallback<List<DataLink>> callback); @Override void listDataLinks(List<String> diskResourceIds, AsyncCallback<String> callback); @Override void deleteDataLinks(List<String> dataLinkIds, AsyncCallback<String> callback); @Override void getInfoTypes(AsyncCallback<List<InfoType>> callback); @Override void setFileType(String filePath, String type, AsyncCallback<String> callback); @Override DiskResourceAutoBeanFactory getDiskResourceFactory(); @Override void moveContents(final Folder sourceFolder,
                             final Folder destFolder,
                             final AsyncCallback<DiskResourceMove> callback); @Override void deleteContents(String selectedFolderId, AsyncCallback<HasPaths> callback); @Override void restoreAll(AsyncCallback<String> callback); @Override void getMetadataTemplateListing(AsyncCallback<List<MetadataTemplateInfo>> callback); @Override void getMetadataTemplate(String templateId, AsyncCallback<MetadataTemplate> callback); @Override void shareWithAnonymous(HasPaths diskResourcePaths, AsyncCallback<String> callback); @Override void copyMetadata(String srcUUID,
                              Splittable paths,
                              AsyncCallback<String> callback); @Override void saveMetadata(String srcUUID,
                             String path,
                             boolean recursive,
                             AsyncCallback<String> callback); @Override void setBulkMetadataFromFile(String metadataFilePath,
                                        String destFolder,
                                        AsyncCallback<String> callback); @Override void requestIdentifier(String uuid, String path, AsyncCallback<String> callback); @Override String downloadTemplate(String templateid);  }
@Test public void refreshFolder_onSuccess() { final Folder folderMock = mock(Folder.class); DiskResourceServiceFacadeImpl spy = spy(new DiskResourceServiceFacadeImpl(deServiceFacadeMock, dePropertiesMock, deConstantsMock, drAutoBeanFactoryMock, userInfoMock, eventBusMock) { public Folder findModel(Folder model) { return folderMock; } public void removeChildren(Folder parent){ } public void getSubFolders(Folder parent, AsyncCallback<List<Folder>> callback){ callback.onSuccess(Lists.<Folder>newArrayList()); } }); spy.eventBus = eventBusMock; when(folderMock.getFolders()).thenReturn(null); spy.refreshFolder(folderMock, folderListCallbackMock); ArgumentCaptor<FolderRefreshedEvent> folderRefreshedEventCaptor = ArgumentCaptor.forClass(FolderRefreshedEvent.class); verify(spy).removeChildren(eq(folderMock)); verify(folderMock).setFolders(Matchers.<List<Folder>>eq(null)); verify(folderListCallbackMock).onSuccess(Matchers.<List<Folder>>any()); verify(eventBusMock).fireEvent(folderRefreshedEventCaptor.capture()); assertEquals(folderMock, folderRefreshedEventCaptor.getValue().getFolder()); }
@Test public void refreshFolder_onFailure() { final Folder folderMock = mock(Folder.class); final Throwable throwableMock = mock(Throwable.class); DiskResourceServiceFacadeImpl spy = spy(new DiskResourceServiceFacadeImpl(deServiceFacadeMock, dePropertiesMock, deConstantsMock, drAutoBeanFactoryMock, userInfoMock, eventBusMock) { public Folder findModel(Folder model) { return folderMock; } public void removeChildren(Folder parent){ } public void getSubFolders(Folder parent, AsyncCallback<List<Folder>> callback){ callback.onFailure(throwableMock); } }); spy.eventBus = eventBusMock; when(folderMock.getFolders()).thenReturn(null); spy.refreshFolder(folderMock, folderListCallbackMock); verify(spy).removeChildren(eq(folderMock)); verify(folderMock).setFolders(Matchers.<List<Folder>>eq(null)); verify(folderListCallbackMock).onFailure(eq(throwableMock)); verifyZeroInteractions(eventBusMock); }