WebpSuggester implements BundleEntrySuggester, ProjectTreeSuggester { @Override public ImmutableList<Suggestion> processBundleZipEntry(BundleContext context, FileData fileData) { return processFileEntry(context, fileData); } WebpSuggester(); @VisibleForTesting  WebpSuggester(WebpConverter webpConverter); @Override ImmutableList<Suggestion> processBundleZipEntry(BundleContext context, FileData fileData); @Override ImmutableList<Suggestion> processProjectEntry(GradleContext context, FileData fileData);  }
@Test public void notAnImageFile_noSuggestion() { FileData file = FakeFileData.builder("hello.ico").build(); assertThat( new WebpSuggester() .processBundleZipEntry( BundleContext.create(MIN_SDK_VERSION_SUPPORTING_LOSSLESS_WEBP), file)) .isEmpty(); }
@Test public void losslessReducibleDrawing_unsupportedApiLevel_noSuggestion() throws IOException { SystemFileData systemFileData = new SystemFileData(getTestDataFile(PNG_DRAWING), Paths.get("drawing.png")); List<Suggestion> suggestions = new WebpSuggester() .processBundleZipEntry( BundleContext.create(MIN_SDK_VERSION_SUPPORTING_LOSSLESS_WEBP - 1), systemFileData); assertThat(suggestions).isEmpty(); }
@Test public void nonLosslessReduciblePhoto_supportedApiLevel_noSuggestion() throws IOException { SystemFileData systemFileData = new SystemFileData(getTestDataFile(JPG_PHOTO), Paths.get("photo.jpg")); List<Suggestion> suggestions = new WebpSuggester() .processBundleZipEntry( BundleContext.create(MIN_SDK_VERSION_SUPPORTING_LOSSLESS_WEBP), systemFileData); assertThat(suggestions).isEmpty(); }
@Test public void reductionBelowThreshold_noSuggestion() throws IOException { FakeWebpConverter fakeConverter = new FakeWebpConverter(); WebpSuggester webpSuggester = new WebpSuggester(fakeConverter); int targetOutputSizeAboveThreshold = (int) (DRAWING_FILE_SIZE - WebpSuggester.SIZE_REDUCTION_THRESHOLD_BYTES + 1); fakeConverter.setFakeData(new byte[targetOutputSizeAboveThreshold]); SystemFileData systemFileData = new SystemFileData(getTestDataFile(PNG_DRAWING), Paths.get("drawing.png")); List<Suggestion> suggestions = webpSuggester.processBundleZipEntry( BundleContext.create(MIN_SDK_VERSION_SUPPORTING_LOSSLESS_WEBP), systemFileData); assertThat(suggestions).isEmpty(); }