pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1803855 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java
Date Wed, 02 Aug 2017 16:22:12 GMT
Author: tilman
Date: Wed Aug  2 16:22:12 2017
New Revision: 1803855

URL: http://svn.apache.org/viewvc?rev=1803855&view=rev
Log:
PDFBOX-2852: remove unneeded code; use jdk7 syntax

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java?rev=1803855&r1=1803854&r2=1803855&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java
Wed Aug  2 16:22:12 2017
@@ -79,27 +79,28 @@ public class PDSquareAnnotationTest
         // the width of the <nnotations border
         final int borderWidth = 1;
 
-        PDDocument document = new PDDocument();
-        PDPage page = new PDPage();
-        document.addPage(page);
-        List<PDAnnotation> annotations = page.getAnnotations();
-
-        PDAnnotationSquareCircle annotation = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
-
-        PDBorderStyleDictionary borderThin = new PDBorderStyleDictionary();
-        borderThin.setWidth(borderWidth);
-
-        PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
-        annotation.setContents("Square Annotation");
-        annotation.setColor(red);
-        annotation.setBorderStyle(borderThin);
-
-
-        annotation.setRectangle(rectangle);
-
-        annotation.constructAppearances();
-        annotations.add(annotation);
-        document.close();
+        try (PDDocument document = new PDDocument())
+        {
+            PDPage page = new PDPage();
+            document.addPage(page);
+            List<PDAnnotation> annotations = page.getAnnotations();
+            
+            PDAnnotationSquareCircle annotation = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
+            
+            PDBorderStyleDictionary borderThin = new PDBorderStyleDictionary();
+            borderThin.setWidth(borderWidth);
+            
+            PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
+            annotation.setContents("Square Annotation");
+            annotation.setColor(red);
+            annotation.setBorderStyle(borderThin);
+            
+            
+            annotation.setRectangle(rectangle);
+            
+            annotation.constructAppearances();
+            annotations.add(annotation);
+        }
     }
     
     @Test
@@ -109,60 +110,54 @@ public class PDSquareAnnotationTest
         final int borderWidth = 1;
 
         File file = new File(IN_DIR, NAME_OF_PDF);
