@Test public void testDownloadFontStyles_downloadsCorrectStyles() throws Exception { TestSubscriber<File> testSubscriber = new TestSubscriber<>(); FontDownloader fontDownloader = new FontDownloader(new MockFontPackage(MOCK_FONT_PACK_NAME)); Style[] stylesToDownload = {Style.REGULAR, Style.BOLD, Style.ITALIC}; fontDownloader.downloadFontStyles(stylesToDownload).subscribe(testSubscriber); testSubscriber.assertNoErrors(); List<String> expectedFileNames = from(stylesToDownload) .map(Style::getLocalName) .toSortedList() .toBlocking() .single(); List<String> downloadedFileNames = from(testSubscriber.getOnNextEvents()) .map(File::getName) .toSortedList() .toBlocking() .single(); assertEquals(stylesToDownload.length, downloadedFileNames.size()); for (int i = 0; i < stylesToDownload.length; i++) { assertEquals(expectedFileNames.get(i), downloadedFileNames.get(i)); } }
public Observable<File> downloadFontStyles(Style... styles) { Timber.i("downloadFontStyles: %s for %s", Arrays.toString(styles), mFontPackage.getName()); return Observable.from(styles) .map(mFontPackage::getFont) .filter(font -> font != null) .collect(HashSet<Font>::new, HashSet::add) .flatMap(FontDownloader::downloadFonts); }
FontDownloader { public Observable<File> downloadFontStyles(Style... styles) { Timber.i("downloadFontStyles: %s for %s", Arrays.toString(styles), mFontPackage.getName()); return Observable.from(styles) .map(mFontPackage::getFont) .filter(font -> font != null) .collect(HashSet<Font>::new, HashSet::add) .flatMap(FontDownloader::downloadFonts); } }
FontDownloader { public Observable<File> downloadFontStyles(Style... styles) { Timber.i("downloadFontStyles: %s for %s", Arrays.toString(styles), mFontPackage.getName()); return Observable.from(styles) .map(mFontPackage::getFont) .filter(font -> font != null) .collect(HashSet<Font>::new, HashSet::add) .flatMap(FontDownloader::downloadFonts); } FontDownloader(FontPackage fontPackage); }
FontDownloader { public Observable<File> downloadFontStyles(Style... styles) { Timber.i("downloadFontStyles: %s for %s", Arrays.toString(styles), mFontPackage.getName()); return Observable.from(styles) .map(mFontPackage::getFont) .filter(font -> font != null) .collect(HashSet<Font>::new, HashSet::add) .flatMap(FontDownloader::downloadFonts); } FontDownloader(FontPackage fontPackage); Observable<File> downloadAllFonts(); Observable<File> downloadFontStyles(Style... styles); static Observable<File> downloadStyleFromPackages(List<FontPackage> packages, Style style); }
FontDownloader { public Observable<File> downloadFontStyles(Style... styles) { Timber.i("downloadFontStyles: %s for %s", Arrays.toString(styles), mFontPackage.getName()); return Observable.from(styles) .map(mFontPackage::getFont) .filter(font -> font != null) .collect(HashSet<Font>::new, HashSet::add) .flatMap(FontDownloader::downloadFonts); } FontDownloader(FontPackage fontPackage); Observable<File> downloadAllFonts(); Observable<File> downloadFontStyles(Style... styles); static Observable<File> downloadStyleFromPackages(List<FontPackage> packages, Style style);  }