You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2022/07/31 13:31:54 UTC

svn commit: r1903143 - in /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf: MergeAcroFormsTest.java MergeAnnotationsTest.java

Author: lehmi
Date: Sun Jul 31 13:31:53 2022
New Revision: 1903143

URL: http://svn.apache.org/viewvc?rev=1903143&view=rev
Log:
PDFBOX-4892: simplify, remove FileInputStream

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

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java?rev=1903143&r1=1903142&r2=1903143&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java Sun Jul 31 13:31:53 2022
@@ -22,9 +22,7 @@ import static org.junit.jupiter.api.Asse
 
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 
 import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.cos.COSBase;
@@ -145,15 +143,10 @@ class MergeAcroFormsTest
         File f2 = new File(TARGET_PDF_DIR, "PDFBOX-1031-2.pdf");
         File pdfOutput = new File(OUT_DIR,"PDFBOX-1031.pdf");
 
-        try (InputStream is1 = new FileInputStream(f1);
-             InputStream is2 = new FileInputStream(f2))
-        {
-            
-            merger.setDestinationFileName(pdfOutput.getAbsolutePath());
-            merger.addSource(is1);
-            merger.addSource(is2);
-            merger.mergeDocuments(null);
-        }
+        merger.setDestinationFileName(pdfOutput.getAbsolutePath());
+        merger.addSource(f1);
+        merger.addSource(f2);
+        merger.mergeDocuments(null);
         
         // Test merge result
         try (PDDocument mergedPDF = Loader.loadPDF(pdfOutput))
@@ -185,14 +178,10 @@ class MergeAcroFormsTest
         
         File pdfOutput = new File(OUT_DIR,"PDFBOX-1100.pdf");
 
-        try (InputStream is1 = new FileInputStream(file1);
-                InputStream is2 = new FileInputStream(file2))
-        {
-            merger.setDestinationFileName(pdfOutput.getAbsolutePath());
-            merger.addSource(is1);
-            merger.addSource(is2);
-            merger.mergeDocuments(null);
-        }
+        merger.setDestinationFileName(pdfOutput.getAbsolutePath());
+        merger.addSource(file1);
+        merger.addSource(file2);
+        merger.mergeDocuments(null);
         
         // Test merge result
         try (PDDocument mergedPDF = Loader.loadPDF(pdfOutput))

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=1903143&r1=1903142&r2=1903143&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 Jul 31 13:31:53 2022
@@ -20,9 +20,7 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -61,49 +59,46 @@ class MergeAnnotationsTest
         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))
+        File pdfOutput = new File(OUT_DIR, "PDFBOX-1065.pdf");
+        merger.setDestinationFileName(pdfOutput.getAbsolutePath());
+        merger.addSource(file1);
+        merger.addSource(file2);
+        merger.mergeDocuments(null);
+
+        // Test merge result
+        try (PDDocument mergedPDF = Loader.loadPDF(pdfOutput))
         {
-            File pdfOutput = new File(OUT_DIR, "PDFBOX-1065.pdf");
-            merger.setDestinationFileName(pdfOutput.getAbsolutePath());
-            merger.addSource(is1);
-            merger.addSource(is2);
-            merger.mergeDocuments(null);
-
-            // Test merge result
-            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");
-            }
+            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");
         }
     }