maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1744011 - /maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
Date Mon, 16 May 2016 10:14:32 GMT
Author: hboutemy
Date: Mon May 16 10:14:32 2016
New Revision: 1744011

URL: http://svn.apache.org/viewvc?rev=1744011&view=rev
Log:
code simplification

Modified:
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java?rev=1744011&r1=1744010&r2=1744011&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
(original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
Mon May 16 10:14:32 2016
@@ -35,36 +35,15 @@ import java.io.Reader;
 public class PdfMojoTest
     extends AbstractMojoTestCase
 {
-    /** {@inheritDoc} */
-    protected void setUp() throws Exception
-    {
-        // required for mojo lookups to work
-        super.setUp();
-    }
-
     /**
      * Tests the basic functioning of the pdf generation using the FO implementation.
      *
      * @throws Exception if any.
      */
-    public void testPdfMojo() throws Exception
+    public void testPdfMojo()
+        throws Exception
     {
-        File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/pom.xml" );
-        assertTrue( "testPom does not exist!", testPom.exists() );
-
-        PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
-        assertNotNull( "pdf mojo not found!", mojo );
-
-        File pdfFile = new File( getBasedir(), "/target/test-output/pdf/fo/maven-pdf-plugin-doc.pdf"
);
-        if ( pdfFile.exists() )
-        {
-            pdfFile.delete();
-        }
-
-        mojo.execute();
-
-        assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
-        assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
+        executePdfMojo( "pom.xml", "fo/maven-pdf-plugin-doc.pdf" );
     }
 
     /**
@@ -72,47 +51,30 @@ public class PdfMojoTest
      *
      * @throws Exception if any.
      */
-    public void testITextImpl() throws Exception
+    public void testITextImpl()
+        throws Exception
     {
-        File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/iText_pom.xml"
);
-        assertTrue( "testPom does not exist!", testPom.exists() );
-
-        PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
-        assertNotNull( "pdf mojo not found!", mojo );
-
-        File pdfFile = new File( getBasedir(), "/target/test-output/pdf/itext/maven-pdf-plugin-doc.pdf"
);
-        if ( pdfFile.exists() )
-        {
-            pdfFile.delete();
-        }
-
-        mojo.execute();
-
-        assertTrue( "iText: Pdf file not created!", pdfFile.exists() );
-        assertTrue( "iText: Pdf file has no content!", pdfFile.length() > 0 );
+        executePdfMojo( "iText_pom.xml", "itext/maven-pdf-plugin-doc.pdf" );
      }
 
     /**
+     * Tests the basic functioning of the pdf generation using the FO implementation.
+     *
      * @throws Exception if any.
      */
-    public void testPdfFilterMojo() throws Exception
+    public void testPdfMojoNoDocDesriptor()
+        throws Exception
     {
-        File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/pom_filtering.xml"
);
-        assertTrue( "testPom does not exist!", testPom.exists() );
-
-        PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
-        assertNotNull( "pdf mojo not found!", mojo );
-
-        File pdfFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf"
);
-        if ( pdfFile.exists() )
-        {
-            pdfFile.delete();
-        }
-
-        mojo.execute();
+        executePdfMojo( "no_docdescriptor_pom.xml", "no/unnamed.pdf" );
+    }
 
-        assertTrue( "FO: Pdf file not created!", pdfFile.exists() );
-        assertTrue( "FO: Pdf file has no content!", pdfFile.length() > 0 );
+    /**
+     * @throws Exception if any.
+     */
+    public void testPdfFilterMojo()
+        throws Exception
+    {
+        executePdfMojo( "pom_filtering.xml", "filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.pdf"
);
 
         File foFile = new File( getBasedir(), "/target/test-output/pdf/filtering/maven-pdf-plugin-doc-1.0-SNAPSHOT.fo"
);
         assertTrue( "FO: Fo file not created!", foFile.exists() );
@@ -147,25 +109,32 @@ public class PdfMojoTest
         assertTrue( foContent.indexOf( new DateBean().getDate() ) > 0 );
     }
 
-    /**
-     * Tests the basic functioning of the pdf generation using the FO implementation.
-     *
-     * @throws Exception if any.
-     */
-    public void testPdfMojoNoDocDesriptor() throws Exception
+    protected PdfMojo lookupPdfMojo( String pom )
+        throws Exception
     {
-        File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/no_docdescriptor_pom.xml"
);
+        File testPom = new File( getBasedir(), "target/test-classes/unit/pdf/" + pom );
         assertTrue( "testPom does not exist!", testPom.exists() );
-
         PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
         assertNotNull( "pdf mojo not found!", mojo );
+        return mojo;
+    }
 
-        File pdfFile = new File( getBasedir(), "/target/test-output/pdf/no/unnamed.pdf" );
+    protected File prepareOutputPdf( String filename )
+    {
+        File pdfFile = new File( getBasedir(), "target/test-output/pdf/" + filename );
         if ( pdfFile.exists() )
         {
             pdfFile.delete();
         }
+        return pdfFile;
+    }
+
+    protected void executePdfMojo( String pom, String pdfFilename )
+        throws Exception
+    {
+        File pdfFile = prepareOutputPdf( pdfFilename );
 
+        PdfMojo mojo = lookupPdfMojo( pom );
         mojo.execute();
 
         assertTrue( "FO: Pdf file not created!", pdfFile.exists() );



Mime
View raw message