You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2020/11/17 08:42:43 UTC
svn commit: r1883514 - in /pdfbox/trunk/tools: ./
src/test/java/org/apache/pdfbox/tools/
src/test/java/org/apache/pdfbox/tools/imageio/
Author: msahyoun
Date: Tue Nov 17 08:42:42 2020
New Revision: 1883514
URL: http://svn.apache.org/viewvc?rev=1883514&view=rev
Log:
PDFBOX-5017: switch to JUnit5; remove vintage engine
Modified:
pdfbox/trunk/tools/pom.xml
pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestExtractText.java
pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java
pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java
Modified: pdfbox/trunk/tools/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/pom.xml?rev=1883514&r1=1883513&r2=1883514&view=diff
==============================================================================
--- pdfbox/trunk/tools/pom.xml (original)
+++ pdfbox/trunk/tools/pom.xml Tue Nov 17 08:42:42 2020
@@ -58,10 +58,6 @@
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<scope>test</scope>
Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestExtractText.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestExtractText.java?rev=1883514&r1=1883513&r2=1883514&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestExtractText.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestExtractText.java Tue Nov 17 08:42:42 2020
@@ -16,15 +16,18 @@
*/
package org.apache.pdfbox.tools;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
/**
* Test suite for ExtractText.
*/
-public class TestExtractText extends TestCase
+public class TestExtractText
{
/**
@@ -32,6 +35,7 @@ public class TestExtractText extends Tes
*
* @throws Exception if something went wrong
*/
+ @Test
public void testEmbeddedPDFs() throws Exception
{
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java?rev=1883514&r1=1883513&r2=1883514&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java Tue Nov 17 08:42:42 2020
@@ -16,6 +16,9 @@
*/
package org.apache.pdfbox.tools;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -26,12 +29,11 @@ import org.apache.pdfbox.pdmodel.PDPageC
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
-import junit.framework.TestCase;
import org.apache.pdfbox.text.PDFTextStripper;
+import org.junit.jupiter.api.Test;
-public class TestPDFText2HTML extends TestCase
+public class TestPDFText2HTML
{
-
private PDDocument createDocument(String title, PDFont font, String text) throws IOException
{
PDDocument doc = new PDDocument();
@@ -49,6 +51,7 @@ public class TestPDFText2HTML extends Te
return doc;
}
+ @Test
public void testEscapeTitle() throws IOException
{
PDFTextStripper stripper = new PDFText2HTML();
@@ -61,6 +64,7 @@ public class TestPDFText2HTML extends Te
assertTrue(text.contains("<foo>"));
}
+ @Test
public void testStyle() throws IOException
{
PDFTextStripper stripper = new PDFText2HTML();
@@ -68,7 +72,7 @@ public class TestPDFText2HTML extends Te
String text = stripper.getText(doc);
Matcher bodyMatcher = Pattern.compile("<p>(.*?)</p>").matcher(text);
- assertTrue("body p exists", bodyMatcher.find());
- assertEquals("body p", "<b><bold></b>", bodyMatcher.group(1));
+ assertTrue(bodyMatcher.find(), "body p exists");
+ assertEquals("<b><bold></b>", bodyMatcher.group(1), "body p");
}
-}
+}
\ No newline at end of file
Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java?rev=1883514&r1=1883513&r2=1883514&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java Tue Nov 17 08:42:42 2020
@@ -16,35 +16,24 @@
*/
package org.apache.pdfbox.tools;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import java.io.IOException;
import java.io.StringReader;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.jupiter.api.Test;
/**
* Test suite for TextToPDF.
*/
-public class TestTextToPdf extends TestCase
+public class TestTextToPdf
{
/**
- * Test class constructor.
- *
- * @param name The name of the test class.
- *
- * @throws IOException If there is an error creating the test.
- */
- public TestTextToPdf( String name ) throws IOException
- {
- super( name );
- }
-
- /**
* This test ensures that a PDF created from an empty String is still readable by Adobe Reader
*/
+ @Test
public void testCreateEmptyPdf() throws Exception
{
TextToPDF pdfCreator = new TextToPDF();
@@ -57,29 +46,8 @@ public class TestTextToPdf extends TestC
// In order for the PDF document to be openable by Adobe Reader, it needs
// to have some pages in it. So we'll check that.
int pageCount = pdfDoc.getNumberOfPages();
- assertNotNull("All Pages was unexpectedly zero.", pageCount);
- assertEquals("Wrong number of pages.", 1, pageCount);
+ assertNotNull(pageCount, "All Pages was unexpectedly zero.");
+ assertEquals(1, pageCount, "Wrong number of pages.");
pdfDoc.close();
}
-
- /**
- * Set the tests in the suite for this test class.
- *
- * @return the Suite.
- */
- public static Test suite()
- {
- return new TestSuite( TestTextToPdf.class );
- }
-
- /**
- * Command line execution.
- *
- * @param args Command line arguments.
- */
- public static void main( String[] args )
- {
- String[] arg = {TestTextToPdf.class.getName() };
- junit.textui.TestRunner.main( arg );
- }
}
Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java?rev=1883514&r1=1883513&r2=1883514&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java Tue Nov 17 08:42:42 2020
@@ -16,6 +16,12 @@
*/
package org.apache.pdfbox.tools.imageio;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
@@ -35,8 +41,6 @@ import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;
-import junit.framework.TestCase;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.Loader;
@@ -51,7 +55,7 @@ import org.apache.pdfbox.rendering.Image
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.util.filetypedetector.FileType;
import org.apache.pdfbox.util.filetypedetector.FileTypeDetector;
-import org.junit.Assert;
+import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -59,7 +63,7 @@ import org.w3c.dom.NodeList;
/**
* Test suite for ImageIOUtil.
*/
-public class TestImageIOUtils extends TestCase
+public class TestImageIOUtils
{
private static final Log LOG = LogFactory.getLog(TestImageIOUtils.class);
@@ -195,7 +199,7 @@ public class TestImageIOUtils extends Te
throws IOException
{
BufferedImage newImage = ImageIO.read(new File(filename));
- assertNotNull("File '" + filename + "' could not be read", newImage);
+ assertNotNull(newImage, "File '" + filename + "' could not be read");
checkNotBlank(filename, newImage);
checkBufferedImageSize(filename, image, newImage);
for (int x = 0; x < image.getWidth(); ++x)
@@ -204,7 +208,7 @@ public class TestImageIOUtils extends Te
{
if (image.getRGB(x, y) != newImage.getRGB(x, y))
{
- assertEquals("\"File '" + filename + "' has different pixel at (" + x + "," + y + ")", new Color(image.getRGB(x, y)), new Color(newImage.getRGB(x, y)));
+ assertEquals(new Color(image.getRGB(x, y)), new Color(newImage.getRGB(x, y)), "\"File '" + filename + "' has different pixel at (" + x + "," + y + ")");
}
}
}
@@ -221,7 +225,7 @@ public class TestImageIOUtils extends Te
throws IOException
{
BufferedImage newImage = ImageIO.read(new File(filename));
- assertNotNull("File '" + filename + "' could not be read", newImage);
+ assertNotNull(newImage, "File '" + filename + "' could not be read");
checkNotBlank(filename, newImage);
checkBufferedImageSize(filename, image, newImage);
}
@@ -229,8 +233,8 @@ public class TestImageIOUtils extends Te
private void checkBufferedImageSize(String filename,
BufferedImage image, BufferedImage newImage) throws IOException
{
- assertEquals("File '" + filename + "' has different height after read", image.getHeight(), newImage.getHeight());
- assertEquals("File '" + filename + "' has different width after read", image.getWidth(), newImage.getWidth());
+ assertEquals(image.getHeight(), newImage.getHeight(), "File '" + filename + "' has different height after read");
+ assertEquals(image.getWidth(), newImage.getWidth(), "File '" + filename + "' has different width after read");
}
private void checkNotBlank(String filename, BufferedImage newImage)
@@ -246,7 +250,7 @@ public class TestImageIOUtils extends Te
colors.add(newImage.getRGB(x, y));
}
}
- assertFalse("File '" + filename + "' has less than two colors", colors.size() < 2);
+ assertFalse(colors.size() < 2, "File '" + filename + "' has less than two colors");
}
private void writeImage(PDDocument document, String imageFormat, String outputPrefix,
@@ -262,7 +266,7 @@ public class TestImageIOUtils extends Te
{
boolean res = ImageIOUtil.writeImage(image, imageFormat, os,
Math.round(dpi), compressionQuality, compressionType);
- assertTrue("ImageIOUtil.writeImage() failed for file " + fileName, res);
+ assertTrue(res, "ImageIOUtil.writeImage() failed for file " + fileName);
}
if ("jpg".equals(imageFormat) || "gif".equals(imageFormat) || "JPEG".equals(compressionType))
@@ -282,6 +286,7 @@ public class TestImageIOUtils extends Te
*
* @throws Exception when there is an exception
*/
+ @Test
public void testRenderImage() throws Exception
{
String inDir = "src/test/resources/input/ImageIOUtil";
@@ -315,7 +320,7 @@ public class TestImageIOUtils extends Te
private void checkResolution(String filename, int expectedResolution)
throws IOException
{
- Assert.assertNotEquals("Empty file " + filename, 0, new File(filename).length());
+ assertNotEquals(0, new File(filename).length(), "Empty file " + filename);
String suffix = filename.substring(filename.lastIndexOf('.') + 1);
if ("BMP".equalsIgnoreCase(suffix))
{
@@ -324,31 +329,31 @@ public class TestImageIOUtils extends Te
return;
}
Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
- assertTrue("No image reader found for suffix " + suffix, readers.hasNext());
+ assertTrue(readers.hasNext(), "No image reader found for suffix " + suffix);
ImageReader reader = (ImageReader) readers.next();
try (ImageInputStream iis = ImageIO.createImageInputStream(new File(filename)))
{
- assertNotNull("No ImageInputStream created for file " + filename, iis);
+ assertNotNull(iis, "No ImageInputStream created for file " + filename);
reader.setInput(iis);
IIOMetadata imageMetadata = reader.getImageMetadata(0);
Element root = (Element) imageMetadata.getAsTree(STANDARD_METADATA_FORMAT);
NodeList dimensionNodes = root.getElementsByTagName("Dimension");
- assertTrue("No resolution found in image file " + filename, dimensionNodes.getLength() > 0);
+ assertTrue(dimensionNodes.getLength() > 0, "No resolution found in image file " + filename);
Element dimensionElement = (Element) dimensionNodes.item(0);
NodeList pixelSizeNodes = dimensionElement.getElementsByTagName("HorizontalPixelSize");
- assertTrue("No X resolution found in image file " + filename, pixelSizeNodes.getLength() > 0);
+ assertTrue(pixelSizeNodes.getLength() > 0, "No X resolution found in image file " + filename);
Node pixelSizeNode = pixelSizeNodes.item(0);
String val = pixelSizeNode.getAttributes().getNamedItem("value").getNodeValue();
int actualResolution = (int) Math.round(25.4 / Double.parseDouble(val));
- assertEquals("X resolution doesn't match in image file " + filename, expectedResolution, actualResolution);
+ assertEquals(expectedResolution, actualResolution, "X resolution doesn't match in image file " + filename);
pixelSizeNodes = dimensionElement.getElementsByTagName("VerticalPixelSize");
- assertTrue("No Y resolution found in image file " + filename, pixelSizeNodes.getLength() > 0);
+ assertTrue(pixelSizeNodes.getLength() > 0, "No Y resolution found in image file " + filename);
pixelSizeNode = pixelSizeNodes.item(0);
val = pixelSizeNode.getAttributes().getNamedItem("value").getNodeValue();
actualResolution = (int) Math.round(25.4 / Double.parseDouble(val));
- assertEquals("Y resolution doesn't match", expectedResolution, actualResolution);
+ assertEquals(expectedResolution, actualResolution, "Y resolution doesn't match");
}
reader.dispose();
}
@@ -370,15 +375,13 @@ public class TestImageIOUtils extends Te
try (DataInputStream dis = new DataInputStream(new FileInputStream(new File(filename))))
{
int skipped = dis.skipBytes(38);
- assertEquals("Can't skip 38 bytes in image file " + filename, 38, skipped);
+ assertEquals(38, skipped, "Can't skip 38 bytes in image file " + filename);
int pixelsPerMeter = Integer.reverseBytes(dis.readInt());
int actualResolution = (int) Math.round(pixelsPerMeter / 100.0 * 2.54);
- assertEquals("X resolution doesn't match in image file " + filename,
- expectedResolution, actualResolution);
+ assertEquals(expectedResolution, actualResolution, "X resolution doesn't match in image file " + filename);
pixelsPerMeter = Integer.reverseBytes(dis.readInt());
actualResolution = (int) Math.round(pixelsPerMeter / 100.0 * 2.54);
- assertEquals("Y resolution doesn't match in image file " + filename,
- expectedResolution, actualResolution);
+ assertEquals(expectedResolution, actualResolution, "Y resolution doesn't match in image file " + filename);
}
}
@@ -402,7 +405,7 @@ public class TestImageIOUtils extends Te
Element comprElement = (Element) root.getElementsByTagName("Compression").item(0);
Node comprTypeNode = comprElement.getElementsByTagName("CompressionTypeName").item(0);
String actualCompression = comprTypeNode.getAttributes().getNamedItem("value").getNodeValue();
- assertEquals("Incorrect TIFF compression in file " + filename, expectedCompression, actualCompression);
+ assertEquals(expectedCompression, actualCompression, "Incorrect TIFF compression in file " + filename);
}
reader.dispose();
}