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 2009/08/26 19:41:34 UTC

svn commit: r808134 - in /incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox: cos/ encryption/ pdfparser/ pdmodel/interactive/form/ util/

Author: lehmi
Date: Wed Aug 26 17:41:33 2009
New Revision: 808134

URL: http://svn.apache.org/viewvc?rev=808134&view=rev
Log:
PDFBOX-464: improve checkstyle compliance

Modified:
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/cos/TestCOSString.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestDateUtil.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripper.java
    incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripperPerformance.java

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/cos/TestCOSString.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/cos/TestCOSString.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/cos/TestCOSString.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/cos/TestCOSString.java Wed Aug 26 17:41:33 2009
@@ -22,8 +22,6 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.pdfbox.cos.COSString;
-
 /**
  * This will test all of the filters in the PDFBox system.
  *

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java Wed Aug 26 17:41:33 2009
@@ -58,7 +58,12 @@
      */
     private PDDocument document;
 
-    protected void setUp() throws Exception {
+    
+    /**
+     * {@inheritDoc}
+     */
+    protected void setUp() throws Exception 
+    {
         permission1 = new AccessPermission();
         permission1.setCanAssembleDocument(false);
         permission1.setCanExtractContent(false);
@@ -87,14 +92,21 @@
 
         InputStream input =
             TestPublicKeyEncryption.class.getResourceAsStream("test.pdf");
-        try {
+        try 
+        {
             document = PDDocument.load(input);
-        } finally {
+        } 
+        finally 
+        {
             input.close();
         }
     }
 
-    protected void tearDown() throws Exception {
+    /**
+     * {@inheritDoc}
+     */
+    protected void tearDown() throws Exception 
+    {
         document.close();
     }
 
@@ -111,13 +123,18 @@
         document.protect(policy);
 
         PDDocument encrypted = reload(document);
-        try {
+        try 
+        {
             Assert.assertTrue(encrypted.isEncrypted());
             encrypted.openProtection(decryption2);
             fail("No exception when using an incorrect decryption key");
-        } catch(CryptographyException expected) {
+        } 
+        catch(CryptographyException expected) 
+        {
             // do nothing
-        } finally {
+        } 
+        finally 
+        {
             encrypted.close();
         }
     }
@@ -136,7 +153,8 @@
         document.protect(policy);
 
         PDDocument encrypted = reload(document);
-        try {
+        try 
+        {
             Assert.assertTrue(encrypted.isEncrypted());
             encrypted.openProtection(decryption1);
 
@@ -150,7 +168,9 @@
             Assert.assertFalse(permission.canModifyAnnotations());
             Assert.assertFalse(permission.canPrint());
             Assert.assertFalse(permission.canPrintDegraded());
-        } finally {
+        } 
+        finally 
+        {
             encrypted.close();
         }
     }
@@ -170,7 +190,8 @@
 
         // open first time
         PDDocument encrypted1 = reload(document);
-        try {
+        try 
+        {
             encrypted1.openProtection(decryption1);
 
             AccessPermission permission =
@@ -183,13 +204,16 @@
             Assert.assertFalse(permission.canModifyAnnotations());
             Assert.assertFalse(permission.canPrint());
             Assert.assertFalse(permission.canPrintDegraded());
-        } finally {
+        } 
+        finally 
+        {
             encrypted1.close();
         }
 
         // open second time
         PDDocument encrypted2 = reload(document);
-        try {
+        try 
+        {
             encrypted2.openProtection(decryption2);
 
             AccessPermission permission =
@@ -202,7 +226,9 @@
             Assert.assertFalse(permission.canModifyAnnotations());
             Assert.assertTrue(permission.canPrint());
             Assert.assertFalse(permission.canPrintDegraded());
-        } finally {
+        } 
+        finally 
+        {
             encrypted2.close();
         }
     }
@@ -211,18 +237,24 @@
      * Reloads the given document by writing it to a temporary byte array
      * and loading a fresh document from that byte array.
      *
-     * @param document input document
+     * @param doc input document
      * @return reloaded document
      * @throws Exception if 
      */
-    private PDDocument reload(PDDocument document) {
-        try {
+    private PDDocument reload(PDDocument doc) 
+    {
+        try 
+        {
             ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-            document.save(buffer);
+            doc.save(buffer);
             return PDDocument.load(new ByteArrayInputStream(buffer.toByteArray()));
-        } catch (IOException e) {
+        } 
+        catch (IOException e) 
+        {
             throw new IllegalStateException("Unexpected failure");
-        } catch (COSVisitorException e) {
+        } 
+        catch (COSVisitorException e) 
+        {
             throw new IllegalStateException("Unexpected failure");
         }
     }
@@ -236,32 +268,35 @@
      * @return recipient specification
      * @throws Exception if the certificate could not be read
      */
-    private PublicKeyRecipient getRecipient(
-            String certificate, AccessPermission permission) throws Exception {
-        InputStream input =
-            TestPublicKeyEncryption.class.getResourceAsStream(certificate);
-        try {
-            CertificateFactory factory =
-                CertificateFactory.getInstance("X.509");
+    private PublicKeyRecipient getRecipient(String certificate, AccessPermission permission) throws Exception 
+    {
+        InputStream input = TestPublicKeyEncryption.class.getResourceAsStream(certificate);
+        try 
+        {
+            CertificateFactory factory = CertificateFactory.getInstance("X.509");
             PublicKeyRecipient recipient = new PublicKeyRecipient();
             recipient.setPermission(permission);
             recipient.setX509(
                     (X509Certificate) factory.generateCertificate(input));
             return recipient;
-        } finally {
+        } 
+        finally 
+        {
             input.close();
         }
     }
 
-    private PublicKeyDecryptionMaterial getDecryptionMaterial(
-            String name, String password) throws Exception {
-        InputStream input = 
-            TestPublicKeyEncryption.class.getResourceAsStream(name);
-        try {
+    private PublicKeyDecryptionMaterial getDecryptionMaterial(String name, String password) throws Exception 
+    {
+        InputStream input = TestPublicKeyEncryption.class.getResourceAsStream(name);
+        try 
+        {
             KeyStore keystore = KeyStore.getInstance("PKCS12");
             keystore.load(input, password.toCharArray());
             return new PublicKeyDecryptionMaterial(keystore, null, password);
-        } finally {
+        } 
+        finally 
+        {
             input.close();
         }
     }

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java Wed Aug 26 17:41:33 2009
@@ -25,8 +25,6 @@
 import junit.framework.TestSuite;
 
 import org.apache.pdfbox.cos.COSName;
-
-import org.apache.pdfbox.pdfparser.BaseParser;
 import org.apache.pdfbox.pdmodel.PDDocument;
 
 

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java Wed Aug 26 17:41:33 2009
@@ -23,8 +23,6 @@
 import junit.framework.TestSuite;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDTextbox;
 
 /**
  * This will test the form fields in PDFBox.

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestDateUtil.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestDateUtil.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestDateUtil.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestDateUtil.java Wed Aug 26 17:41:33 2009
@@ -23,8 +23,6 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.pdfbox.util.DateConverter;
-
 /**
  * Test the date conversion utility.
  *

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripper.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripper.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripper.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripper.java Wed Aug 26 17:41:33 2009
@@ -35,7 +35,6 @@
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 
-import org.apache.pdfbox.util.PDFTextStripper;
 
 /**
  * Test suite for PDFTextStripper.
@@ -125,7 +124,7 @@
      * @return <code>true</code> is the strings are both null,
      * or if their contents are the same, otherwise <code>false</code>.
      */
-    private boolean stringsEqual(PrintWriter log, String expected, String actual)
+    private boolean stringsEqual(String expected, String actual)
     {
         boolean equals = true;
         if( (expected == null) && (actual == null) )
@@ -215,10 +214,12 @@
     public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSort)
     throws Exception
     {
-        if(bSort){
+        if(bSort)
+        {
             log.println("Preparing to parse " + inFile.getName() + " for sorted test");
         }
-        else{
+        else
+        {
             log.println("Preparing to parse " + inFile.getName() + " for standard test");
         }
 
@@ -227,9 +228,11 @@
         PDDocument document = null;
         try
         {
-            if (outDir.exists() == false) {
-                if (outDir.mkdirs() == false) {
-                    throw (new Exception ("Error creating " + outDir.getAbsolutePath() + " directory"));
+            if (!outDir.exists()) 
+            {
+                if (!outDir.mkdirs()) 
+                {
+                    throw (new Exception("Error creating " + outDir.getAbsolutePath() + " directory"));
                 }
             }
             
@@ -237,11 +240,13 @@
             File outFile = null;
             File expectedFile = null;
 
-            if(bSort){
+            if(bSort)
+            {
                 outFile = new File(outDir,  inFile.getName() + "-sorted.txt");
                 expectedFile = new File(inFile.getParentFile(), inFile.getName() + "-sorted.txt");
             }
-            else{
+            else
+            {
                 outFile = new File(outDir, inFile.getName() + ".txt");
                 expectedFile = new File(inFile.getParentFile(), inFile.getName() + ".txt");
             }
@@ -287,7 +292,7 @@
                 {
                     actualLine = actualReader.readLine();
                 }
-                if (!stringsEqual(log, expectedLine, actualLine))
+                if (!stringsEqual(expectedLine, actualLine))
                 {
                     this.bFail = true;
                     log.println("FAILURE: Line mismatch for file " + inFile.getName() +
@@ -327,14 +332,18 @@
      * @param inDir Input directory search for PDF files in.
      * @param outDir Output directory where the temp files will be created.
      */
-    private void doTestDir(File inDir, File outDir) throws Exception {
-        File[] testFiles = inDir.listFiles(new FilenameFilter() {
-            public boolean accept(File dir, String name) {
+    private void doTestDir(File inDir, File outDir) throws Exception 
+    {
+        File[] testFiles = inDir.listFiles(new FilenameFilter() 
+        {
+            public boolean accept(File dir, String name) 
+            {
                 return (name.endsWith(".pdf"));
             }
         });
 
-        for (int n = 0; n < testFiles.length; n++) {
+        for (int n = 0; n < testFiles.length; n++) 
+        {
             //Test without sorting
             doTestFile(testFiles[n], outDir, false, false);
             //Test with sorting
@@ -360,12 +369,16 @@
         {
             log = new PrintWriter( new FileWriter( "textextract.log" ) );
 
-            if ((filename == null) || (filename.length() == 0)) {
+            if ((filename == null) || (filename.length() == 0)) 
+            {
                 doTestDir(inDir, outDir);
                 if (inDirExt.exists())
+                {
                     doTestDir(inDirExt, outDirExt);
+                }
             }
-            else {
+            else 
+            {
                 //Test without sorting
                 doTestFile(new File(inDir, filename), outDir, true, false);
                 //Test with sorting

Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripperPerformance.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripperPerformance.java?rev=808134&r1=808133&r2=808134&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripperPerformance.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestTextStripperPerformance.java Wed Aug 26 17:41:33 2009
@@ -29,7 +29,6 @@
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 
-import org.apache.pdfbox.util.PDFTextStripper;
 
 /**
  * Test the performance of the PDF text stripper utility.