You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/02/21 09:40:44 UTC

svn commit: r1886747 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java

Author: tilman
Date: Sun Feb 21 09:40:44 2021
New Revision: 1886747

URL: http://svn.apache.org/viewvc?rev=1886747&view=rev
Log:
PDFBOX-4892: use try-with-resources

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java?rev=1886747&r1=1886746&r2=1886747&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java Sun Feb 21 09:40:44 2021
@@ -56,15 +56,14 @@ class MergeAnnotationsTest
     @Test
     void testLinkAnnotations() throws IOException
     {
-        
         // Merge the PDFs from PDFBOX-1065
         PDFMergerUtility merger = new PDFMergerUtility();
         File file1 = new File(TARGET_PDF_DIR, "PDFBOX-1065-1.pdf");
         File file2 = new File(TARGET_PDF_DIR, "PDFBOX-1065-2.pdf");
 
         try (InputStream is1 = new FileInputStream(file1);
-                InputStream is2 = new FileInputStream(file2)) {
-
+             InputStream is2 = new FileInputStream(file2))
+        {
             File pdfOutput = new File(OUT_DIR, "PDFBOX-1065.pdf");
             merger.setDestinationFileName(pdfOutput.getAbsolutePath());
             merger.addSource(is1);
@@ -72,39 +71,39 @@ class MergeAnnotationsTest
             merger.mergeDocuments(null);
 
             // Test merge result
-            PDDocument mergedPDF = Loader.loadPDF(pdfOutput);
-            assertEquals(6, mergedPDF.getNumberOfPages(), "There shall be 6 pages");
-
-            PDDocumentNameDestinationDictionary destinations = mergedPDF.getDocumentCatalog().getDests();
-
-            // Each document has 3 annotations with 2 entries in the /Dests dictionary per annotation. One for the
-            // source and one for the target.
-            assertEquals(12, destinations.getCOSObject().entrySet().size(),
-                    "There shall be 12 entries");
-
-            List<PDAnnotation> sourceAnnotations01 = mergedPDF.getPage(0).getAnnotations();
-            List<PDAnnotation> sourceAnnotations02 = mergedPDF.getPage(3).getAnnotations();
-
-            List<PDAnnotation> targetAnnotations01 = mergedPDF.getPage(2).getAnnotations();
-            List<PDAnnotation> targetAnnotations02 = mergedPDF.getPage(5).getAnnotations();
-
-            // Test for the first set of annotations to be merged an linked correctly
-            assertEquals(3, sourceAnnotations01.size(),
-                    "There shall be 3 source annotations at the first page");
-            assertEquals(3, targetAnnotations01.size(),
-                    "There shall be 3 source annotations at the third page");
-            assertTrue(testAnnotationsMatch(sourceAnnotations01, targetAnnotations01),
-                    "The annotations shall match to each other");
-
-            // Test for the second set of annotations to be merged an linked correctly
-            assertEquals(3, sourceAnnotations02.size(),
-                    "There shall be 3 source annotations at the first page");
-            assertEquals(3, targetAnnotations02.size(),
-                    "There shall be 3 source annotations at the third page");
-            assertTrue(testAnnotationsMatch(sourceAnnotations02, targetAnnotations02),
-                    "The annotations shall match to each other");
-
-            mergedPDF.close();
+            try (PDDocument mergedPDF = Loader.loadPDF(pdfOutput))
+            {
+                assertEquals(6, mergedPDF.getNumberOfPages(), "There shall be 6 pages");
+                
+                PDDocumentNameDestinationDictionary destinations = mergedPDF.getDocumentCatalog().getDests();
+                
+                // Each document has 3 annotations with 2 entries in the /Dests dictionary per annotation. One for the
+                // source and one for the target.
+                assertEquals(12, destinations.getCOSObject().entrySet().size(),
+                        "There shall be 12 entries");
+                
+                List<PDAnnotation> sourceAnnotations01 = mergedPDF.getPage(0).getAnnotations();
+                List<PDAnnotation> sourceAnnotations02 = mergedPDF.getPage(3).getAnnotations();
+                
+                List<PDAnnotation> targetAnnotations01 = mergedPDF.getPage(2).getAnnotations();
+                List<PDAnnotation> targetAnnotations02 = mergedPDF.getPage(5).getAnnotations();
+                
+                // Test for the first set of annotations to be merged an linked correctly
+                assertEquals(3, sourceAnnotations01.size(),
+                        "There shall be 3 source annotations at the first page");
+                assertEquals(3, targetAnnotations01.size(),
+                        "There shall be 3 source annotations at the third page");
+                assertTrue(testAnnotationsMatch(sourceAnnotations01, targetAnnotations01),
+                        "The annotations shall match to each other");
+                
+                // Test for the second set of annotations to be merged an linked correctly
+                assertEquals(3, sourceAnnotations02.size(),
+                        "There shall be 3 source annotations at the first page");
+                assertEquals(3, targetAnnotations02.size(),
+                        "There shall be 3 source annotations at the third page");
+                assertTrue(testAnnotationsMatch(sourceAnnotations02, targetAnnotations02),
+                        "The annotations shall match to each other");
+            }
         }
     }