pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1849413 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Date Thu, 20 Dec 2018 16:26:53 GMT
Author: tilman
Date: Thu Dec 20 16:26:53 2018
New Revision: 1849413

URL: http://svn.apache.org/viewvc?rev=1849413&view=rev
Log:
PDFBOX-4071: DRY refactoring

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

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1849413&r1=1849412&r2=1849413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Thu Dec 20 16:26:53 2018
@@ -193,12 +193,10 @@ public class PDFMergerUtilityTest extend
         dst.close();
 
         PDDocument doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf"));
-        PDPageTree pageTree = doc.getPages();
 
-        // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees.
-        PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot();
-        checkElement(pageTree, structureTreeRoot.getParentTree().getCOSObject());
-        checkElement(pageTree, structureTreeRoot.getK());
+        checkForPageOrphans(doc);
+
+        doc.close();
     }
 
     /**
@@ -231,16 +229,12 @@ public class PDFMergerUtilityTest extend
         dst.close();
 
         doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf"));
-        PDPageTree pageTree = doc.getPages();
 
-        // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees.
-        PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot();
-        checkElement(pageTree, structureTreeRoot.getParentTree().getCOSObject());
-        checkElement(pageTree, structureTreeRoot.getK());
+        checkForPageOrphans(doc);
 
         // Assume that the merged tree has double element count
         elementCounter = new ElementCounter();
-        elementCounter.walk(structureTreeRoot.getK());
+        elementCounter.walk(doc.getDocumentCatalog().getStructureTreeRoot().getK());
         assertEquals(singleCnt * 2, elementCounter.cnt);
         assertEquals(singleSetSize * 2, elementCounter.set.size());
 
@@ -261,13 +255,7 @@ public class PDFMergerUtilityTest extend
         src.close();
         dst.save(new File(TARGETTESTDIR, "PDFBOX-4408-merged.pdf"));
         checkWithNumberTree(dst);
-
-        // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees.
-        PDPageTree pageTree = dst.getPages();
-        PDStructureTreeRoot structureTreeRoot = dst.getDocumentCatalog().getStructureTreeRoot();
-        checkElement(pageTree, structureTreeRoot.getParentTree().getCOSObject());
-        checkElement(pageTree, structureTreeRoot.getK());
-
+        checkForPageOrphans(dst);
         dst.close();
     }
     /**
@@ -338,6 +326,15 @@ public class PDFMergerUtilityTest extend
         Files.delete(outFile.toPath());
     }
 
+    private void checkForPageOrphans(PDDocument doc) throws IOException
+    {
+        // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees.
+        PDPageTree pageTree = doc.getPages();
+        PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot();
+        checkElement(pageTree, structureTreeRoot.getParentTree().getCOSObject());
+        checkElement(pageTree, structureTreeRoot.getK());
+    }
+
     private void createSimpleFile(File file) throws IOException
     {
         try (PDDocument doc = new PDDocument())



Mime
View raw message