-        PDDocument document = PDDocument.load(file);
-        PDPage page = document.getPage(0);
-        List<PDAnnotation> annotations = page.getAnnotations();
-
-        PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) annotations.get(0);
-
-        PDRectangle rectangle = new PDRectangle();
-        rectangle.setLowerLeftX(91.5958f);
-        rectangle.setLowerLeftY(741.91f);
-        rectangle.setUpperRightX(113.849f);
-        rectangle.setUpperRightY(757.078f);
-
-        // test the correct setting of the appearance stream
-        assertNotNull("Appearance dictionary shall not be null", annotation.getAppearance());
-        assertNotNull("Normal appearance shall not be null", annotation.getAppearance().getNormalAppearance());
-        PDAppearanceStream appearanceStream = annotation.getAppearance().getNormalAppearance().getAppearanceStream();
-        assertNotNull("Appearance stream shall not be null", appearanceStream);
-        assertEquals(rectangle.getLowerLeftX(), appearanceStream.getBBox().getLowerLeftX(),
DELTA);
-        assertEquals(rectangle.getLowerLeftY(), appearanceStream.getBBox().getLowerLeftY(),
DELTA);
-        assertEquals(rectangle.getWidth(), appearanceStream.getBBox().getWidth(), DELTA);
-        assertEquals(rectangle.getHeight(), appearanceStream.getBBox().getHeight(), DELTA);
-
-        Matrix matrix = appearanceStream.getMatrix();
-        assertNotNull("Matrix shall not be null", matrix);
-
-        // should have been translated to a 0 origin
-        assertEquals(-rectangle.getLowerLeftX(), matrix.getTranslateX(), DELTA);
-        assertEquals(-rectangle.getLowerLeftY(), matrix.getTranslateY(), DELTA);
-
-        // test the content of the apperance stream
-        PDStream contentStream = appearanceStream.getContentStream();
-        assertNotNull("Content stream shall not be null", contentStream);
-        PDFStreamParser parser = new PDFStreamParser(appearanceStream);
-        parser.parse();
-        List<Object> tokens = parser.getTokens();
-
-        // the samples content stream should contain 10 tokens
-        assertEquals(10, tokens.size());
-
-        // setting of the stroking color
-        assertEquals(1, ((COSInteger) tokens.get(0)).intValue());
-        assertEquals(0, ((COSInteger) tokens.get(1)).intValue());
-        assertEquals(0, ((COSInteger) tokens.get(2)).intValue());
-        assertEquals("RG", ((Operator) tokens.get(3)).getName());
-
-        // setting of the rectangle for the border
-        // it shall be inset by the border width
-        assertEquals(rectangle.getLowerLeftX() + borderWidth, ((COSFloat) tokens.get(4)).floatValue(),
DELTA);
-        assertEquals(rectangle.getLowerLeftY() + borderWidth, ((COSFloat) tokens.get(5)).floatValue(),
DELTA);
-        assertEquals(rectangle.getWidth() - 2 * borderWidth, ((COSFloat) tokens.get(6)).floatValue(),
DELTA);
-        assertEquals(rectangle.getHeight() - 2 * borderWidth, ((COSFloat) tokens.get(7)).floatValue(),
DELTA);
-        assertEquals("re", ((Operator) tokens.get(8)).getName());
-        assertEquals("S", ((Operator) tokens.get(9)).getName());
-        
-        document.close();
+        try (PDDocument document = PDDocument.load(file))
+        {
+            PDPage page = document.getPage(0);
+            List<PDAnnotation> annotations = page.getAnnotations();
+            
+            PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) annotations.get(0);
+            
+            // test the correct setting of the appearance stream
+            assertNotNull("Appearance dictionary shall not be null", annotation.getAppearance());
+            assertNotNull("Normal appearance shall not be null", annotation.getAppearance().getNormalAppearance());
+            PDAppearanceStream appearanceStream = annotation.getAppearance().getNormalAppearance().getAppearanceStream();
+            assertNotNull("Appearance stream shall not be null", appearanceStream);
+            assertEquals(rectangle.getLowerLeftX(), appearanceStream.getBBox().getLowerLeftX(),
DELTA);
+            assertEquals(rectangle.getLowerLeftY(), appearanceStream.getBBox().getLowerLeftY(),
DELTA);
+            assertEquals(rectangle.getWidth(), appearanceStream.getBBox().getWidth(), DELTA);
+            assertEquals(rectangle.getHeight(), appearanceStream.getBBox().getHeight(), DELTA);
+            
+            Matrix matrix = appearanceStream.getMatrix();
+            assertNotNull("Matrix shall not be null", matrix);
+            
+            // should have been translated to a 0 origin
+            assertEquals(-rectangle.getLowerLeftX(), matrix.getTranslateX(), DELTA);
+            assertEquals(-rectangle.getLowerLeftY(), matrix.getTranslateY(), DELTA);
+            
+            // test the content of the apperance stream
+            PDStream contentStream = appearanceStream.getContentStream();
+            assertNotNull("Content stream shall not be null", contentStream);
+            PDFStreamParser parser = new PDFStreamParser(appearanceStream);
+            parser.parse();
+            List<Object> tokens = parser.getTokens();
+            
+            // the samples content stream should contain 10 tokens
+            assertEquals(10, tokens.size());
+            
+            // setting of the stroking color
+            assertEquals(1, ((COSInteger) tokens.get(0)).intValue());
+            assertEquals(0, ((COSInteger) tokens.get(1)).intValue());
+            assertEquals(0, ((COSInteger) tokens.get(2)).intValue());
+            assertEquals("RG", ((Operator) tokens.get(3)).getName());
+            
+            // setting of the rectangle for the border
+            // it shall be inset by the border width
+            assertEquals(rectangle.getLowerLeftX() + borderWidth, ((COSFloat) tokens.get(4)).floatValue(),
DELTA);
+            assertEquals(rectangle.getLowerLeftY() + borderWidth, ((COSFloat) tokens.get(5)).floatValue(),
DELTA);
+            assertEquals(rectangle.getWidth() - 2 * borderWidth, ((COSFloat) tokens.get(6)).floatValue(),
DELTA);
+            assertEquals(rectangle.getHeight() - 2 * borderWidth, ((COSFloat) tokens.get(7)).floatValue(),
DELTA);
+            assertEquals("re", ((Operator) tokens.get(8)).getName());
+            assertEquals("S", ((Operator) tokens.get(9)).getName());
+        }
     }
 }



Mime
View raw message