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/16 18:57:27 UTC
svn commit: r1883494 - in
/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight:
TestIsartorBavaria.java integration/TestValidFiles.java
Author: msahyoun
Date: Mon Nov 16 18:57:27 2020
New Revision: 1883494
URL: http://svn.apache.org/viewvc?rev=1883494&view=rev
Log:
PDFBOX-5017: switch test to junit5
Modified:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java
Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java?rev=1883494&r1=1883493&r2=1883494&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java Mon Nov 16 18:57:27 2020
@@ -21,6 +21,10 @@
package org.apache.pdfbox.preflight;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -37,26 +41,17 @@ import org.apache.commons.io.FileUtils;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
import org.apache.pdfbox.preflight.parser.PreflightParser;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@RunWith(Parameterized.class)
public class TestIsartorBavaria
{
private static final String FILTER_FILE = "isartor.filter";
private static final String SKIP_BAVARIA = "skip-bavaria";
private static FileOutputStream isartorResultFile;
- @Parameters(name = "{0}")
public static Collection<Object[]> initializeParameters() throws Exception
{
String filter = System.getProperty(FILTER_FILE);
@@ -129,7 +124,7 @@ public class TestIsartorBavaria
return data;
}
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception
{
String irp = System.getProperty("isartor.results.path");
@@ -152,7 +147,7 @@ public class TestIsartorBavaria
}
}
- @AfterClass
+ @AfterAll
public static void afterClass() throws Exception
{
if (isartorResultFile != null)
@@ -161,23 +156,14 @@ public class TestIsartorBavaria
}
}
- private final Set<String> expectedErrorSet;
- private final File file;
-
- public TestIsartorBavaria(File path, Set<String> errorSet)
- {
- System.out.println(" " + path.getName());
- this.file = path;
- this.expectedErrorSet = errorSet;
- }
-
- @Test()
- public void validate() throws Exception
+ @ParameterizedTest
+ @MethodSource("initializeParameters")
+ public void validate(File file, Set<String> expectedErrorSet) throws Exception
{
ValidationResult result = PreflightParser.validate(file);
if (result != null)
{
- if (this.expectedErrorSet.isEmpty())
+ if (expectedErrorSet.isEmpty())
{
Set<String> errorSet = new HashSet<>();
for (ValidationError error : result.getErrorsList())
@@ -197,21 +183,20 @@ public class TestIsartorBavaria
message.append(' ');
message.append(errMsg);
}
- assertTrue(message.toString(), result.isValid());
- assertTrue(message.toString(), result.getErrorsList().isEmpty());
+ assertTrue(result.isValid(), message.toString());
+ assertTrue(result.getErrorsList().isEmpty(), message.toString());
}
else
{
- assertFalse(file.getName() + " : PDF/A file should be invalid (expected "
- + this.expectedErrorSet + ")", result.isValid()); // TODO
+ assertFalse(result.isValid(), file.getName() + " : PDF/A file should be invalid (expected "
+ + expectedErrorSet + ")"); // TODO
- assertTrue(file.getName() + " : Should find at least one error",
- result.getErrorsList().size() > 0);
+ assertTrue(result.getErrorsList().size() > 0, file.getName() + " : Should find at least one error");
// each expected error should occur
boolean logged = false;
boolean allFound = true;
- for (String expectedError : this.expectedErrorSet)
+ for (String expectedError : expectedErrorSet)
{
boolean oneFound = false;
for (ValidationError error : result.getErrorsList())
Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java?rev=1883494&r1=1883493&r2=1883494&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java Mon Nov 16 18:57:27 2020
@@ -1,5 +1,9 @@
package org.apache.pdfbox.preflight.integration;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
/*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -34,15 +38,11 @@ import org.apache.commons.logging.LogFac
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.preflight.ValidationResult;
import org.apache.pdfbox.preflight.parser.PreflightParser;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
-@RunWith(Parameterized.class)
public class TestValidFiles
{
@@ -58,22 +58,15 @@ public class TestValidFiles
protected Log logger = null;
- public TestValidFiles(File path)
- {
- this.path = path;
- this.logger = LogFactory.getLog(path != null ? path.getName() : "dummy");
- }
-
- protected static Collection<Object[]> stopIfExpected() throws Exception
+ protected static Collection<File> stopIfExpected() throws Exception
{
// throw new Exception("Test badly configured");
- List<Object[]> ret = new ArrayList<>();
- ret.add(new Object[] { null });
+ List<File> ret = new ArrayList<>();
+ ret.add(null);
return ret;
}
- @Parameters
- public static Collection<Object[]> initializeParameters() throws Exception
+ public static Collection<File> initializeParameters() throws Exception
{
// find isartor files
String isartor = System.getProperty(ISARTOR_FILES);
@@ -85,19 +78,18 @@ public class TestValidFiles
File root = new File(isartor);
// load expected errors
// prepare config
- List<Object[]> data = new ArrayList<>();
+ List<File> data = new ArrayList<>();
Collection<?> files = FileUtils.listFiles(root, new String[] { "pdf" }, true);
for (Object object : files)
{
File file = (File) object;
- Object[] tmp = new Object[] { file };
- data.add(tmp);
+ data.add(file);
}
return data;
}
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception
{
String irp = System.getProperty(RESULTS_FILE);
@@ -113,15 +105,17 @@ public class TestValidFiles
}
}
- @AfterClass
+ @AfterAll
public static void afterClass() throws Exception
{
IOUtils.closeQuietly(isartorResultFile);
}
- @Test()
- public void validate() throws Exception
+ @ParameterizedTest
+ @MethodSource("initializeParameters")
+ public void validate(File path) throws Exception
{
+ logger = LogFactory.getLog(path != null ? path.getName() : "dummy");
if (path == null)
{
logger.warn("This is an empty test");
@@ -129,14 +123,12 @@ public class TestValidFiles
}
ValidationResult result = PreflightParser.validate(path);
- Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")",
- result.isValid());
- Assert.assertTrue(path + " : Should find at least one error",
- result.getErrorsList().size() > 0);
+ assertFalse(result.isValid(), path + " : Isartor file should be invalid (" + path + ")");
+ assertTrue(result.getErrorsList().size() > 0, path + " : Should find at least one error");
// could contain more than one error
if (result.getErrorsList().size() > 0)
{
- Assert.fail("File expected valid : " + path.getAbsolutePath());
+ fail("File expected valid : " + path.getAbsolutePath());
}
}