Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java Thu Dec 24 18:42:29 2020 @@ -16,6 +16,18 @@ ==================================================================== */ package org.apache.poi.stress; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.ref.WeakReference; + import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.usermodel.GroupShape; import org.apache.poi.sl.usermodel.Notes; @@ -29,18 +41,6 @@ import org.apache.poi.sl.usermodel.TextP import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextShape; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.ref.WeakReference; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - public abstract class SlideShowHandler extends POIFSFileHandler { public void handleSlideShow(SlideShow<?,?> ss) throws IOException { renderSlides(ss); @@ -127,10 +127,8 @@ public abstract class SlideShowHandler e private void readPictures(SlideShow<?,?> ss) { for (PictureData pd : ss.getPictureData()) { Dimension dim = pd.getImageDimension(); - assertTrue("Expecting a valid height, but had an image with height: " + dim.getHeight(), - dim.getHeight() >= 0); - assertTrue("Expecting a valid width, but had an image with width: " + dim.getWidth(), - dim.getWidth() >= 0); + assertTrue( dim.getHeight() >= 0, "Expecting a valid height, but had an image with height: " + dim.getHeight() ); + assertTrue( dim.getWidth() >= 0, "Expecting a valid width, but had an image with width: " + dim.getWidth() ); } }
Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.stress; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -37,10 +37,10 @@ public abstract class SpreadsheetHandler public void handleWorkbook(Workbook wb) throws IOException { // try to access some of the content readContent(wb); - + // write out the file writeToArray(wb); - + // access some more content (we had cases where writing corrupts the data in memory) readContent(wb); @@ -51,11 +51,11 @@ public abstract class SpreadsheetHandler Workbook read = WorkbookFactory.create(new ByteArrayInputStream(out.toByteArray())); assertNotNull(read); - + readContent(read); - + extractEmbedded(read); - + modifyContent(read); read.close(); @@ -68,7 +68,7 @@ public abstract class SpreadsheetHandler } finally { stream.close(); } - + return stream; } @@ -84,7 +84,7 @@ public abstract class SpreadsheetHandler if(sheet.getPhysicalNumberOfRows() > 1000) { continue; } - + for(Row row : sheet) { for(Cell cell : row) { assertNotNull(cell.toString()); @@ -111,7 +111,7 @@ public abstract class SpreadsheetHandler } } } - + private void modifyContent(Workbook wb) { /* a number of file fail because of various things: udf, unimplemented functions, ... we would need quite a list of excludes and the large regression tests would probably Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/TestAllFiles.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/TestAllFiles.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/TestAllFiles.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/TestAllFiles.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,8 @@ package org.apache.poi.stress; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.BufferedInputStream; import java.io.File; @@ -34,18 +33,16 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.stream.Stream; import org.apache.poi.OldFileFormatException; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.tools.ant.DirectoryScanner; -import org.junit.AssumptionViolatedException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.opentest4j.TestAbortedException; /** * This is an integration test which performs various actions on all stored test-files and tries @@ -54,7 +51,7 @@ import org.junit.runners.Parameterized.P * This test looks for any file under the test-data directory and tries to do some useful * processing with it based on it's type. * - * The test is implemented as a junit {@link Parameterized} test, which leads + * The test is implemented as a junit {@link ParameterizedTest} test, which leads * to one test-method call for each file (currently around 950 files are handled). * * There is a a mapping of extension to implementations of the interface @@ -71,7 +68,6 @@ import org.junit.runners.Parameterized.P * here as well! This is to ensure that files that should not work really do not work, e.g. * that we do not remove expected sanity checks. */ -@RunWith(Parameterized.class) public class TestAllFiles { private static final File ROOT_DIR = new File("test-data"); private static final boolean IGNORE_SCRATCHPAD = Boolean.getBoolean("scratchpad.ignore"); @@ -344,8 +340,7 @@ public class TestAllFiles { "spreadsheet/61300.xls"//intentionally fuzzed -- used to cause infinite loop ); - @Parameters(name="{index}: {0} using {1}") - public static Iterable<Object[]> files() { + public static Stream<Arguments> files() { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(ROOT_DIR); scanner.setExcludes(SCAN_EXCLUDES); @@ -354,7 +349,7 @@ public class TestAllFiles { System.out.println("Handling " + scanner.getIncludedFiles().length + " files"); - List<Object[]> files = new ArrayList<>(); + List<Arguments> files = new ArrayList<>(); for(String file : scanner.getIncludedFiles()) { file = file.replace('\\', '/'); // ... failures/handlers lookup doesn't work on windows otherwise if (IGNORED.contains(file)) { @@ -362,49 +357,41 @@ public class TestAllFiles { continue; } FileHandler handler = HANDLERS.get(getExtension(file)); - files.add(new Object[] { file, handler }); + files.add(Arguments.of( file, handler )); // for some file-types also run OPCFileHandler if(handler instanceof XSSFFileHandler || handler instanceof XWPFFileHandler || handler instanceof XSLFFileHandler || handler instanceof XDGFFileHandler) { - files.add(new Object[] { file, new OPCFileHandler() }); + files.add(Arguments.of( file, new OPCFileHandler() )); } if (handler instanceof HSSFFileHandler || handler instanceof HSLFFileHandler || handler instanceof HWPFFileHandler || handler instanceof HDGFFileHandler) { - files.add(new Object[] { file, new HPSFFileHandler() }); + files.add(Arguments.of( file, new HPSFFileHandler() )); } } - return files; + return files.stream(); } - @SuppressWarnings("DefaultAnnotationParam") - @Parameter(value=0) - public String file; + // the display name annotation is ignored by ants junitlauncher listeners :( + // ... even when using a custom display name generator + @ParameterizedTest(name = "#{index} {0}" ) + @MethodSource("files") + public void testAllFiles(String file, FileHandler handler) throws Exception { + assertNotNull(handler, "Did not find a handler for file " + file); - @Parameter(value=1) - public FileHandler handler; - - @Before - public void setPassword() { // this also removes the password for non encrypted files String pass = TestAllFiles.FILE_PASSWORD.get(file); Biff8EncryptionKey.setCurrentUserPassword(pass); - } - @Test - public void testAllFiles() throws Exception { - if(handler == null) { - fail("Did not find a handler for file " + file); - } System.out.println("Reading " + file + " with " + handler.getClass().getSimpleName()); - assertNotNull("Unknown file extension for file: " + file + ": " + getExtension(file), handler); + assertNotNull( handler, "Unknown file extension for file: " + file + ": " + getExtension(file) ); File inputFile = new File(ROOT_DIR, file); // special cases where docx-handling breaks, but OPCPackage handling works @@ -416,14 +403,12 @@ public class TestAllFiles { try { try (InputStream stream = new BufferedInputStream(new FileInputStream(inputFile), 64 * 1024)) { handler.handleFile(stream, file); - assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!", - OLD_FILES_HWPF.contains(file) && !ignoreHPSF); + assertFalse( OLD_FILES_HWPF.contains(file) && !ignoreHPSF, "Expected to fail for file " + file + " and handler " + handler + ", but did not fail!" ); } handler.handleExtracting(inputFile); - assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!", - EXPECTED_FAILURES.contains(file) && !ignoredOPC && !ignoreHPSF); + assertFalse( EXPECTED_FAILURES.contains(file) && !ignoredOPC && !ignoreHPSF, "Expected to fail for file " + file + " and handler " + handler + ", but did not fail!" ); } catch (OldFileFormatException e) { // for old word files we should still support extracting text if(OLD_FILES_HWPF.contains(file)) { @@ -435,7 +420,7 @@ public class TestAllFiles { throw new Exception("While handling " + file, e); } } - } catch (AssumptionViolatedException e) { + } catch (TestAbortedException e) { // file handler ignored this file } catch (Exception e) { // check if we expect failure for this file @@ -448,7 +433,7 @@ public class TestAllFiles { try { // let some file handlers do additional stuff handler.handleAdditional(inputFile); - } catch (AssumptionViolatedException e) { + } catch (TestAbortedException e) { // file handler ignored this file } catch (Exception e) { if(!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) { Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/XDGFFileHandler.java Thu Dec 24 18:42:29 2020 @@ -21,7 +21,7 @@ import java.io.InputStream; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.xdgf.usermodel.XmlVisioDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class XDGFFileHandler extends AbstractFileHandler { @Override Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java Thu Dec 24 18:42:29 2020 @@ -16,8 +16,8 @@ ==================================================================== */ package org.apache.poi.stress; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.File; import java.io.FileInputStream; @@ -27,7 +27,7 @@ import org.apache.poi.extractor.Extracto import org.apache.poi.sl.extractor.SlideShowExtractor; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlideShow; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class XSLFFileHandler extends SlideShowHandler { @Override @@ -64,7 +64,7 @@ public class XSLFFileHandler extends Sli extractor.setNotesByDefault(false); extractor.setMasterByDefault(false); - assertEquals("With all options disabled we should not get text", "", extractor.getText()); + assertEquals("", extractor.getText(), "With all options disabled we should not get text"); } } Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java Thu Dec 24 18:42:29 2020 @@ -24,7 +24,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.XLSBUnsupportedException; import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class XSSFBFileHandler extends AbstractFileHandler { Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Thu Dec 24 18:42:29 2020 @@ -16,10 +16,10 @@ ==================================================================== */ package org.apache.poi.stress; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -54,7 +54,7 @@ import org.apache.poi.xssf.eventusermode import org.apache.poi.xssf.extractor.XSSFExportToXml; import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; public class XSSFFileHandler extends SpreadsheetHandler { @@ -78,7 +78,7 @@ public class XSSFFileHandler extends Spr Decryptor dec = ei.getDecryptor(); try { boolean b = dec.verifyPassword(pass); - assertTrue("password mismatch", b); + assertTrue( b, "password mismatch" ); } catch (EncryptedDocumentException e) { String msg = "Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files"; assumeFalse(msg.equals(e.getMessage())); @@ -190,8 +190,7 @@ public class XSSFFileHandler extends Spr XLSX2CSV.main(new String[]{file.getAbsolutePath()}); ExcelComparator.main(new String[]{file.getAbsolutePath(), file.getAbsolutePath()}); - assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", - EXPECTED_ADDITIONAL_FAILURES.contains(testFile)); + assertFalse( EXPECTED_ADDITIONAL_FAILURES.contains(testFile), "Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!" ); } catch (OLE2NotOfficeXmlFileException e) { // we have some files that are not actually OOXML and thus cannot be tested here Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java (original) +++ poi/trunk/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java Thu Dec 24 18:42:29 2020 @@ -22,7 +22,7 @@ import java.io.FileInputStream; import java.io.InputStream; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class XWPFFileHandler extends AbstractFileHandler { @Override Modified: poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java (original) +++ poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Thu Dec 24 18:42:29 2020 @@ -17,6 +17,7 @@ package org.apache.poi.poifs.nio; +import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -35,7 +36,7 @@ import org.apache.poi.util.POILogger; /** * A POIFS {@link DataSource} backed by a File */ -public class FileBackedDataSource extends DataSource { +public class FileBackedDataSource extends DataSource implements Closeable { private final static POILogger logger = POILogFactory.getLogger(FileBackedDataSource.class); private final FileChannel channel; Modified: poi/trunk/src/java/org/apache/poi/ss/formula/atp/DateParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/atp/DateParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/ss/formula/atp/DateParser.java (original) +++ poi/trunk/src/java/org/apache/poi/ss/formula/atp/DateParser.java Thu Dec 24 18:42:29 2020 @@ -17,80 +17,13 @@ package org.apache.poi.ss.formula.atp; -import java.util.Calendar; -import java.util.regex.Pattern; - -import org.apache.poi.ss.formula.eval.ErrorEval; -import org.apache.poi.ss.formula.eval.EvaluationException; -import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.Removal; /** * Parser for java dates. + * @deprecated in 5.0.0 - use {@link org.apache.poi.ss.util.DateParser} */ -public class DateParser { - private DateParser() { - // enforcing singleton - } - - /** - * Parses a date from a string. - * - * @param strVal a string with a date pattern. - * @return a date parsed from argument. - * @throws EvaluationException exception upon parsing. - */ - public static Calendar parseDate(String strVal) throws EvaluationException { - String[] parts = Pattern.compile("/").split(strVal); - if (parts.length != 3) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - String part2 = parts[2]; - int spacePos = part2.indexOf(' '); - if (spacePos > 0) { - // drop time portion if present - part2 = part2.substring(0, spacePos); - } - int f0; - int f1; - int f2; - try { - f0 = Integer.parseInt(parts[0]); - f1 = Integer.parseInt(parts[1]); - f2 = Integer.parseInt(part2); - } catch (NumberFormatException e) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - if (f0 < 0 || f1 < 0 || f2 < 0 || (f0 > 12 && f1 > 12 && f2 > 12)) { - // easy to see this cannot be a valid date - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - - if (f0 >= 1900 && f0 < 9999) { - // when 4 digit value appears first, the format is YYYY/MM/DD, regardless of OS settings - return makeDate(f0, f1, f2); - } - // otherwise the format seems to depend on OS settings (default date format) -// if (false) { -// // MM/DD/YYYY is probably a good guess, if the in the US -// return makeDate(f2, f0, f1); -// } - // TODO - find a way to choose the correct date format - throw new RuntimeException("Unable to determine date format for text '" + strVal + "'"); - } - - /** - * @param month 1-based - */ - private static Calendar makeDate(int year, int month, int day) throws EvaluationException { - if (month < 1 || month > 12) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - Calendar cal = LocaleUtil.getLocaleCalendar(year, month - 1, 1, 0, 0, 0); - if (day < 1 || day > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - cal.set(Calendar.DAY_OF_MONTH, day); - return cal; - } - +@Removal(version = "6.0.0") +@Deprecated +public class DateParser extends org.apache.poi.ss.util.DateParser { } Modified: poi/trunk/src/java/org/apache/poi/ss/util/DateParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/DateParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/ss/util/DateParser.java (original) +++ poi/trunk/src/java/org/apache/poi/ss/util/DateParser.java Thu Dec 24 18:42:29 2020 @@ -35,7 +35,7 @@ import org.apache.poi.util.LocaleUtil; * Parser for java dates. */ public class DateParser { - private DateParser() { + protected DateParser() { // enforcing singleton } Modified: poi/trunk/src/multimodule/excelant/test9/module-info.class URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/excelant/test9/module-info.class?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== Binary files - no diff available. Modified: poi/trunk/src/multimodule/excelant/test9/module-info.java URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/excelant/test9/module-info.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/multimodule/excelant/test9/module-info.java (original) +++ poi/trunk/src/multimodule/excelant/test9/module-info.java Thu Dec 24 18:42:29 2020 @@ -25,4 +25,8 @@ module org.apache.poi.excelant { exports org.apache.poi.ss.excelant.util; opens org.apache.poi.ss.excelant; + + // test specific exports + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; } \ No newline at end of file Modified: poi/trunk/src/multimodule/integration/java9/module-info.java URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/integration/java9/module-info.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/multimodule/integration/java9/module-info.java (original) +++ poi/trunk/src/multimodule/integration/java9/module-info.java Thu Dec 24 18:42:29 2020 @@ -16,12 +16,12 @@ ==================================================================== */ module org.apache.poi.stress { - requires junit; + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; requires net.bytebuddy; requires java.desktop; requires org.apache.poi.examples; exports org.apache.poi.stress; - } \ No newline at end of file Modified: poi/trunk/src/multimodule/ooxml/test9/module-info.class URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/ooxml/test9/module-info.class?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== Binary files - no diff available. Modified: poi/trunk/src/multimodule/ooxml/test9/module-info.java URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/ooxml/test9/module-info.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/multimodule/ooxml/test9/module-info.java (original) +++ poi/trunk/src/multimodule/ooxml/test9/module-info.java Thu Dec 24 18:42:29 2020 @@ -98,28 +98,29 @@ module org.apache.poi.ooxml { // test specific exports - requires junit; + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; requires com.google.common; - exports org.apache.poi.extractor.ooxml to junit; - exports org.apache.poi.openxml4j.opc.compliance to junit; - exports org.apache.poi.poifs.crypt.tests to junit; - exports org.apache.poi.sl.tests to junit; - exports org.apache.poi.sl.tests.draw to junit; - exports org.apache.poi.ss.tests to junit; - exports org.apache.poi.ss.tests.extractor to junit; - exports org.apache.poi.ss.tests.format to junit; - exports org.apache.poi.ss.tests.formula to junit; - exports org.apache.poi.ss.tests.formula.eval to junit; - exports org.apache.poi.ss.tests.formula.functions to junit; - exports org.apache.poi.ss.tests.usermodel to junit; - exports org.apache.poi.ss.tests.util to junit; - exports org.apache.poi.util.tests to junit; - exports org.apache.poi.xslf to junit; - exports org.apache.poi.xslf.extractor to junit; - exports org.apache.poi.xssf.io to junit; - exports org.apache.poi.xssf.usermodel.charts to junit; - exports org.apache.poi.xwpf to junit; + exports org.apache.poi.extractor.ooxml to org.junit.platform.commons; + exports org.apache.poi.openxml4j.opc.compliance to org.junit.platform.commons; + exports org.apache.poi.poifs.crypt.tests to org.junit.platform.commons; + exports org.apache.poi.sl.tests to org.junit.platform.commons; + exports org.apache.poi.sl.tests.draw to org.junit.platform.commons; + exports org.apache.poi.ss.tests to org.junit.platform.commons; + exports org.apache.poi.ss.tests.extractor to org.junit.platform.commons; + exports org.apache.poi.ss.tests.format to org.junit.platform.commons; + exports org.apache.poi.ss.tests.formula to org.junit.platform.commons; + exports org.apache.poi.ss.tests.formula.eval to org.junit.platform.commons; + exports org.apache.poi.ss.tests.formula.functions to org.junit.platform.commons; + exports org.apache.poi.ss.tests.usermodel to org.junit.platform.commons; + exports org.apache.poi.ss.tests.util to org.junit.platform.commons; + exports org.apache.poi.util.tests to org.junit.platform.commons; + exports org.apache.poi.xslf to org.junit.platform.commons; + exports org.apache.poi.xslf.extractor to org.junit.platform.commons; + exports org.apache.poi.xssf.io to org.junit.platform.commons; + exports org.apache.poi.xssf.usermodel.charts to org.junit.platform.commons; + exports org.apache.poi.xwpf to org.junit.platform.commons; } \ No newline at end of file Modified: poi/trunk/src/multimodule/poi/java9/module-info.class URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/poi/java9/module-info.class?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== Binary files - no diff available. Modified: poi/trunk/src/multimodule/poi/test9/module-info.class URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/poi/test9/module-info.class?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== Binary files - no diff available. Modified: poi/trunk/src/multimodule/poi/test9/module-info.java URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/poi/test9/module-info.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/multimodule/poi/test9/module-info.java (original) +++ poi/trunk/src/multimodule/poi/test9/module-info.java Thu Dec 24 18:42:29 2020 @@ -103,8 +103,11 @@ module org.apache.poi.poi { exports org.apache.poi.wp.usermodel; // test specific exports - requires junit; requires net.bytebuddy; - opens org.apache.poi.hpsf.basic to junit; - opens org.apache.poi.hssf.record.pivot to junit; + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; + + opens org.apache.poi.hpsf.basic to org.junit.platform.commons; + opens org.apache.poi.hssf.record.pivot to org.junit.platform.commons; + opens org.apache.poi.hssf.dev to org.junit.platform.commons; } \ No newline at end of file Modified: poi/trunk/src/multimodule/scratchpad/test9/module-info.class URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/scratchpad/test9/module-info.class?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== Binary files - no diff available. Modified: poi/trunk/src/multimodule/scratchpad/test9/module-info.java URL: http://svn.apache.org/viewvc/poi/trunk/src/multimodule/scratchpad/test9/module-info.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/multimodule/scratchpad/test9/module-info.java (original) +++ poi/trunk/src/multimodule/scratchpad/test9/module-info.java Thu Dec 24 18:42:29 2020 @@ -76,13 +76,14 @@ module org.apache.poi.scratchpad { // test specific exports - requires junit; + requires org.junit.jupiter.api; + requires org.junit.jupiter.params; requires org.mockito; - exports org.apache.poi.hemf.hemfplus.extractor to junit; - exports org.apache.poi.hslf to junit; - exports org.apache.poi.hwmf to junit; - exports org.apache.poi.hwpf.util to junit; + exports org.apache.poi.hemf.hemfplus.extractor to org.junit.platform.commons; + exports org.apache.poi.hslf to org.junit.platform.commons; + exports org.apache.poi.hwmf to org.junit.platform.commons; + exports org.apache.poi.hwpf.util to org.junit.platform.commons; opens org.apache.poi.hwpf.model to org.mockito; opens org.apache.poi.hwpf.model.types to org.mockito; Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java Thu Dec 24 18:42:29 2020 @@ -17,13 +17,12 @@ package org.apache.poi.extractor.ooxml; import static org.apache.poi.POITestCase.assertContains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileInputStream; @@ -31,7 +30,6 @@ import java.io.IOException; import java.util.Locale; import org.apache.poi.POIDataSamples; -import org.apache.poi.UnsupportedFileFormatException; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.POIOLE2TextExtractor; import org.apache.poi.extractor.POITextExtractor; @@ -39,6 +37,7 @@ import org.apache.poi.hssf.HSSFTestDataS import org.apache.poi.hssf.extractor.EventBasedExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.ooxml.extractor.POIXMLExtractorFactory; +import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; @@ -47,7 +46,7 @@ import org.apache.poi.poifs.filesystem.P import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.xmlbeans.XmlException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test that the extractor factory plays nicely @@ -86,17 +85,17 @@ public class TestExtractorFactory { private static final File vsd = getFileAndCheck(dgTests, "Test_Visio-Some_Random_Text.vsd"); private static final File vsdx = getFileAndCheck(dgTests, "test.vsdx"); - private static POIDataSamples pubTests = POIDataSamples.getPublisherInstance(); - private static File pub = getFileAndCheck(pubTests, "Simple.pub"); + private static final POIDataSamples pubTests = POIDataSamples.getPublisherInstance(); + private static final File pub = getFileAndCheck(pubTests, "Simple.pub"); private static final POIXMLExtractorFactory xmlFactory = new POIXMLExtractorFactory(); private static File getFileAndCheck(POIDataSamples samples, String name) { File file = samples.getFile(name); - assertNotNull("Did not get a file for " + name, file); - assertTrue("Did not get a type file for " + name, file.isFile()); - assertTrue("File did not exist: " + name, file.exists()); + assertNotNull(file, "Did not get a file for " + name); + assertTrue(file.isFile(), "Did not get a type file for " + name); + assertTrue(file.exists(), "File did not exist: " + name); return file; } @@ -127,6 +126,7 @@ public class TestExtractorFactory { R apply(T t) throws IOException, OpenXML4JException, XmlException; } + @SuppressWarnings("ConstantConditions") @Test public void testFile() throws Exception { for (int i = 0; i < TEST_SET.length; i += 4) { @@ -172,6 +172,7 @@ public class TestExtractorFactory { assertTrue(ex.getMessage().contains("Invalid header signature; read 0x3D20726F68747541, expected 0xE11AB1A1E011CFD0")); } + @SuppressWarnings("ConstantConditions") private void testStream(final FunctionEx<FileInputStream, POITextExtractor> poifsIS, final boolean loadOOXML) throws IOException, OpenXML4JException, XmlException { for (int i = 0; i < TEST_SET.length; i += 4) { @@ -182,22 +183,21 @@ public class TestExtractorFactory { try (FileInputStream fis = new FileInputStream(testFile); POITextExtractor ext = poifsIS.apply(fis)) { testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]); - } catch (IllegalArgumentException e) { - fail("failed to process "+testFile); } } } private void testExtractor(final POITextExtractor ext, final String testcase, final String extrClass, final Integer minLength) { - assertEquals("invalid extractor for " + testcase, extrClass, ext.getClass().getSimpleName()); + assertEquals(extrClass, ext.getClass().getSimpleName(), "invalid extractor for " + testcase); final String actual = ext.getText(); if (minLength == -1) { assertContains(actual.toLowerCase(Locale.ROOT), "test"); } else { - assertTrue("extracted content too short for " + testcase, actual.length() > minLength); + assertTrue(actual.length() > minLength, "extracted content too short for " + testcase); } } + @SuppressWarnings("ConstantConditions") @Test public void testPackage() throws Exception { for (int i = 0; i < TEST_SET.length; i += 4) { @@ -208,19 +208,17 @@ public class TestExtractorFactory { try (final OPCPackage pkg = OPCPackage.open(testFile, PackageAccess.READ); final POITextExtractor ext = xmlFactory.create(pkg)) { + assertNotNull(ext); testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]); pkg.revert(); } } } - @Test(expected = UnsupportedFileFormatException.class) - public void testPackageInvalid() throws Exception { + @Test + public void testPackageInvalid() { // Text - try (final OPCPackage pkg = OPCPackage.open(txt, PackageAccess.READ); - final POITextExtractor ignored = xmlFactory.create(pkg)) { - fail("extracting from invalid package"); - } + assertThrows(NotOfficeXmlFileException.class, () -> OPCPackage.open(txt, PackageAccess.READ)); } @Test @@ -334,7 +332,7 @@ public class TestExtractorFactory { final String actual = embeds.length+"-"+numWord+"-"+numXls+"-"+numPpt+"-"+numMsg+"-"+numWordX; final String expected = (String)testObj[i+2]; - assertEquals("invalid number of embeddings - "+testObj[i], expected, actual); + assertEquals(expected, actual, "invalid number of embeddings - "+testObj[i]); } } @@ -445,28 +443,31 @@ public class TestExtractorFactory { * #59074 - Excel 95 files should give a helpful message, not just * "No supported documents found in the OLE2 stream" */ + @Test public void bug59074() throws Exception { try (POITextExtractor extractor = ExtractorFactory.createExtractor(POIDataSamples.getSpreadSheetInstance().getFile("59074.xls"))) { String text = extractor.getText(); - assertContains(text, "testdoc"); + assertContains(text, "Exotic warrant"); } } - @Test(expected = IllegalStateException.class) - public void testGetEmbeddedFromXMLExtractor() throws IOException { + @Test + public void testGetEmbeddedFromXMLExtractor() { // currently not implemented - ExtractorFactory.getEmbeddedDocsTextExtractors(null); + assertThrows(IllegalStateException.class, () -> ExtractorFactory.getEmbeddedDocsTextExtractors(null)); } // This bug is currently open. This test will fail with "expected error not thrown" when the bug has been fixed. // When this happens, change this from @Test(expected=...) to @Test // bug 45565: text within TextBoxes is extracted by ExcelExtractor and WordExtractor - @Test(expected=AssertionError.class) + @Test public void test45565() throws Exception { try (POITextExtractor extractor = ExtractorFactory.createExtractor(HSSFTestDataSamples.getSampleFile("45565.xls"))) { String text = extractor.getText(); - assertContains(text, "testdoc"); - assertContains(text, "test phrase"); + assertThrows(AssertionError.class, () -> { + assertContains(text, "testdoc"); + assertContains(text, "test phrase"); + }); } } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestDetectAsOOXML.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestDetectAsOOXML.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestDetectAsOOXML.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestDetectAsOOXML.java Thu Dec 24 18:42:29 2020 @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.ooxml; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -30,7 +30,7 @@ import org.apache.poi.openxml4j.opc.OPCP import org.apache.poi.poifs.filesystem.DocumentFactoryHelper; import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.util.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test that HXF correctly detects OOXML @@ -52,15 +52,14 @@ public class TestDetectAsOOXML { }; for (Object[] fm : fileAndMagic) { - InputStream is = HSSFTestDataSamples.openSampleFileStream((String)fm[0]); - is = FileMagic.prepareToCheckMagic(is); - FileMagic act = FileMagic.valueOf(is); + try (InputStream is = FileMagic.prepareToCheckMagic(HSSFTestDataSamples.openSampleFileStream((String)fm[0]))) { + FileMagic act = FileMagic.valueOf(is); - assertEquals("OOXML files should be detected, others not", - act == FileMagic.OOXML, DocumentFactoryHelper.hasOOXMLHeader(is)); + assertEquals(act == FileMagic.OOXML, DocumentFactoryHelper.hasOOXMLHeader(is), + "OOXML files should be detected, others not"); - assertEquals("file magic failed for "+fm[0], fm[1], act); - is.close(); + assertEquals(fm[1], act, "file magic failed for " + fm[0]); + } } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestEmbedded.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestEmbedded.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestEmbedded.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestEmbedded.java Thu Dec 24 18:42:29 2020 @@ -19,9 +19,9 @@ package org.apache.poi.ooxml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -30,7 +30,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test that we handle embeded bits in OOXML files properly Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java Thu Dec 24 18:42:29 2020 @@ -17,13 +17,17 @@ package org.apache.poi.ooxml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -47,7 +51,8 @@ import org.apache.poi.util.TempFile; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xwpf.usermodel.XWPFRelation; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; /** * Test recursive read and write of OPC packages @@ -110,110 +115,88 @@ public final class TestPOIXMLDocument { traverse(p, context); } else { POIXMLDocumentPart prev = context.get(uri); - assertSame("Duplicate POIXMLDocumentPart instance for targetURI=" + uri, prev, p.getDocumentPart()); + assertSame(prev, p.getDocumentPart(), "Duplicate POIXMLDocumentPart instance for targetURI=" + uri); } } } - public void assertReadWrite(OPCPackage pkg1) throws Exception { + private void assertReadWrite(POIDataSamples samples, String filename) throws Exception { + try (InputStream is = samples.openResourceAsStream(filename); + OPCPackage pkg1 = PackageHelper.open(is)){ + File tmp = TempFile.createTempFile("poi-ooxml", ".tmp"); + try (FileOutputStream out = new FileOutputStream(tmp); + OPCParser doc = new OPCParser(pkg1)) { + doc.parse(new TestFactory()); + traverse(doc); + doc.write(out); + out.close(); + + // Should not be able to write to an output stream that has been closed + // FIXME: A better exception class (IOException?) and message should be raised + // indicating that the document could not be written because the output stream is closed. + // see {@link org.apache.poi.openxml4j.opc.ZipPackage#saveImpl(java.io.OutputStream)} + OpenXML4JRuntimeException e = assertThrows(OpenXML4JRuntimeException.class, () -> doc.write(out), + "Should not be able to write to an output stream that has been closed."); + assertTrue(e.getMessage().matches("Fail to save: an error occurs while saving the package : " + + "The part .+ failed to be saved in the stream with marshaller .+")); + + // Should not be able to write a document that has been closed + doc.close(); + IOException e2 = assertThrows(IOException.class, () -> doc.write(new NullOutputStream()), + "Should not be able to write a document that has been closed."); + assertEquals("Cannot write data, document seems to have been closed already", e2.getMessage()); - OPCParser doc = new OPCParser(pkg1); - doc.parse(new TestFactory()); - - traverse(doc); - - File tmp = TempFile.createTempFile("poi-ooxml", ".tmp"); - FileOutputStream out = new FileOutputStream(tmp); - doc.write(out); - out.close(); - - // Should not be able to write to an output stream that has been closed - try { - doc.write(out); - fail("Should not be able to write to an output stream that has been closed."); - } catch (final OpenXML4JRuntimeException e) { - // FIXME: A better exception class (IOException?) and message should be raised - // indicating that the document could not be written because the output stream is closed. - // see {@link org.apache.poi.openxml4j.opc.ZipPackage#saveImpl(java.io.OutputStream)} - if (e.getMessage().matches("Fail to save: an error occurs while saving the package : The part .+ failed to be saved in the stream with marshaller .+")) { - // expected - } else { - throw e; - } - } - - // Should not be able to write a document that has been closed - doc.close(); - try { - doc.write(new NullOutputStream()); - fail("Should not be able to write a document that has been closed."); - } catch (final IOException e) { - if (e.getMessage().equals("Cannot write data, document seems to have been closed already")) { - // expected - } else { - throw e; + // Should be able to close a document multiple times, though subsequent closes will have no effect. } - } - - // Should be able to close a document multiple times, though subsequent closes will have no effect. - doc.close(); - - - @SuppressWarnings("resource") - OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath()); - doc = new OPCParser(pkg1); - try { - doc.parse(new TestFactory()); - traverse(doc); - - assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size()); - ArrayList<PackagePart> l1 = pkg1.getParts(); - ArrayList<PackagePart> l2 = pkg2.getParts(); - assertEquals(l1.size(), l2.size()); - for (int i=0; i < l1.size(); i++){ - PackagePart p1 = l1.get(i); - PackagePart p2 = l2.get(i); - - assertEquals(p1.getContentType(), p2.getContentType()); - assertEquals(p1.hasRelationships(), p2.hasRelationships()); - if(p1.hasRelationships()){ - assertEquals(p1.getRelationships().size(), p2.getRelationships().size()); + try (OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath()); + OPCParser doc = new OPCParser(pkg1)) { + doc.parse(new TestFactory()); + traverse(doc); + + assertEquals(pkg1.getRelationships().size(), pkg2.getRelationships().size()); + + ArrayList<PackagePart> l1 = pkg1.getParts(); + ArrayList<PackagePart> l2 = pkg2.getParts(); + + assertEquals(l1.size(), l2.size()); + for (int i = 0; i < l1.size(); i++) { + PackagePart p1 = l1.get(i); + PackagePart p2 = l2.get(i); + + assertEquals(p1.getContentType(), p2.getContentType()); + assertEquals(p1.hasRelationships(), p2.hasRelationships()); + if (p1.hasRelationships()) { + assertEquals(p1.getRelationships().size(), p2.getRelationships().size()); + } + assertEquals(p1.getPartName(), p2.getPartName()); } - assertEquals(p1.getPartName(), p2.getPartName()); } - } finally { - doc.close(); - pkg1.close(); - pkg2.close(); } } @Test public void testPPTX() throws Exception { - POIDataSamples pds = POIDataSamples.getSlideShowInstance(); - assertReadWrite(PackageHelper.open(pds.openResourceAsStream("PPTWithAttachments.pptm"))); + assertReadWrite(POIDataSamples.getSlideShowInstance(), "PPTWithAttachments.pptm"); } @Test public void testXLSX() throws Exception { - POIDataSamples pds = POIDataSamples.getSpreadSheetInstance(); - assertReadWrite(PackageHelper.open(pds.openResourceAsStream("ExcelWithAttachments.xlsm"))); + assertReadWrite(POIDataSamples.getSpreadSheetInstance(), "ExcelWithAttachments.xlsm"); } @Test public void testDOCX() throws Exception { - POIDataSamples pds = POIDataSamples.getDocumentInstance(); - assertReadWrite(PackageHelper.open(pds.openResourceAsStream("WordWithAttachments.docx"))); + assertReadWrite(POIDataSamples.getDocumentInstance(), "WordWithAttachments.docx"); } @Test public void testRelationOrder() throws Exception { POIDataSamples pds = POIDataSamples.getDocumentInstance(); - @SuppressWarnings("resource") - OPCPackage pkg = PackageHelper.open(pds.openResourceAsStream("WordWithAttachments.docx")); - try (OPCParser doc = new OPCParser(pkg)) { + try (InputStream is = pds.openResourceAsStream("WordWithAttachments.docx"); + OPCPackage pkg = PackageHelper.open(is); + OPCParser doc = new OPCParser(pkg)) { doc.parse(new TestFactory()); for (POIXMLDocumentPart rel : doc.getRelations()) { @@ -226,9 +209,9 @@ public final class TestPOIXMLDocument { @Test public void testGetNextPartNumber() throws Exception { POIDataSamples pds = POIDataSamples.getDocumentInstance(); - @SuppressWarnings("resource") - OPCPackage pkg = PackageHelper.open(pds.openResourceAsStream("WordWithAttachments.docx")); - try (OPCParser doc = new OPCParser(pkg)) { + try (InputStream is = pds.openResourceAsStream("WordWithAttachments.docx"); + OPCPackage pkg = PackageHelper.open(is); + OPCParser doc = new OPCParser(pkg)) { doc.parse(new TestFactory()); // Non-indexed parts: Word is taken, Excel is not @@ -272,34 +255,32 @@ public final class TestPOIXMLDocument { @Test public void testVSDX() throws Exception { POIDataSamples pds = POIDataSamples.getDiagramInstance(); - @SuppressWarnings("resource") - OPCPackage open = PackageHelper.open(pds.openResourceAsStream("test.vsdx")); - POIXMLDocument part = new OPCParser(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT); - - assertNotNull(part); - assertEquals(0, part.getRelationCounter()); - part.close(); + try (InputStream is = pds.openResourceAsStream("test.vsdx"); + OPCPackage open = PackageHelper.open(is); + POIXMLDocument part = new OPCParser(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT)) { + assertNotNull(part); + assertEquals(0, part.getRelationCounter()); + } } @Test public void testVSDXPart() throws IOException { POIDataSamples pds = POIDataSamples.getDiagramInstance(); - OPCPackage open = PackageHelper.open(pds.openResourceAsStream("test.vsdx")); + try (InputStream is = pds.openResourceAsStream("test.vsdx"); + OPCPackage open = PackageHelper.open(is)) { - POIXMLDocumentPart part = new POIXMLDocumentPart(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT); + POIXMLDocumentPart part = new POIXMLDocumentPart(open, PackageRelationshipTypes.VISIO_CORE_DOCUMENT); - assertNotNull(part); - assertEquals(0, part.getRelationCounter()); - - open.close(); + assertNotNull(part); + assertEquals(0, part.getRelationCounter()); + } } - @Test(expected=POIXMLException.class) + @Test public void testInvalidCoreRel() throws IOException { POIDataSamples pds = POIDataSamples.getDiagramInstance(); - try (OPCPackage open = PackageHelper.open(pds.openResourceAsStream("test.vsdx"))) { - new POIXMLDocumentPart(open, "somethingillegal"); + assertThrows(POIXMLException.class, () -> new POIXMLDocumentPart(open, "somethingillegal")); } } @@ -316,23 +297,20 @@ public final class TestPOIXMLDocument { } @Test - public void testOSGIClassLoading() { + public void testOSGIClassLoading() throws IOException { + byte[] data; + try (InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx")) { + data = IOUtils.toByteArray(is); + } + // the schema type loader is cached per thread in POIXMLTypeLoader. // So create a new Thread and change the context class loader (which would normally be used) // to not contain the OOXML classes - Runnable run = () -> { - InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx"); - XMLSlideShow ppt = null; - try { - ppt = new XMLSlideShow(is); - ppt.getSlides().get(0).getShapes(); - } catch (IOException e) { - fail("failed to load XMLSlideShow"); - } finally { - IOUtils.closeQuietly(ppt); - IOUtils.closeQuietly(is); - } - }; + Runnable run = () -> assertDoesNotThrow(() -> { + try (XMLSlideShow ppt = new XMLSlideShow(new ByteArrayInputStream(data))) { + assertNotNull(ppt.getSlides().get(0).getShapes()); + }} + ); ClassLoader cl = getClass().getClassLoader(); UncaughtHandler uh = new UncaughtHandler(); @@ -347,14 +325,10 @@ public final class TestPOIXMLDocument { ta[i].start(); } for (Thread thread : ta) { - try { - thread.join(); - } catch (InterruptedException e) { - fail("failed to join thread"); - } + assertDoesNotThrow((Executable) thread::join, "failed to join thread"); } } - assertFalse("Should not have an exception now, but had " + uh.e, uh.hasException()); + assertFalse(uh.hasException(), "Should not have an exception now, but had " + uh.e); } private static class UncaughtHandler implements UncaughtExceptionHandler { @@ -362,7 +336,6 @@ public final class TestPOIXMLDocument { public synchronized void uncaughtException(Thread t, Throwable e) { this.e = e; - } public synchronized boolean hasException() { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java Thu Dec 24 18:42:29 2020 @@ -17,36 +17,33 @@ package org.apache.poi.ooxml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; -import java.io.File; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.Optional; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Test setting extended and custom OOXML properties @@ -57,7 +54,7 @@ public final class TestPOIXMLProperties private POIXMLProperties _props; private CoreProperties _coreProperties; - @Before + @BeforeEach public void setUp() throws IOException { sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx"); sampleNoThumb = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); @@ -68,7 +65,7 @@ public final class TestPOIXMLProperties assertNotNull(_props); } - @After + @AfterEach public void closeResources() throws Exception { sampleDoc.close(); sampleNoThumb.close(); @@ -158,53 +155,48 @@ public final class TestPOIXMLProperties */ @Test public void testCustomProperties() throws Exception { - POIXMLDocument wb1 = new XSSFWorkbook(); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { - POIXMLProperties.CustomProperties customProps = wb1.getProperties().getCustomProperties(); - customProps.addProperty("test-1", "string val"); - customProps.addProperty("test-2", 1974); - customProps.addProperty("test-3", 36.6); - //adding a duplicate - try { + POIXMLProperties.CustomProperties customProps = wb1.getProperties().getCustomProperties(); + customProps.addProperty("test-1", "string val"); + customProps.addProperty("test-2", 1974); customProps.addProperty("test-3", 36.6); - fail("expected exception"); - } catch(IllegalArgumentException e){ + //adding a duplicate + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> customProps.addProperty("test-3", 36.6)); assertEquals("A property with this name already exists in the custom properties", e.getMessage()); - } - customProps.addProperty("test-4", true); + customProps.addProperty("test-4", true); - POIXMLDocument wb2 = XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)wb1); - wb1.close(); - org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties ctProps = - wb2.getProperties().getCustomProperties().getUnderlyingProperties(); - assertEquals(4, ctProps.sizeOfPropertyArray()); - org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty p; - - p = ctProps.getPropertyArray(0); - assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); - assertEquals("test-1", p.getName()); - assertEquals("string val", p.getLpwstr()); - assertEquals(2, p.getPid()); - - p = ctProps.getPropertyArray(1); - assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); - assertEquals("test-2", p.getName()); - assertEquals(1974, p.getI4()); - assertEquals(3, p.getPid()); - - p = ctProps.getPropertyArray(2); - assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); - assertEquals("test-3", p.getName()); - assertEquals(36.6, p.getR8(), 0); - assertEquals(4, p.getPid()); - - p = ctProps.getPropertyArray(3); - assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); - assertEquals("test-4", p.getName()); - assertTrue(p.getBool()); - assertEquals(5, p.getPid()); - - wb2.close(); + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1)) { + org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties ctProps = + wb2.getProperties().getCustomProperties().getUnderlyingProperties(); + assertEquals(4, ctProps.sizeOfPropertyArray()); + org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty p; + + p = ctProps.getPropertyArray(0); + assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); + assertEquals("test-1", p.getName()); + assertEquals("string val", p.getLpwstr()); + assertEquals(2, p.getPid()); + + p = ctProps.getPropertyArray(1); + assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); + assertEquals("test-2", p.getName()); + assertEquals(1974, p.getI4()); + assertEquals(3, p.getPid()); + + p = ctProps.getPropertyArray(2); + assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); + assertEquals("test-3", p.getName()); + assertEquals(36.6, p.getR8(), 0); + assertEquals(4, p.getPid()); + + p = ctProps.getPropertyArray(3); + assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid()); + assertEquals("test-4", p.getName()); + assertTrue(p.getBool()); + assertEquals(5, p.getPid()); + } + } } @Test @@ -246,7 +238,7 @@ public final class TestPOIXMLProperties @Test public void testGetSetRevision() { String revision = _coreProperties.getRevision(); - assertTrue("Revision number is 1", Integer.parseInt(revision) > 1); + assertTrue(Integer.parseInt(revision) > 1, "Revision number is 1"); _coreProperties.setRevision("20"); assertEquals("20", _coreProperties.getRevision()); _coreProperties.setRevision("20xx"); @@ -264,17 +256,17 @@ public final class TestPOIXMLProperties public static boolean dateTimeEqualToUTCString(Date dateTime, String utcString) { Calendar utcCalendar = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC); utcCalendar.setTimeInMillis(dateTime.getTime()); - String dateTimeUtcString = utcCalendar.get(Calendar.YEAR) + "-" + - zeroPad((utcCalendar.get(Calendar.MONTH)+1)) + "-" + - zeroPad(utcCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + + String dateTimeUtcString = utcCalendar.get(Calendar.YEAR) + "-" + + zeroPad((utcCalendar.get(Calendar.MONTH)+1)) + "-" + + zeroPad(utcCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + zeroPad(utcCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + - zeroPad(utcCalendar.get(Calendar.MINUTE)) + ":" + + zeroPad(utcCalendar.get(Calendar.MINUTE)) + ":" + zeroPad(utcCalendar.get(Calendar.SECOND)) + "Z"; return utcString.equals(dateTimeUtcString); } - @Ignore("Fails to add some of the thumbnails, needs more investigation") + @Disabled("Fails to add some of the thumbnails, needs more investigation") @Test public void testThumbnails() throws Exception { POIXMLProperties noThumbProps = sampleNoThumb.getProperties(); @@ -329,7 +321,7 @@ public final class TestPOIXMLProperties @Test public void testBug60977() throws IOException { - + try (final XSSFWorkbook workbook = new XSSFWorkbook()) { final Sheet sheet = workbook.createSheet("sheet"); final Row row = sheet.createRow(0); @@ -346,24 +338,24 @@ public final class TestPOIXMLProperties XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook); assertNotNull(wbBack); // properties documents are read lazily, so we have to access them to verify they parse properly - assertNotNull("First writeOutAndReadBack", wbBack.getProperties()); - assertEquals("First prop check", propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr()); + assertNotNull(wbBack.getProperties(), "First writeOutAndReadBack"); + assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr(), "First prop check"); customProperties.addProperty(propName + "1", propValue); wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook); assertNotNull(wbBack); // properties documents are read lazily, so we have to access them to verify they parse properly - assertNotNull("Second writeOutAndReadBack", wbBack.getProperties()); - assertEquals("Second prop check", propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr()); - assertEquals("Second prop check1", propValue, wbBack.getProperties().getCustomProperties().getProperty(propName + "1").getLpwstr()); + assertNotNull(wbBack.getProperties(), "Second writeOutAndReadBack"); + assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr(), "Second prop check"); + assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName + "1").getLpwstr(), "Second prop check1"); wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook); assertNotNull(wbBack); // properties documents are read lazily, so we have to access them to verify they parse properly - assertNotNull("Third writeOutAndReadBack", wbBack.getProperties()); - assertEquals("Third prop check", propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr()); - assertEquals("Third prop check1", propValue, wbBack.getProperties().getCustomProperties().getProperty(propName + "1").getLpwstr()); - + assertNotNull(wbBack.getProperties(), "Third writeOutAndReadBack"); + assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName).getLpwstr(), "Third prop check"); + assertEquals(propValue, wbBack.getProperties().getCustomProperties().getProperty(propName + "1").getLpwstr(), "Third prop check1"); + /* Manual test to write out the file more than once: File test1 = File.createTempFile("test1", ".xlsx", new File("C:\\temp")); File test2 = File.createTempFile("test2", ".xlsx", new File("C:\\temp")); @@ -379,7 +371,7 @@ public final class TestPOIXMLProperties try (final java.io.FileOutputStream fs = new java.io.FileOutputStream(test2)) { workbook.write(fs); } - + try (final XSSFWorkbook wb = new XSSFWorkbook(test2)) { assertNotNull(wb.getProperties()); } catch (InvalidFormatException e) { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ooxml; import static org.apache.poi.POITestCase.assertContains; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor; @@ -28,7 +28,7 @@ import org.apache.poi.openxml4j.opc.OPCP import org.apache.poi.xslf.usermodel.XSLFSlideShow; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestXMLPropertiesTextExtractor { private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,11 @@ package org.apache.poi.openxml4j.opc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.InputStream; @@ -30,7 +30,7 @@ import javax.xml.parsers.DocumentBuilder import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.internal.ContentType; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for content type (ContentType class). @@ -81,12 +81,8 @@ public final class TestContentType { "te{xt/xml", "tex}t/xml", "te xt/xml", "text" + (char) 9 + "/xml", "text xml", " text/xml "}; for (String contentType : contentTypesToTest) { - try { - new ContentType(contentType); - } catch (InvalidFormatException e) { - continue; - } - fail("Must have fail for content type: '" + contentType + "' !"); + assertThrows(InvalidFormatException.class, () -> new ContentType(contentType), + "Must have fail for content type: '" + contentType + "' !"); } } @@ -120,12 +116,8 @@ public final class TestContentType { "text/\u0080" // characters above ASCII are not allowed }; for (String contentType : contentTypesToTest) { - try { - new ContentType(contentType); - } catch (InvalidFormatException e) { - continue; - } - fail("Must have fail for content type: '" + contentType + "' !"); + assertThrows(InvalidFormatException.class, () -> new ContentType(contentType), + "Must have fail for content type: '" + contentType + "' !"); } } @@ -138,12 +130,8 @@ public final class TestContentType { public void testContentTypeCommentFailure() { String[] contentTypesToTest = new String[]{"text/xml(comment)"}; for (String contentType : contentTypesToTest) { - try { - new ContentType(contentType); - } catch (InvalidFormatException e) { - continue; - } - fail("Must have fail for content type: '" + contentType + "' !"); + assertThrows(InvalidFormatException.class, () -> new ContentType(contentType), + "Must have fail for content type: '" + contentType + "' !"); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestFileHelper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestFileHelper.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestFileHelper.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestFileHelper.java Thu Dec 24 18:42:29 2020 @@ -17,13 +17,13 @@ package org.apache.poi.openxml4j.opc; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.util.TreeMap; import org.apache.poi.openxml4j.opc.internal.FileHelper; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test TestFileHelper class. Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.openxml4j.opc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.io.InputStream; @@ -28,8 +28,8 @@ import org.apache.poi.openxml4j.OpenXML4 import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public final class TestListParts { private static final POILogger logger = POILogFactory.getLogger(TestListParts.class); @@ -38,7 +38,7 @@ public final class TestListParts { private TreeMap<PackagePartName, String> values; - @Before + @BeforeEach public void setUp() throws Exception { values = new TreeMap<>(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org