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 2020/11/16 20:59:03 UTC
svn commit: r1883500 - in
/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text: BidiTest.java
TestTextStripper.java
Author: lehmi
Date: Mon Nov 16 20:59:02 2020
New Revision: 1883500
URL: http://svn.apache.org/viewvc?rev=1883500&view=rev
Log:
PDFBOX-5017: switch test to junit5
Modified:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java?rev=1883500&r1=1883499&r2=1883500&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java Mon Nov 16 20:59:02 2020
@@ -17,7 +17,7 @@
package org.apache.pdfbox.text;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileInputStream;
@@ -33,9 +33,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
-import org.junit.After;
-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;
/**
* Test for the PDButton class.
@@ -59,7 +59,7 @@ public class BidiTest
private boolean bFail = false;
- @Before
+ @BeforeEach
public void setUp() throws IOException
{
if (!outDir.exists())
@@ -89,7 +89,7 @@ public class BidiTest
doTestFile(testFile, outDir, false, false);
}
- @After
+ @AfterEach
public void tearDown() throws IOException
{
document.close();
@@ -104,7 +104,7 @@ public class BidiTest
* @param bSort Whether or not the extracted text is sorted
* @throws Exception when there is an exception
*/
- public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSort)
+ private void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSort)
throws IOException
{
if(bSort)
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java?rev=1883500&r1=1883499&r2=1883500&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java Mon Nov 16 20:59:02 2020
@@ -21,6 +21,13 @@ import difflib.DeleteDelta;
import difflib.DiffUtils;
import difflib.InsertDelta;
import difflib.Patch;
+
+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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -38,10 +45,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.util.BoundingBox;
@@ -54,7 +57,8 @@ import org.apache.pdfbox.pdmodel.font.PD
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
-import org.junit.Assert;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
@@ -102,7 +106,7 @@ import org.junit.Assert;
* @author Robert Dickinson
* @author Ben Litchfield
*/
-public class TestTextStripper extends TestCase
+public class TestTextStripper
{
/**
@@ -111,7 +115,7 @@ public class TestTextStripper extends Te
private static final Log log = LogFactory.getLog(TestTextStripper.class);
private boolean bFail = false;
- private PDFTextStripper stripper = null;
+ private static PDFTextStripper stripper;
private static final String ENCODING = "UTF-8";
/**
@@ -121,22 +125,13 @@ public class TestTextStripper extends Te
*
* @throws IOException If there is an error creating the test.
*/
- public TestTextStripper( String name ) throws IOException
+ @BeforeAll
+ static void init() throws IOException
{
- super( name );
stripper = new PDFTextStripper();
stripper.setLineSeparator("\n");
- }
-
- /**
- * Test suite setup.
- */
- @Override
- public void setUp()
- {
// If you want to test a single file using DEBUG logging, from an IDE,
// you can do something like this:
- //
// System.setProperty("org.apache.pdfbox.util.TextStripper.file", "FVS318Ref.pdf");
}
@@ -234,7 +229,7 @@ public class TestTextStripper extends Te
* @param bSort Whether or not the extracted text is sorted
* @throws Exception when there is an exception
*/
- public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSort)
+ private void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSort)
throws Exception
{
if(bSort)
@@ -440,6 +435,7 @@ public class TestTextStripper extends Te
* @throws IOException
* @throws URISyntaxException
*/
+ @Test
public void testStripByOutlineItems() throws IOException, URISyntaxException
{
PDDocument doc = Loader
@@ -484,7 +480,7 @@ public class TestTextStripper extends Te
stripper.setEndBookmark(oi3);
String textoi23 = stripper.getText(doc);
assertFalse(textoi23.isEmpty());
- Assert.assertNotEquals(textoi23, textFull);
+ assertNotEquals(textoi23, textFull);
String expectedTextoi23 =
"Second at level 1\n"
@@ -504,8 +500,8 @@ public class TestTextStripper extends Te
stripper.setEndPage(4);
String textp34 = stripper.getText(doc);
assertFalse(textp34.isEmpty());
- Assert.assertNotEquals(textoi23, textFull);
- Assert.assertEquals(textoi23, textp34);
+ assertNotEquals(textoi23, textFull);
+ assertEquals(textoi23, textp34);
// this should grab 0-based page 2, i.e. 1-based page 3
// by the bookmark
@@ -513,8 +509,8 @@ public class TestTextStripper extends Te
stripper.setEndBookmark(oi2);
String textoi2 = stripper.getText(doc);
assertFalse(textoi2.isEmpty());
- Assert.assertNotEquals(textoi2, textoi23);
- Assert.assertNotEquals(textoi23, textFull);
+ assertNotEquals(textoi2, textoi23);
+ assertNotEquals(textoi23, textFull);
String expectedTextoi2 =
"Second at level 1\n"
@@ -531,9 +527,9 @@ public class TestTextStripper extends Te
stripper.setEndPage(3);
String textp3 = stripper.getText(doc);
assertFalse(textp3.isEmpty());
- Assert.assertNotEquals(textp3, textp34);
- Assert.assertNotEquals(textoi23, textFull);
- Assert.assertEquals(textoi2, textp3);
+ assertNotEquals(textp3, textp34);
+ assertNotEquals(textoi23, textFull);
+ assertEquals(textoi2, textp3);
// Test with orphan bookmark
PDOutlineItem oiOrphan = new PDOutlineItem();
@@ -565,6 +561,7 @@ public class TestTextStripper extends Te
*
* @throws Exception when there is an exception
*/
+ @Test
public void testExtract() throws Exception
{
String filename = System.getProperty("org.apache.pdfbox.util.TextStripper.file");
@@ -595,6 +592,7 @@ public class TestTextStripper extends Te
}
}
+ @Test
public void testTabula() throws IOException
{
File pdfFile = new File("src/test/resources/input","eu-001.pdf");
@@ -677,24 +675,4 @@ public class TestTextStripper extends Te
}
}
- /**
- * Set the tests in the suite for this test class.
- *
- * @return the Suite.
- */
- public static Test suite()
- {
- return new TestSuite( TestTextStripper.class );
- }
-
- /**
- * Command line execution.
- *
- * @param args Command line arguments.
- */
- public static void main( String[] args )
- {
- String[] arg = {TestTextStripper.class.getName() };
- junit.textui.TestRunner.main( arg );
- }
}