### Question:
HierarchyExporter implements IHierarchyExporter { @Override public BackendFolders getBackendFolders(UserDataRequest udr) { final List<BackendFolders> allFoldersIterables = Lists.newArrayList(); for (PIMBackend backend: backends) { allFoldersIterables.add(backend.getBackendFolders(udr)); } return new BackendFolders() { @Override public Iterator<BackendFolder> iterator() { return Iterables.concat(allFoldersIterables).iterator(); } }; } @Inject @VisibleForTesting  HierarchyExporter(Backends backends); @Override BackendFolders getBackendFolders(UserDataRequest udr); @Override BackendId createFolder(UserDataRequest udr, FolderCreateRequest folderCreateRequest,
			Optional<BackendId> parentBackendId);  }### Answer:
@Test public void getBackendFoldersShouldBeEmptyWhenAllEmpty() { PIMBackend contactsBackend = createMock(PIMBackend.class); PIMBackend calendarBackend = createMock(PIMBackend.class); MailBackend mailBackend = createMock(MailBackend.class); expectGetPIMDataType(contactsBackend, calendarBackend, mailBackend); expect(contactsBackend.getBackendFolders(userDataRequest)) .andReturn(BackendFolders.EMPTY.instance()); expect(calendarBackend.getBackendFolders(userDataRequest)) .andReturn(BackendFolders.EMPTY.instance()); expect(mailBackend.getBackendFolders(userDataRequest)) .andReturn(BackendFolders.EMPTY.instance()); replay(mailBackend, calendarBackend, contactsBackend); Backends backends = buildBackends(contactsBackend, calendarBackend, mailBackend); BackendFolders backendFolders = new HierarchyExporter(backends).getBackendFolders(userDataRequest); verify(mailBackend, calendarBackend, contactsBackend); assertThat(backendFolders).isEmpty(); }
@Test public void getBackendFoldersShouldHaveAllElementsWhenEveryBackendHasFolder() { PIMBackend contactsBackend = createMock(PIMBackend.class); PIMBackend calendarBackend = createMock(PIMBackend.class); MailBackend mailBackend = createMock(MailBackend.class); BackendFolder addressBook = BackendFolder.builder() .displayName("addressBook") .backendId(new TestBackendId("12")) .parentId(Optional.<BackendId>absent()) .folderType(FolderType.DEFAULT_CONTACTS_FOLDER) .build(); BackendFolder calendar = BackendFolder.builder() .displayName("calendar") .backendId(new TestBackendId("15")) .parentId(Optional.<BackendId>absent()) .folderType(FolderType.DEFAULT_CALENDAR_FOLDER) .build(); BackendFolder mailbox = BackendFolder.builder() .displayName("mailbox") .backendId(new TestBackendId("18")) .parentId(Optional.<BackendId>absent()) .folderType(FolderType.DEFAULT_INBOX_FOLDER) .build(); expectGetPIMDataType(contactsBackend, calendarBackend, mailBackend); expect(contactsBackend.getBackendFolders(userDataRequest)).andReturn(folders(addressBook)); expect(calendarBackend.getBackendFolders(userDataRequest)).andReturn(folders(calendar)); expect(mailBackend.getBackendFolders(userDataRequest)).andReturn(folders(mailbox)); replay(mailBackend, calendarBackend, contactsBackend); Backends backends = buildBackends(contactsBackend, calendarBackend, mailBackend); BackendFolders backendFolders = new HierarchyExporter(backends).getBackendFolders(userDataRequest); verify(mailBackend, calendarBackend, contactsBackend); assertThat(backendFolders).containsOnly(addressBook, calendar, mailbox); }