OptimizationRuler implements Function<PDDocument, Boolean> { @Override public Boolean apply(PDDocument document) { if (policy == OptimizationPolicy.YES) { return true; } if (policy == OptimizationPolicy.AUTO) { return willNeedOptimization(document); } return false; } OptimizationRuler(OptimizationPolicy policy); @Override Boolean apply(PDDocument document);  }
@Test public void noPolicy() { assertFalse(new OptimizationRuler(OptimizationPolicy.NO).apply(mock(PDDocument.class))); }
@Test public void yesPolicy() { assertTrue(new OptimizationRuler(OptimizationPolicy.YES).apply(mock(PDDocument.class))); }
@Test public void sharedResourceWithImagesDictionary() throws IOException { try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( getClass().getClassLoader().getResourceAsStream("pdf/shared_resource_dic_w_images.pdf")))) { assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document)); } }
@Test public void sharedResourceWithFontsDictionary() throws IOException { try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( getClass().getClassLoader().getResourceAsStream("pdf/shared_resource_dic_w_fonts.pdf")))) { assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document)); } }
@Test public void sharedXobjectsDictionary() throws IOException { try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( getClass().getClassLoader().getResourceAsStream("pdf/shared_xobjects_dics.pdf")))) { assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document)); } }
@Test public void sharedFontsDictionary() throws IOException { try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( getClass().getClassLoader().getResourceAsStream("pdf/shared_fonts_dics.pdf")))) { assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document)); } }