瀏覽代碼

Updating lib versions (#111)

* updating all lib versions

* changing workflow to java 8

* changing workflow to java 8

* updating plugins

* Update pom.xml

* addressing sonar issues, reviewing docs

* addressing docs and preparing release

* adding notes on wkhtmltopdf location

* improvind ToC docs

---------

Co-authored-by: Jhonny Mertz <jhonny.mertz@hp.com>
Jhonny Mertz 1 年之前
父節點
當前提交
c5fbf480c6
共有 20 個文件被更改,包括 563 次插入208 次删除
  1. 2 2
      .github/workflows/build.yml
  2. 3 2
      .github/workflows/publish.yml
  3. 87 17
      README.md
  4. 32 14
      pom.xml
  5. 93 37
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java
  6. 1 1
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/configurations/WrapperConfig.java
  7. 33 4
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/configurations/XvfbConfig.java
  8. 29 1
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/PDFExportException.java
  9. 6 1
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/WkhtmltopdfConfigurationException.java
  10. 10 1
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/WrapperConfigException.java
  11. 39 4
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/BaseObject.java
  12. 14 6
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/Cover.java
  13. 44 5
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/Page.java
  14. 5 4
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/TableOfContents.java
  15. 29 6
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Param.java
  16. 20 3
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Params.java
  17. 12 2
      src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Symbol.java
  18. 54 50
      src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/integration/PdfIntegrationTests.java
  19. 41 39
      src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/unit/PdfTests.java
  20. 9 9
      src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/unit/XvfbConfigTests.java

+ 2 - 2
.github/workflows/build.yml

@@ -13,10 +13,10 @@ jobs:
           sudo apt-get install -y xfonts-base xfonts-75dpi xvfb libfontconfig
           wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
           sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
-      - name: Set up JDK 11
+      - name: Set up JDK 8
         uses: actions/setup-java@v3
         with:
-          java-version: '11'
+          java-version: '8'
           distribution: 'adopt'
           cache: maven
       - name: Build with Maven

+ 3 - 2
.github/workflows/publish.yml

@@ -19,9 +19,10 @@ jobs:
         run: mvn -B package --file pom.xml
 
       - name: Set up Apache Maven Central
-        uses: actions/setup-java@v1
+        uses: actions/setup-java@v3
         with: # running setup-java again overwrites the settings.xml
-          java-version: 11
+          java-version: '8'
+          distribution: 'adopt'
           server-id: ossrh
           server-username: OSSRH_USERNAME
           server-password: OSSRH_PASSWORD

+ 87 - 17
README.md

@@ -16,7 +16,7 @@ If you are using Gradle/Maven, see example below:
 In your `build.gradle`:
 ```groovy
 dependencies {
-    compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.15-RELEASE'
+    compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.2.0-RELEASE'
 }
 ```
 
@@ -26,7 +26,7 @@ In your `pom.xml`:
 <dependency>
     <groupId>com.github.jhonnymertz</groupId>
     <artifactId>java-wkhtmltopdf-wrapper</artifactId>
-    <version>1.1.15-RELEASE</version>
+    <version>1.2.0-RELEASE</version>
 </dependency>
 ```
 
@@ -40,32 +40,106 @@ String executable = WrapperConfig.findExecutable();
 // Customize the OS command to be called if needed
 Pdf pdf = new Pdf(new WrapperConfig(executable));
 
-pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
-pdf.addPageFromUrl("http://www.google.com");
-
-// Add a Table of Contents
-pdf.addToc();
-
-// The `wkhtmltopdf` shell command accepts different types of options such as global, page, headers and footers, and toc. Please see `wkhtmltopdf -H` for a full explanation.
-// All options are passed as array, for example:
+// Add global params:
 pdf.addParam(new Param("--no-footer-line"), new Param("--header-html", "file:///header.html"));
 pdf.addParam(new Param("--enable-javascript"));
 pdf.addParam(new Param("--javascript-delay", "2000"));
 
-// Add styling for Table of Contents
-pdf.addTocParam(new Param("--xsl-style-sheet", "my_toc.xsl"));
+// Add pages
+Page page1 = pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
+Page page2 = pdf.addPageFromUrl("http://www.google.com");
+
+// Add per-page params
+page1.addParam(new Param("--footer-center", "Page1Footer"));
+page1.addParam(new Param("--exclude-from-outline"));
+page2.addParam(new Param( "--header-center", "Page2HeaderOverride"));
+
+// Add a Table of Contents and ToC params
+TableOfContents toc = pdf.addToc();
+toc.addParam(new Param("--footer-center", "TocFooter"));
+toc.addParam(new Param("--xsl-style-sheet", "my_toc.xsl"));
 
 // Save the PDF
 pdf.saveAs("output.pdf");
 ```
 
+### `wkhtmltopdf` location and automatic retrieval attempt
+
+Library provides a method to attempt to find the `wkhtmltopdf` executable from the OS path, or an exact location can be provided:
+
+```java
+// Attempt to find the wkhtmltopdf command from OS path
+String executable = WrapperConfig.findExecutable();
+
+// Exact custom location
+String executable = "/usr/local/bin/wkhtmltopdf";
+
+final Pdf pdf = new Pdf(new WrapperConfig(executable));
+```
+
+> Note: make sure the tool `wkhtmltopdf` is installed and in the OS path for the user currently running the Java application. Otherwise, library will not be able to find the `wkhtmltopdf`. To test if the command is visible, you may try `which wkhtmltopdf` (linux) or `where wkhtmltopdf` (windows) in the command line. 
+
+### Global params vs. per-object params
+
+`wkhtmltopdf` accepts different types of options such as global, page, headers and footers, and toc. Please see `wkhtmltopdf -H` for a full explanation. The library allows setting params globally and per-object, as follows.
+
+```java
+final Pdf pdf = new Pdf(new WrapperConfig(WrapperConfig.findExecutable()));
+
+// Adding global params
+pdf.addParam(new Param("--header-center", "GlobalHeader"));
+
+// Adding per-object params
+TableOfContents toc = pdf.addToc();
+toc.addParam(new Param("--footer-center", "TocFooter"));
+
+Page page1 = pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page1</h1></html>");
+page1.addParam(new Param("--footer-center", "Page1Footer"));
+page1.addParam(new Param("--exclude-from-outline")); // removes from toc
+
+Page page2 = pdf.addPageFromUrl("http://www.google.com");
+page2.addParam(new Param( "--header-center", "Page2HeaderOverride")); // override global header
+```
+
+### Page/object ordering and ToC positioning
+
+The list of pages/objects in the document appear as the order in which pages/objects were added to the main `pdf`. Except by the ToC, which is always placed at the beginning of the document. However, you can change this by using the `setAlwaysPutTocFirst(false)`.
+
+```java
+final Pdf pdf = new Pdf(new WrapperConfig(WrapperConfig.findExecutable()));
+
+pdf.addCoverFromString("<html><head><meta charset=\"utf-8\"></head><h1>CoverPage</h1></html>");
+pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h2>Page 1</h2></html>");
+pdf.addToc(); // ToC will be placed at the beginning of the document by default, regardless of the order of addition
+pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h2>Page 2</h2></html>");
+
+pdf.getPDF(); // ToC forced to go first, then in order of addition: cover, page 1 and page 2 
+```
+
+#### Changing ToC position
+
+By default, the ToC is always placed at the beginning of the document. You can change this by using the `setAlwaysPutTocFirst(false)`:
+
+```java
+final WrapperConfig config = new WrapperConfig(WrapperConfig.findExecutable());
+config.setAlwaysPutTocFirst(false);
+final Pdf pdf = new Pdf(config);
+
+pdf.addCoverFromString("<html><head><meta charset=\"utf-8\"></head><h1>CoverPage</h1></html>");
+pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h2>Page 1</h2></html>");
+pdf.addToc(); // ToC will be placed according to the order of addition as config.setAlwaysPutTocFirst(false) is set
+pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h2>Page 2</h2></html>");
+
+pdf.getPDF(); // Follows order of addition: cover, page 1, ToC, and page 2
+```
+
 ### Xvfb Support
 
 ```java
 XvfbConfig xc = new XvfbConfig();
 xc.addParams(new Param("--auto-servernum"), new Param("--server-num=1"));
 
-WrapperConfig wc = new WrapperConfig();
+WrapperConfig wc = new WrapperConfig(WrapperConfig.findExecutable());
 wc.setXvfbConfig(xc);
 
 Pdf pdf = new Pdf(wc);
@@ -102,10 +176,6 @@ This is not an official Wkhtmltopdf product
 ------------
 This library is not an official Wkhtmltopdf product. Support is available on a best-effort basis via github issue tracking. Pull requests are welcomed.
 
-Bugs
-------------
-- Tests are incomplete
-
 Known issues
 ------------
 

+ 32 - 14
pom.xml

@@ -3,7 +3,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.github.jhonnymertz</groupId>
     <artifactId>java-wkhtmltopdf-wrapper</artifactId>
-    <version>1.1.15-RELEASE</version>
+    <version>1.2.0-RELEASE</version>
     <packaging>jar</packaging>
 
     <name>Java WkHtmlToPdf Wrapper</name>
@@ -45,18 +45,31 @@
         <maven.compiler.target>1.8</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <slf4j-version>2.0.9</slf4j-version>
+        <commons-lang-version>3.13.0</commons-lang-version>
+        <commons-io-version>2.14.0</commons-io-version>
+        <junit-version>5.10.0</junit-version>
+        <pdfbox-version>3.0.0</pdfbox-version>
+        <mockito-version>5.6.0</mockito-version>
+        <hamcrest-version>1.3</hamcrest-version>
+
+        <!-- Maven plugins -->
+        <maven-surefire-version>3.1.2</maven-surefire-version>
+        <maven-javadoc-version>3.6.0</maven-javadoc-version>
+        <maven-gpg-version>3.1.0</maven-gpg-version>
+        <maven-source-version>3.3.0</maven-source-version>
+        <sonatype-staging-version>1.6.13</sonatype-staging-version>
     </properties>
 
     <dependencies>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
-            <version>3.12.0</version>
+            <version>${commons-lang-version}</version>
         </dependency>
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
-            <version>2.11.0</version>
+            <version>${commons-io-version}</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
@@ -72,21 +85,27 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.13.2</version>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <version>${junit-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-all</artifactId>
+            <version>${hamcrest-version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.pdfbox</groupId>
             <artifactId>pdfbox</artifactId>
-            <version>2.0.29</version>
+            <version>${pdfbox-version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
-            <version>4.11.0</version>
+            <version>${mockito-version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
@@ -103,7 +122,7 @@
                     <!-- Show 100% of the lines from the stack trace (doesn't work) -->
                     <trimStackTrace>false</trimStackTrace>
                 </configuration>
-                <version>3.0.0</version>
+                <version>${maven-surefire-version}</version>
                 <executions>
                     <execution>
                         <id>unit-tests</id>
@@ -144,7 +163,7 @@
             <plugin>
                 <groupId>org.sonatype.plugins</groupId>
                 <artifactId>nexus-staging-maven-plugin</artifactId>
-                <version>1.6.13</version>
+                <version>${sonatype-staging-version}</version>
                 <extensions>true</extensions>
                 <configuration>
                     <serverId>ossrh</serverId>
@@ -163,7 +182,7 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-source-plugin</artifactId>
-                        <version>3.2.1</version>
+                        <version>${maven-source-version}</version>
                         <executions>
                             <execution>
                                 <id>attach-sources</id>
@@ -176,7 +195,7 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-javadoc-plugin</artifactId>
-                        <version>3.5.0</version>
+                        <version>${maven-javadoc-version}</version>
                         <executions>
                             <execution>
                                 <id>attach-javadocs</id>
@@ -189,7 +208,7 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-gpg-plugin</artifactId>
-                        <version>3.0.1</version>
+                        <version>${maven-gpg-version}</version>
                         <executions>
                             <execution>
                                 <id>sign-artifacts</id>
@@ -219,5 +238,4 @@
             <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
         </repository>
     </distributionManagement>
-
 </project>

+ 93 - 37
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java

@@ -6,8 +6,8 @@ import com.github.jhonnymertz.wkhtmltopdf.wrapper.exceptions.PDFExportException;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.BaseObject;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Cover;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Page;
-import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.TableOfContents;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.SourceType;
+import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.TableOfContents;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Params;
 import org.apache.commons.io.FileUtils;
@@ -24,8 +24,13 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -52,12 +57,18 @@ public class Pdf {
 
     private File tempDirectory;
 
+    /**
+     * The constant TEMPORARY_FILE_PREFIX.
+     */
     public static String TEMPORARY_FILE_PREFIX = "java-wkhtmltopdf-wrapper";
 
     private String outputFilename = null;
 
-    private List<Integer> successValues = new ArrayList<Integer>(Arrays.asList(0));
+    private List<Integer> successValues = new ArrayList<>(Collections.singletonList(0));
 
+    /**
+     * Instantiates a new Pdf.
+     */
     @Deprecated
     /**
      * Default constructor
@@ -67,29 +78,40 @@ public class Pdf {
         this(new WrapperConfig());
     }
 
-    public Pdf(WrapperConfig wrapperConfig) {
+    /**
+     * Instantiates a new Pdf.
+     *
+     * @param wrapperConfig the wrapper config
+     */
+    public Pdf(final WrapperConfig wrapperConfig) {
         this.wrapperConfig = wrapperConfig;
         this.params = new Params();
-        this.objects = new ArrayList<BaseObject>();
+        this.objects = new ArrayList<>();
         logger.info("Initialized with {}", wrapperConfig);
     }
 
     /**
      * Add a page to the pdf
      *
+     * @param source the source
+     * @param type   the type
+     * @return the page
      * @deprecated Use the specific type method to a better semantic
      */
     @Deprecated
-    public Page addPage(String source, SourceType type) {
+    public Page addPage(final String source, final SourceType type) {
         Page page = new Page(source, type);
         this.objects.add(page);
         return page;
     }
 
-     /**
+    /**
      * Add a cover from an URL to the pdf
+     *
+     * @param source the source
+     * @return the cover
      */
-    public Cover addCoverFromUrl(String source) {
+    public Cover addCoverFromUrl(final String source) {
         Cover cover = new Cover(source, SourceType.url);
         this.objects.add(cover);
         return cover;
@@ -97,8 +119,11 @@ public class Pdf {
 
     /**
      * Add a cover from a HTML-based string to the pdf
+     *
+     * @param source the source
+     * @return the cover
      */
-    public Cover addCoverFromString(String source) {
+    public Cover addCoverFromString(final String source) {
         Cover cover = new Cover(source, SourceType.htmlAsString);
         this.objects.add(cover);
         return cover;
@@ -106,8 +131,11 @@ public class Pdf {
 
     /**
      * Add a cover from a file to the pdf
+     *
+     * @param source the source
+     * @return the cover
      */
-    public Cover addCoverFromFile(String source) {
+    public Cover addCoverFromFile(final String source) {
         Cover cover = new Cover(source, SourceType.file);
         this.objects.add(cover);
         return cover;
@@ -115,8 +143,11 @@ public class Pdf {
 
     /**
      * Add a page from an URL to the pdf
+     *
+     * @param source the source
+     * @return the page
      */
-    public Page addPageFromUrl(String source) {
+    public Page addPageFromUrl(final String source) {
         Page page = new Page(source, SourceType.url);
         this.objects.add(page);
         return page;
@@ -124,8 +155,11 @@ public class Pdf {
 
     /**
      * Add a page from a HTML-based string to the pdf
+     *
+     * @param source the source
+     * @return the page
      */
-    public Page addPageFromString(String source) {
+    public Page addPageFromString(final String source) {
         Page page = new Page(source, SourceType.htmlAsString);
         this.objects.add(page);
         return page;
@@ -133,8 +167,11 @@ public class Pdf {
 
     /**
      * Add a page from a file to the pdf
+     *
+     * @param source the source
+     * @return the page
      */
-    public Page addPageFromFile(String source) {
+    public Page addPageFromFile(final String source) {
         Page page = new Page(source, SourceType.file);
         this.objects.add(page);
         return page;
@@ -142,6 +179,8 @@ public class Pdf {
 
     /**
      * Add a toc
+     *
+     * @return the table of contents
      */
     public TableOfContents addToc() {
         TableOfContents toc = new TableOfContents();
@@ -150,21 +189,34 @@ public class Pdf {
         return toc;
     }
 
-    public void addParam(Param param, Param... params) {
+    /**
+     * Adds a global param
+     *
+     * @param param  the global param
+     * @param params the global params
+     */
+    public void addParam(final Param param, final Param... params) {
         this.params.add(param, params);
     }
 
     /**
-     * Adds a param to the most recently added toc
+     * Adds a param to the most recently added toc. If more than one ToC is needed, make sure to use per-object params.
+     *
+     * @param param  the param
+     * @param params the params
+     * @deprecated Use per-object params as this will add only to the last ToC
      */
-    public void addTocParam(Param param, Param... params) {
+    @Deprecated
+    public void addTocParam(final Param param, final Param... params) {
         this.lastToc.addParam(param, params);
     }
 
     /**
      * Sets the timeout to wait while generating a PDF, in seconds
+     *
+     * @param timeout the timeout
      */
-    public void setTimeout(int timeout) {
+    public void setTimeout(final int timeout) {
         this.timeout = timeout;
     }
 
@@ -180,6 +232,11 @@ public class Pdf {
         }
     }
 
+    /**
+     * Gets allow missing assets.
+     *
+     * @return the allow missing assets
+     */
     public boolean getAllowMissingAssets() {
         return successValues.contains(1);
     }
@@ -190,7 +247,7 @@ public class Pdf {
      *
      * @param successValues The full list of process return values you will accept as a 'success'.
      */
-    public void setSuccessValues(List<Integer> successValues) {
+    public void setSuccessValues(final List<Integer> successValues) {
         this.successValues = successValues;
     }
 
@@ -198,16 +255,16 @@ public class Pdf {
      * Sets the temporary folder to store files during the process
      * Default is provided by #File.createTempFile()
      *
-     * @param tempDirectory
+     * @param tempDirectory the temp directory
      */
-    public void setTempDirectory(File tempDirectory) {
+    public void setTempDirectory(final File tempDirectory) {
         this.tempDirectory = tempDirectory;
     }
 
     /**
      * Gets the temporary folder where files are stored during processing
-     * 
-     * @return
+     *
+     * @return temp directory
      */
     public File getTempDirectory() {
         return this.tempDirectory;
@@ -216,12 +273,12 @@ public class Pdf {
     /**
      * Executes the wkhtmltopdf into standard out and captures the results.
      *
-     * @param path The path to the file where the PDF will be saved.
-     * @return
-     * @throws IOException
-     * @throws InterruptedException
+     * @param path The path to the file where the PDF will be saved
+     * @return the pdf file generated pointing to the location saved
+     * @throws IOException          when not able to save the file
+     * @throws InterruptedException when the PDF generation process got interrupted
      */
-    public File saveAs(String path) throws IOException, InterruptedException {
+    public File saveAs(final String path) throws IOException, InterruptedException {
         File file = new File(path);
         FileUtils.writeByteArrayToFile(file, getPDF());
         logger.info("PDF successfully saved in {}", file.getAbsolutePath());
@@ -233,10 +290,10 @@ public class Pdf {
      *
      * @param path The path to the file where the PDF will be saved.
      * @return the pdf file saved
-     * @throws IOException when not able to save the file
+     * @throws IOException          when not able to save the file
      * @throws InterruptedException when the PDF generation process got interrupted
      */
-    public File saveAsDirect(String path) throws IOException, InterruptedException {
+    public File saveAsDirect(final String path) throws IOException, InterruptedException {
         File file = new File(path);
         outputFilename = file.getAbsolutePath();
         getPDF();
@@ -247,9 +304,9 @@ public class Pdf {
      * Generates a PDF file as byte array from the wkhtmltopdf output
      *
      * @return the PDF file as a byte array
-     * @throws IOException when not able to save the file
+     * @throws IOException          when not able to save the file
      * @throws InterruptedException when the PDF generation process got interrupted
-     * @throws PDFExportException when the wkhtmltopdf process fails
+     * @throws PDFExportException   when the wkhtmltopdf process fails
      */
     public byte[] getPDF() throws IOException, InterruptedException, PDFExportException {
 
@@ -292,7 +349,7 @@ public class Pdf {
      * @throws IOException when not able to save temporary files from htmlAsString
      */
     protected String[] getCommandAsArray() throws IOException {
-        List<String> commandLine = new ArrayList<String>();
+        List<String> commandLine = new ArrayList<>();
 
         if (wrapperConfig.isXvfbEnabled()) {
             commandLine.addAll(wrapperConfig.getXvfbConfig().getCommandLine());
@@ -304,7 +361,7 @@ public class Pdf {
         commandLine.addAll(params.getParamsAsStringList());
 
         // Check if TOC is always first
-        if(wrapperConfig.getAlwaysPutTocFirst()) {
+        if (wrapperConfig.getAlwaysPutTocFirst()) {
             // remove and add TOC to top
             List<BaseObject> tocObjects = objects.stream().filter((o) -> o instanceof TableOfContents).collect(Collectors.toList()); // .getObjectIdentifier().equalsIgnoreCase("toc")
             objects.removeAll(tocObjects);
@@ -317,7 +374,7 @@ public class Pdf {
         }
 
         commandLine.add((null != outputFilename) ? outputFilename : STDINOUT);
-        logger.debug("Command generated: {}", commandLine.toString());
+        logger.debug("Command generated: {}", commandLine);
         return commandLine.toArray(new String[commandLine.size()]);
     }
 
@@ -332,7 +389,7 @@ public class Pdf {
     private byte[] getFuture(Future<byte[]> future) {
         try {
             return future.get(this.timeout, TimeUnit.SECONDS);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             throw new RuntimeException(e);
         }
     }
@@ -343,7 +400,7 @@ public class Pdf {
     private void cleanTempFiles() {
         logger.debug("Cleaning up temporary files...");
         for (BaseObject object : objects) {
-            if(object instanceof Page) {
+            if (object instanceof Page) {
                 Page page = (Page) object;
                 if (page.getType().equals(SourceType.htmlAsString)) {
                     try {
@@ -381,5 +438,4 @@ public class Pdf {
     public String getCommand() throws IOException {
         return StringUtils.join(getCommandAsArray(), " ");
     }
-
 }

+ 1 - 1
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/configurations/WrapperConfig.java

@@ -74,7 +74,7 @@ public class WrapperConfig {
 
             logger.debug("Wkhtmltopdf command found in classpath: {}", text);
             return text;
-        } catch (InterruptedException | IOException e) {
+        } catch (final InterruptedException | IOException e) {
             logger.error("Fatal:", e);
             throw new WrapperConfigException("Failed while getting wkhtmltopdf executable.", e);
         }

+ 33 - 4
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/configurations/XvfbConfig.java

@@ -14,28 +14,57 @@ public class XvfbConfig {
     private final Params params = new Params();
     private String command;
 
+    /**
+     * Instantiates a new Xvfb config.
+     */
     public XvfbConfig() {
         this("xvfb-run");
     }
 
-    public XvfbConfig(String command) {
+    /**
+     * Instantiates a new Xvfb config.
+     *
+     * @param command the command
+     */
+    public XvfbConfig(final String command) {
         setCommand(command);
     }
 
-    public void addParams(Param param, Param... params) {
+    /**
+     * Add params.
+     *
+     * @param param  the param
+     * @param params the params
+     */
+    public void addParams(final Param param, final Param... params) {
         this.params.add(param, params);
     }
 
+    /**
+     * Gets command.
+     *
+     * @return the command
+     */
     public String getCommand() {
         return command;
     }
 
-    public void setCommand(String command) {
+    /**
+     * Sets command.
+     *
+     * @param command the command
+     */
+    public void setCommand(final String command) {
         this.command = command;
     }
 
+    /**
+     * Gets command line.
+     *
+     * @return the command line
+     */
     public List<String> getCommandLine() {
-        List<String> commandLine = new ArrayList<String>();
+        List<String> commandLine = new ArrayList<>();
 
         commandLine.add(getCommand());
         commandLine.addAll(params.getParamsAsStringList());

+ 29 - 1
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/PDFExportException.java

@@ -13,25 +13,53 @@ public class PDFExportException extends RuntimeException {
 
     private byte[] err;
 
-    public PDFExportException(String command, int exitStatus, byte[] err, byte[] out) {
+    /**
+     * Instantiates a new Pdf export exception.
+     *
+     * @param command    the command
+     * @param exitStatus the exit status
+     * @param err        the err
+     * @param out        the out
+     */
+    public PDFExportException(final String command, final int exitStatus, final byte[] err, final byte[] out) {
         this.command = command;
         this.exitStatus = exitStatus;
         this.err = err;
         this.out = out;
     }
 
+    /**
+     * Gets command.
+     *
+     * @return the command
+     */
     public String getCommand() {
         return command;
     }
 
+    /**
+     * Gets exit status.
+     *
+     * @return the exit status
+     */
     public int getExitStatus() {
         return exitStatus;
     }
 
+    /**
+     * Get out byte [ ].
+     *
+     * @return the byte [ ]
+     */
     public byte[] getOut() {
         return out;
     }
 
+    /**
+     * Get err byte [ ].
+     *
+     * @return the byte [ ]
+     */
     public byte[] getErr() {
         return err;
     }

+ 6 - 1
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/WkhtmltopdfConfigurationException.java

@@ -6,7 +6,12 @@ package com.github.jhonnymertz.wkhtmltopdf.wrapper.exceptions;
  */
 public class WkhtmltopdfConfigurationException extends RuntimeException {
 
-    public WkhtmltopdfConfigurationException(String s) {
+    /**
+     * Instantiates a new Wkhtmltopdf configuration exception.
+     *
+     * @param s the s
+     */
+    public WkhtmltopdfConfigurationException(final String s) {
         super(s);
     }
 

+ 10 - 1
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/exceptions/WrapperConfigException.java

@@ -1,8 +1,17 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.exceptions;
 
+/**
+ * The type Wrapper config exception.
+ */
 public class WrapperConfigException extends RuntimeException {
 
-    public WrapperConfigException(String s, Throwable t) {
+    /**
+     * Instantiates a new Wrapper config exception.
+     *
+     * @param s the s
+     * @param t the t
+     */
+    public WrapperConfigException(final String s, final Throwable t) {
         super(s, t);
     }
 

+ 39 - 4
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/BaseObject.java

@@ -10,35 +10,70 @@ import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Params;
 
+/**
+ * The type Base object.
+ */
 public abstract class BaseObject {
+	/**
+	 * The Object identifier.
+	 */
 	String objectIdentifier;
 
+	/**
+	 * The Params.
+	 */
 	Params params;
 
+	/**
+	 * Instantiates a new Base object.
+	 */
 	BaseObject()
 	{
 		objectIdentifier = SetObjectIdentifier();
 		params = new Params();
 	}
 
+	/**
+	 * Set object identifier string.
+	 *
+	 * @return the string
+	 */
 	public abstract String SetObjectIdentifier();
 
+	/**
+	 * Gets object identifier.
+	 *
+	 * @return the object identifier
+	 */
 	public String getObjectIdentifier() {
 		return this.objectIdentifier;
 	}
 
-	public void addParam( Param param, Param... params )
+	/**
+	 * Add param.
+	 *
+	 * @param param  the param
+	 * @param params the params
+	 */
+	public void addParam(final Param param, final Param... params )
 	{
 		this.params.add( param, params );
 	}
 
-	public List<String> getCommandAsList(Pdf pdf) throws IOException
+	/**
+	 * Gets command as list.
+	 *
+	 * @param pdf the pdf
+	 * @return the command as list
+	 * @throws IOException the io exception
+	 */
+	public List<String> getCommandAsList(final Pdf pdf) throws IOException
 	{
 		List<String> commands = new ArrayList<>();
 		if(StringUtils.isNotBlank(objectIdentifier)){
-			commands.add( objectIdentifier );
+			commands.add(objectIdentifier);
 		}
-		commands.addAll( this.params.getParamsAsStringList() );
+		commands.addAll(this.params.getParamsAsStringList());
 		return commands;
 	}
 }

+ 14 - 6
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/Cover.java

@@ -1,15 +1,23 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.objects;
 
+/**
+ * The type Cover.
+ */
 public class Cover extends Page {
+
     @Override
-    public String SetObjectIdentifier()
-    {
+    public String SetObjectIdentifier() {
         return "cover";
     }
 
-    public Cover( String source, SourceType type )
-    {
-        super( source, type );
+    /**
+     * Instantiates a new Cover.
+     *
+     * @param source the source
+     * @param type   the type
+     */
+    public Cover(final String source, final SourceType type) {
+        super(source, type);
     }
-    
+
 }

+ 44 - 5
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/Page.java

@@ -13,12 +13,21 @@ import org.apache.commons.lang3.StringUtils;
 
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf;
 
+/**
+ * The type Page.
+ */
 public class Page extends BaseObject {
     private String source;
     private String filePath;
     private SourceType type;
 
-    public Page(String source, SourceType type) {
+    /**
+     * Instantiates a new Page.
+     *
+     * @param source the source
+     * @param type   the type
+     */
+    public Page(final String source, final SourceType type) {
         this.source = source;
         this.type = type;
     }
@@ -31,7 +40,7 @@ public class Page extends BaseObject {
     }
 
     @Override
-    public List<String> getCommandAsList(Pdf pdf) throws IOException
+    public List<String> getCommandAsList(final Pdf pdf) throws IOException
     {
         List<String> commands = new ArrayList<>();
         if(StringUtils.isNotBlank(objectIdentifier)){
@@ -61,27 +70,57 @@ public class Page extends BaseObject {
 
     }
 
+    /**
+     * Gets source.
+     *
+     * @return the source
+     */
     public String getSource() {
         return source;
     }
 
-    public void setSource(String source) {
+    /**
+     * Sets source.
+     *
+     * @param source the source
+     */
+    public void setSource(final String source) {
         this.source = source;
     }
 
+    /**
+     * Gets type.
+     *
+     * @return the type
+     */
     public SourceType getType() {
         return type;
     }
 
-    public void setType(SourceType type) {
+    /**
+     * Sets type.
+     *
+     * @param type the type
+     */
+    public void setType(final SourceType type) {
         this.type = type;
     }
 
+    /**
+     * Gets file path.
+     *
+     * @return the file path
+     */
     public String getFilePath() {
         return filePath;
     }
 
-    public void setFilePath(String filePath) {
+    /**
+     * Sets file path.
+     *
+     * @param filePath the file path
+     */
+    public void setFilePath(final String filePath) {
         this.filePath = filePath;
     }
 }

+ 5 - 4
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/objects/TableOfContents.java

@@ -1,10 +1,11 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.objects;
 
-public class TableOfContents extends BaseObject
-{
+/**
+ * The type Table of contents.
+ */
+public class TableOfContents extends BaseObject {
     @Override
-    public String SetObjectIdentifier()
-    {
+    public String SetObjectIdentifier() {
         return "toc";
     }
 }

+ 29 - 6
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Param.java

@@ -1,30 +1,53 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.params;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
+/**
+ * The type Param.
+ */
 public class Param {
 
     private String key;
 
     // Some commands accept more than one value such as cookies and headers
-    private List<String> values = new ArrayList<String>();
+    private List<String> values = new ArrayList<>();
 
-    public Param(String key, String... valueArray) {
+    /**
+     * Instantiates a new Param.
+     *
+     * @param key        the key
+     * @param valueArray the value array
+     */
+    public Param(final String key, final String... valueArray) {
         this.key = key;
-        for (String value : valueArray) {
-            values.add(value);
-        }
+        Collections.addAll(values, valueArray);
     }
 
-    public Param(String key) {
+    /**
+     * Instantiates a new Param.
+     *
+     * @param key the key
+     */
+    public Param(final String key) {
         this(key, new String[0]);
     }
 
+    /**
+     * Gets key.
+     *
+     * @return the key
+     */
     public String getKey() {
         return key;
     }
 
+    /**
+     * Gets values.
+     *
+     * @return the values
+     */
     public List<String> getValues() {
         return values;
     }

+ 20 - 3
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Params.java

@@ -7,21 +7,38 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+/**
+ * The type Params.
+ */
 public class Params {
 
     private Collection<Param> params;
 
+    /**
+     * Instantiates a new Params.
+     */
     public Params() {
-        this.params = new ArrayList<Param>();
+        this.params = new ArrayList<>();
     }
 
-    public void add(Param param, Param... params) {
+    /**
+     * Add.
+     *
+     * @param param  the param
+     * @param params the params
+     */
+    public void add(final Param param, final Param... params) {
         this.params.add(param);
         this.params.addAll(Arrays.asList(params));
     }
 
+    /**
+     * Gets params as string list.
+     *
+     * @return the params as string list
+     */
     public List<String> getParamsAsStringList() {
-        List<String> commandLine = new ArrayList<String>();
+        List<String> commandLine = new ArrayList<>();
 
         for (Param p : params) {
             commandLine.add(p.getKey());

+ 12 - 2
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/params/Symbol.java

@@ -1,12 +1,22 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.params;
 
+/**
+ * The enum Symbol.
+ */
 public enum Symbol {
 
-    separator(" "), param("");
+    /**
+     * Separator symbol.
+     */
+    separator(" "),
+    /**
+     * Param symbol.
+     */
+    param("");
 
     private final String symbol;
 
-    Symbol(String symbol) {
+    Symbol(final String symbol) {
         this.symbol = symbol;
     }
 

+ 54 - 50
src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/integration/PdfIntegrationTests.java

@@ -1,61 +1,65 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.integration;
 
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf;
-import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Page;
-import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.TableOfContents;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.WrapperConfig;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.XvfbConfig;
+import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Page;
+import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.TableOfContents;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.text.PDFTextStripper;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 
-import static org.hamcrest.core.StringContains.containsString;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.StringContains.containsString;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
-public class PdfIntegrationTests {
+class PdfIntegrationTests {
 
     @Test
-    public void findExecutable() {
+    void findExecutable() {
         //see if executable is installed
         try {
             WrapperConfig.findExecutable();
         } catch (RuntimeException ex) {
-            Assert.fail(ex.getMessage());
+            fail(ex.getMessage());
         }
     }
 
     @Test
-    public void getDefaultWkhtmltopdfCommandAsArray() {
+    void getDefaultWkhtmltopdfCommandAsArray() {
         String installedCommand = WrapperConfig.findExecutable();
 
         WrapperConfig wc = new WrapperConfig();
         String[] result = wc.getWkhtmltopdfCommandAsArray();
 
-        Assert.assertArrayEquals(installedCommand.split(" "), result);
+        assertArrayEquals(installedCommand.split(" "), result);
     }
 
     @Test
-    public void getCustomWkhtmltopdfCommandAsArray() {
+    void getCustomWkhtmltopdfCommandAsArray() {
         WrapperConfig wc = new WrapperConfig("custom wkhtmltopdf command");
 
         String[] result = wc.getWkhtmltopdfCommandAsArray();
 
-        Assert.assertEquals("custom", result[0]);
-        Assert.assertEquals("wkhtmltopdf", result[1]);
-        Assert.assertEquals("command", result[2]);
+        assertEquals("custom", result[0]);
+        assertEquals("wkhtmltopdf", result[1]);
+        assertEquals("command", result[2]);
     }
 
     @Test
-    public void testPdfFromStringTo() throws Exception {
+    void testPdfFromStringTo() throws Exception {
 
         // GIVEN a html template containing special characters that java stores in utf-16 internally
         Pdf pdf = new Pdf();
@@ -66,11 +70,11 @@ public class PdfIntegrationTests {
 
         String pdfText = getPdfTextFromBytes(pdfBytes);
 
-        Assert.assertThat("document should contain the creditorName", pdfText, containsString("Müller"));
+        assertThat("document should contain the creditorName", pdfText, containsString("Müller"));
     }
 
     @Test
-    public void testMultipleObjectsOrder() throws Exception {
+    void testMultipleObjectsOrder() throws Exception {
         final String executable = WrapperConfig.findExecutable();
         WrapperConfig config = new WrapperConfig(executable);
         config.setAlwaysPutTocFirst(false);
@@ -83,7 +87,7 @@ public class PdfIntegrationTests {
 
         Page mainPage = pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h2>Heading1</h2></html>");
         mainPage.addParam(new Param("--exclude-from-outline"));
-        
+
         byte[] pdfBytes = pdf.getPDF();
         String pdfText = getPdfTextFromBytes(pdfBytes);
 
@@ -91,18 +95,18 @@ public class PdfIntegrationTests {
         int indexOfCover = pdfText.indexOf("CoverPage");
         int indexOfToc = pdfText.indexOf("TableOfContents");
         int indexOfMainPage = pdfText.indexOf("Heading1");
-        
-        Assert.assertThat("document should have a cover page before the table of contents", indexOfCover < indexOfToc, is(true));
-        Assert.assertThat("document should have a table of contents before the main page", indexOfToc < indexOfMainPage, is(true));
+
+        assertThat("document should have a cover page before the table of contents", indexOfCover < indexOfToc, is(true));
+        assertThat("document should have a table of contents before the main page", indexOfToc < indexOfMainPage, is(true));
     }
 
     @Test
-    public void testMultipleObjectsWithOptions() throws Exception {
+    void testMultipleObjectsWithOptions() throws Exception {
         final String executable = WrapperConfig.findExecutable();
         WrapperConfig config = new WrapperConfig(executable);
         Pdf pdf = new Pdf(config);
 
-        pdf.addParam( new Param( "--header-center", "GlobalHeader" ) );
+        pdf.addParam(new Param("--header-center", "GlobalHeader"));
 
         TableOfContents toc = pdf.addToc();
         toc.addParam(new Param("--footer-center", "TocFooter"));
@@ -112,8 +116,8 @@ public class PdfIntegrationTests {
         page1.addParam(new Param("--exclude-from-outline")); // removes from toc
 
         Page page2 = pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page2</h1></html>");
-        page2.addParam( new Param( "--header-center", "Page2HeaderOverride" ) ); // override global header
-        
+        page2.addParam(new Param("--header-center", "Page2HeaderOverride")); // override global header
+
         byte[] pdfBytes = pdf.getPDF();
         String pdfText = getPdfTextFromBytes(pdfBytes);
 
@@ -121,19 +125,19 @@ public class PdfIntegrationTests {
         int tocFooterCount = StringUtils.countMatches(pdfText, "TocFooter");
         int page1FooterCount = StringUtils.countMatches(pdfText, "Page1Footer");
 
-        Assert.assertThat("document doesn't contain correct number of global headers", 2, equalTo(globalHeaderCount));
-        Assert.assertThat("document doesn't contain correct number of toc footers", 1, equalTo(tocFooterCount));
-        Assert.assertThat("document doesn't contain correct number of page 1 footers", 1, equalTo(page1FooterCount));
+        assertThat("document doesn't contain correct number of global headers", 2, equalTo(globalHeaderCount));
+        assertThat("document doesn't contain correct number of toc footers", 1, equalTo(tocFooterCount));
+        assertThat("document doesn't contain correct number of page 1 footers", 1, equalTo(page1FooterCount));
 
-        try (PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes))) {
-            String pdfTocPageText = getPdfTextForPage(document,1);
-            Assert.assertThat("document toc shouldn't contain page1", pdfTocPageText, not(containsString("Page1")));
-            Assert.assertThat("document toc is missing page2", pdfTocPageText, containsString("Page2"));
+        try (PDDocument document = Loader.loadPDF(pdfBytes)) {
+            String pdfTocPageText = getPdfTextForPage(document, 1);
+            assertThat("document toc shouldn't contain page1", pdfTocPageText, not(containsString("Page1")));
+            assertThat("document toc is missing page2", pdfTocPageText, containsString("Page2"));
         }
     }
 
     @Test
-    public void testMultiplePages() throws Exception {
+    void testMultiplePages() throws Exception {
         Pdf pdf = new Pdf();
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page 1</h1></html>");
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page 2</h1></html>");
@@ -145,11 +149,11 @@ public class PdfIntegrationTests {
 
         String pdfText = getPdfTextFromBytes(pdfBytes);
 
-        Assert.assertThat("document should contain the fourth page name", pdfText, containsString("Page 4"));
+        assertThat("document should contain the fourth page name", pdfText, containsString("Page 4"));
     }
 
     @Test
-    public void callingGetCommandFollowedByGetPdfShouldNotInfluenceTheOutput() throws Exception {
+    void callingGetCommandFollowedByGetPdfShouldNotInfluenceTheOutput() throws Exception {
         Pdf pdf = new Pdf();
 
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Twice</h1></html>");
@@ -161,11 +165,11 @@ public class PdfIntegrationTests {
 
         String pdfText = getPdfTextFromBytes(pdfBytes);
 
-        Assert.assertThat("document should contain the string that was originally inserted", pdfText, containsString("Twice"));
+        assertThat("document should contain the string that was originally inserted", pdfText, containsString("Twice"));
     }
 
     @Test
-    public void testRemovingGeneratedFile() throws Exception {
+    void testRemovingGeneratedFile() throws Exception {
         Pdf pdf = new Pdf();
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page 1</h1></html>");
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page 2</h1></html>");
@@ -173,11 +177,11 @@ public class PdfIntegrationTests {
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Page 4</h1></html>");
 
         File savedPdf = pdf.saveAs("output.pdf");
-        Assert.assertTrue(savedPdf.delete());
+        assertTrue(savedPdf.delete());
     }
 
     private String getPdfTextFromBytes(byte[] pdfBytes) throws IOException {
-        PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
+        PDDocument pdDocument = Loader.loadPDF(pdfBytes);
         String text = new PDFTextStripper().getText(pdDocument);
 
         pdDocument.close();
@@ -193,18 +197,18 @@ public class PdfIntegrationTests {
     }
 
     @Test
-    public void CleanUpTempFilesTest() {
+    void CleanUpTempFilesTest() {
         Pdf pdf = new Pdf();
         pdf.addPageFromString("<!DOCTYPE html><head><title>title</title></head><body><p>TEST</p></body>");
         try {
             pdf.getPDF();
         } catch (Exception ex) {
-            Assert.fail(ex.getMessage());
+            fail(ex.getMessage());
         }
     }
 
     @Test
-    public void testPdfWithXvfb() throws Exception {
+    void testPdfWithXvfb() throws Exception {
         WrapperConfig wc = null;
         if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
             XvfbConfig xc = new XvfbConfig();
@@ -220,14 +224,14 @@ public class PdfIntegrationTests {
 
         // WHEN
         byte[] pdfBytes = pdf.getPDF();
-        PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
+        PDDocument pdDocument = Loader.loadPDF(pdfBytes);
         String pdfText = new PDFTextStripper().getText(pdDocument);
 
-        Assert.assertThat("document should be generated", pdfText, containsString("Google"));
+        assertThat("document should be generated", pdfText, containsString("Google"));
     }
 
     @Test
-    public void testPdfWithLongParameters() throws Exception {
+    void testPdfWithLongParameters() throws Exception {
         final String executable = WrapperConfig.findExecutable();
         Pdf pdf = new Pdf(new WrapperConfig(executable));
         pdf.addPageFromUrl("http://www.google.com");
@@ -238,9 +242,9 @@ public class PdfIntegrationTests {
 
         // WHEN
         byte[] pdfBytes = pdf.getPDF();
-        PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
+        PDDocument pdDocument = Loader.loadPDF(pdfBytes);
         String pdfText = new PDFTextStripper().getText(pdDocument);
 
-        Assert.assertThat("document should be generated", pdfText, containsString("Google"));
+        assertThat("document should be generated", pdfText, containsString("Google"));
     }
 }

+ 41 - 39
src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/unit/PdfTests.java

@@ -8,154 +8,156 @@ import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Cover;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.Page;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.objects.TableOfContents;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.StringContains.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class PdfTests {
+class PdfTests {
 
     private WrapperConfig wc;
     private Pdf pdf;
 
-    @Before
+    @BeforeEach
     public void setUp() {
         wc = new WrapperConfig("wkhtmltopdf");
         pdf = new Pdf(wc);
     }
 
-    @After
+    @AfterEach
     public void cleanUp() {
         pdf.cleanAllTempFiles();
     }
 
     @Test
-    public void testParams() throws Exception {
+    void testParams() throws Exception {
         pdf.addParam(new Param("--enable-javascript"), new Param("--html-header", "file:///example.html"));
         pdf.addPageFromUrl("http://www.google.com");
-        Assert.assertThat("command params should contain the --enable-javascript and --html-header", pdf.getCommand(), containsString("--enable-javascript --html-header file:///example.html"));
+        assertThat("command params should contain the --enable-javascript and --html-header", pdf.getCommand(), containsString("--enable-javascript --html-header file:///example.html"));
     }
 
     @Test
-    public void testUniqueTempFileGenerationDirectory() throws IOException {
+    void testUniqueTempFileGenerationDirectory() throws IOException {
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
         pdf.getCommand();
         pdf.getCommand();
         final File dir = new File(System.getProperty("java.io.tmpdir"));
         File[] files = dir.listFiles(new FilenameFilterConfig());
-        Assert.assertEquals(1, files.length);
+        assertEquals(1, files.length);
     }
 
     @Test
-    public void testTempDirectoryCleanup() throws IOException {
+    void testTempDirectoryCleanup() throws IOException {
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
         pdf.getCommand();
         final File dir = new File(System.getProperty("java.io.tmpdir"));
         File[] files = dir.listFiles(new FilenameFilterConfig());
-        Assert.assertEquals(1, files.length);
+        assertEquals(1, files.length);
         pdf.cleanAllTempFiles();
         files = dir.listFiles(new FilenameFilterConfig());
-        Assert.assertEquals(0, files.length);
+        assertEquals(0, files.length);
     }
 
     @Test
-    public void testCustomTempDirectory() throws IOException {
+    void testCustomTempDirectory() throws IOException {
         File f = File.createTempFile("java-wrapper-wkhtmltopdf-test", ".html");
         pdf.setTempDirectory(new File(f.getParent()));
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
-        Assert.assertThat("command params should contain custom temp directory", pdf.getCommand(), containsString(f.getParent()));
+        assertThat("command params should contain custom temp directory", pdf.getCommand(), containsString(f.getParent()));
     }
 
     @Test
-    public void testMissingAssetsProperty() {
+    void testMissingAssetsProperty() {
         pdf.addPageFromUrl("http://www.google.com");
         pdf.setAllowMissingAssets();
-        Assert.assertTrue(pdf.getAllowMissingAssets());
+        assertTrue(pdf.getAllowMissingAssets());
         pdf.setSuccessValues(Arrays.asList(0, 1));
-        Assert.assertTrue(pdf.getAllowMissingAssets());
+        assertTrue(pdf.getAllowMissingAssets());
     }
 
     @Test
-    public void testAddPages() throws IOException {
+    void testAddPages() throws IOException {
         pdf.addPageFromUrl("http://www.google.com");
         pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
         pdf.addPageFromFile("test.html");
-        Assert.assertThat("command params should contain url input", pdf.getCommand(), containsString("http://www.google.com"));
-        Assert.assertThat("command params should contain file input", pdf.getCommand(), containsString("test.html"));
+        assertThat("command params should contain url input", pdf.getCommand(), containsString("http://www.google.com"));
+        assertThat("command params should contain file input", pdf.getCommand(), containsString("test.html"));
     }
 
     @Test
-    public void testTocParams() throws IOException {
+    void testTocParams() throws IOException {
         pdf.addToc();
         pdf.addTocParam(new Param("--test-param"), new Param("--test-param2", "test-value"));
         pdf.addPageFromUrl("http://www.google.com");
-        Assert.assertThat("command params should contain toc params", pdf.getCommand(), containsString("--test-param2 test-value"));
+        assertThat("command params should contain toc params", pdf.getCommand(), containsString("--test-param2 test-value"));
     }
 
     @Test
-    public void testTocParamsUsingTocObject() throws IOException {
+    void testTocParamsUsingTocObject() throws IOException {
         TableOfContents toc = pdf.addToc();
         toc.addParam(new Param("--test-param"), new Param("--test-param2", "test-value"));
         pdf.addPageFromUrl("http://www.google.com");
-        Assert.assertThat("command params should contain toc params", pdf.getCommand(), containsString("--test-param2 test-value"));
+        assertThat("command params should contain toc params", pdf.getCommand(), containsString("--test-param2 test-value"));
     }
 
     @Test
-    public void testXvfbCommand() throws Exception {
+    void testXvfbCommand() throws Exception {
         wc.setXvfbConfig(new XvfbConfig());
         pdf = new Pdf(wc);
-        Assert.assertThat("command should contain xvfb-run config", pdf.getCommand(), containsString("xvfb-run"));
+        assertThat("command should contain xvfb-run config", pdf.getCommand(), containsString("xvfb-run"));
     }
 
     @Test
-    public void testTocAlwaysFirstByDefault() throws Exception {
+    void testTocAlwaysFirstByDefault() throws Exception {
         pdf.addPageFromUrl("http://www.google.com");
         pdf.addToc();
         pdf.addPageFromFile("test.html");
-        Assert.assertThat("command params should contain toc before pages", pdf.getCommand(), containsString("wkhtmltopdf toc http://www.google.com test.html -"));
+        assertThat("command params should contain toc before pages", pdf.getCommand(), containsString("wkhtmltopdf toc http://www.google.com test.html -"));
     }
 
     @Test
-    public void testTocCustomLocation() throws Exception {
+    void testTocCustomLocation() throws Exception {
         wc.setAlwaysPutTocFirst(false);
         pdf.addPageFromUrl("http://www.google.com");
         pdf.addToc();
         pdf.addPageFromFile("test.html");
-        Assert.assertThat("command params should contain toc after url page and before file page", pdf.getCommand(), containsString("wkhtmltopdf http://www.google.com toc test.html -"));
+        assertThat("command params should contain toc after url page and before file page", pdf.getCommand(), containsString("wkhtmltopdf http://www.google.com toc test.html -"));
     }
 
     @Test
-    public void testPageParams() throws IOException {
+    void testPageParams() throws IOException {
         Page page1 = pdf.addPageFromUrl("http://www.google.com");
         page1.addParam(new Param("--exclude-from-outline"));
         Page page2 = pdf.addPageFromFile("test.html");
         page2.addParam( new Param("--zoom", "2"));
-        Assert.assertThat("command url page should contain page specific params", pdf.getCommand(), containsString("http://www.google.com --exclude-from-outline"));
-        Assert.assertThat("command file page should contain page specific params", pdf.getCommand(), containsString("test.html --zoom"));
+        assertThat("command url page should contain page specific params", pdf.getCommand(), containsString("http://www.google.com --exclude-from-outline"));
+        assertThat("command file page should contain page specific params", pdf.getCommand(), containsString("test.html --zoom"));
     }
 
     @Test
-    public void testCoverParams() throws IOException {
+    void testCoverParams() throws IOException {
         Cover cover = pdf.addCoverFromFile("cover.html");
         cover.addParam(new Param("--test-param"), new Param("--test-param2", "test-value"));
         pdf.addPageFromUrl("http://www.google.com");
-        Assert.assertThat("command params should contain cover params", pdf.getCommand(), containsString("cover cover.html --test-param --test-param2 test-value"));
+        assertThat("command params should contain cover params", pdf.getCommand(), containsString("cover cover.html --test-param --test-param2 test-value"));
     }
 
     @Test
-    public void testMulipleObjects() throws IOException {
+    void testMulipleObjects() throws IOException {
         wc.setAlwaysPutTocFirst(false);
         pdf.addCoverFromFile("cover.html");
         pdf.addPageFromFile("foreword.html");
         pdf.addToc();
         pdf.addPageFromUrl("http://www.google.com");
         pdf.addPageFromFile("test.html");
-        Assert.assertThat("command should match the order objects are added", pdf.getCommand(), containsString("wkhtmltopdf cover cover.html foreword.html toc http://www.google.com test.html -"));
+        assertThat("command should match the order objects are added", pdf.getCommand(), containsString("wkhtmltopdf cover cover.html foreword.html toc http://www.google.com test.html -"));
     }
 }

+ 9 - 9
src/test/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/unit/XvfbConfigTests.java

@@ -4,35 +4,35 @@ import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.WrapperConfig;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.XvfbConfig;
 import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.StringContains.containsString;
 
-public class XvfbConfigTests {
+class XvfbConfigTests {
 
     private WrapperConfig wc;
 
-    @Before
+    @BeforeEach
     public void setUp() {
         wc = new WrapperConfig("wkhtmltopdf");
     }
 
     @Test
-    public void testXvfbEnable() throws Exception {
+    void testXvfbEnable() throws Exception {
         wc.setXvfbConfig(new XvfbConfig());
         Pdf pdf = new Pdf(wc);
-        Assert.assertThat("command should contain xvfb-run config", pdf.getCommand(), containsString("xvfb-run"));
+        assertThat("command should contain xvfb-run config", pdf.getCommand(), containsString("xvfb-run"));
     }
 
     @Test
-    public void testXvfbParams() throws Exception {
+    void testXvfbParams() throws Exception {
         XvfbConfig xvfbConfig = new XvfbConfig();
         xvfbConfig.addParams(new Param("--test-param"), new Param("--test-param2", "test-value"));
         wc.setXvfbConfig(xvfbConfig);
         Pdf pdf = new Pdf(wc);
         pdf.addPageFromUrl("http://www.google.com");
-        Assert.assertThat("command params should contain xvfb params", pdf.getCommand(), containsString("xvfb-run --test-param --test-param2 test-value wkhtmltopdf http://www.google.com -"));
+        assertThat("command params should contain xvfb params", pdf.getCommand(), containsString("xvfb-run --test-param --test-param2 test-value wkhtmltopdf http://www.google.com -"));
     }
 }