LargeFilesSuggester implements BundleEntrySuggester, ProjectTreeSuggester { @Override public ImmutableList<Suggestion> processBundleZipEntry(BundleContext context, FileData fileData) { return processFileEntry(context, fileData, isBundleAssetFile(fileData)); } LargeFilesSuggester(); @Override ImmutableList<Suggestion> processBundleZipEntry(BundleContext context, FileData fileData); @Override ImmutableList<Suggestion> processProjectEntry(GradleContext context, FileData fileData);  }
@Test public void smallFile_containsNoSuggestions() { fileData = FakeFileData.builder(BIN_FILE).setSize(SMALL_FILE_SIZE).build(); assertThat( new LargeFilesSuggester() .processBundleZipEntry(BundleContext.create(1, false), fileData)) .isEmpty(); }
@Test public void ignoresNonAssetFiles() { fileData = FakeFileData.builder(DEX_FILE).setSize(LARGE_FILE_SIZE).build(); assertThat( new LargeFilesSuggester() .processBundleZipEntry(BundleContext.create(1, false), fileData)) .isEmpty(); }
@Test public void ignoresProjectNonAssetFiles() { fileData = FakeFileData.builder(JAVA_FILE).setSize(LARGE_FILE_SIZE).build(); assertThat( new LargeFilesSuggester() .processBundleZipEntry(BundleContext.create(1, false), fileData)) .isEmpty(); }
@Test public void isOnDemandModule_noSuggestion() { fileData = FakeFileData.builder(MP4_VIDEO).build(); assertThat( new LargeFilesSuggester() .processBundleZipEntry(BundleContext.create(1, true), fileData)) .isEmpty(); }
@Test public void notOnDemandModule_containsSuggestions() { fileData = FakeFileData.builder(MP4_VIDEO).setSize(MEDIA_FILE_SIZE).build(); List<Suggestion> suggestions = new LargeFilesSuggester().processBundleZipEntry(BundleContext.create(1, false), fileData); assertThat(suggestions).hasSize(2); assertThat(suggestions) .containsExactly( Suggestion.create( Suggestion.IssueType.MEDIA_STREAMING, Suggestion.Category.LARGE_FILES, Payload.getDefaultInstance(), "Stream media file " + MP4_VIDEO + " from the internet to avoid bundling in apk", MEDIA_FILE_SIZE, null), Suggestion.create( Suggestion.IssueType.LARGE_FILES_DYNAMIC_FEATURE, Suggestion.Category.LARGE_FILES, Payload.getDefaultInstance(), "Place large file " + MP4_VIDEO + " inside an on demand dynamic-feature to avoid bundling in apk", MEDIA_FILE_SIZE, null)); }
@Test public void largeFile_containsOnlyLargeFileSuggestion() { fileData = FakeFileData.builder(BIN_FILE).setSize(LARGE_FILE_SIZE).build(); List<Suggestion> suggestions = new LargeFilesSuggester().processBundleZipEntry(BundleContext.create(1, false), fileData); assertThat(suggestions).hasSize(1); assertThat(suggestions) .containsExactly( Suggestion.create( Suggestion.IssueType.LARGE_FILES_DYNAMIC_FEATURE, Suggestion.Category.LARGE_FILES, Payload.getDefaultInstance(), "Place large file " + BIN_FILE + " inside an on demand dynamic-feature to avoid bundling in apk", LARGE_FILE_SIZE, null)); }