aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-12-24 18:42:29 +0000
commita0fa9e19b1196bc10034f15474d27ce23bf5865a (patch)
tree499c1eb427ebff72f7e447d13dd1de1552df8146 /src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
parentfb012041e8dd788637e68737199bc313b3e90098 (diff)
downloadpoi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.tar.gz
poi-a0fa9e19b1196bc10034f15474d27ce23bf5865a.zip
#65026 - Migrate tests to Junit 5
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java')
-rw-r--r--src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java89
1 files changed, 33 insertions, 56 deletions
diff --git a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
index f03bbf9127..ef4eec6417 100644
--- a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
+++ b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
@@ -16,26 +16,35 @@
==================================================================== */
package org.apache.poi.poifs.dev;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+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.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.property.PropertyTable;
import org.apache.poi.util.TempFile;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.io.*;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestPOIFSDump {
private static PrintStream SYSTEM;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM = System.out;
System.setOut(new PrintStream(new OutputStream() {
@@ -46,7 +55,7 @@ public class TestPOIFSDump {
}, false, "UTF-8"));
}
- @AfterClass
+ @AfterAll
public static void resetSystemOut() {
System.setOut(SYSTEM);
}
@@ -65,7 +74,7 @@ public class TestPOIFSDump {
"-dump-mini-stream",
};
- @After
+ @AfterEach
public void tearDown() throws IOException {
// clean up the directory that POIFSDump writes to
deleteDirectory(new File(new File(TEST_FILE+"_dump").getName()));
@@ -140,60 +149,28 @@ public class TestPOIFSDump {
}
}
@Test
- public void testInvalidFile() throws Exception {
- try {
- POIFSDump.main(new String[]{
- INVALID_FILE
- });
- fail("Should fail with an exception");
- } catch (NotOLE2FileException e) {
- // expected here
- }
-
- try {
- POIFSDump.main(new String[]{
- INVALID_XLSX_FILE
- });
- fail("Should fail with an exception");
- } catch (OfficeXmlFileException e) {
- // expected here
- }
+ public void testInvalidFile() {
+ assertThrows(NotOLE2FileException.class, () -> POIFSDump.main(new String[]{INVALID_FILE}));
+ assertThrows(OfficeXmlFileException.class, () -> POIFSDump.main(new String[]{INVALID_XLSX_FILE}));
for(String option : DUMP_OPTIONS) {
- try {
- POIFSDump.main(new String[]{
- option,
- INVALID_FILE
- });
- fail("Should fail with an exception");
- } catch (NotOLE2FileException e) {
- // expected here
- }
-
- try {
- POIFSDump.main(new String[]{
- option,
- INVALID_XLSX_FILE
- });
- fail("Should fail with an exception");
- } catch (OfficeXmlFileException e) {
- // expected here
- }
+ assertThrows(NotOLE2FileException.class, () -> POIFSDump.main(new String[]{option, INVALID_FILE}));
+ assertThrows(OfficeXmlFileException.class, () -> POIFSDump.main(new String[]{option, INVALID_XLSX_FILE}));
}
}
- @Ignore("Calls System.exit()")
+ @Disabled("Calls System.exit()")
@Test
public void testMainNoArgs() throws Exception {
POIFSDump.main(new String[] {});
}
- @Test(expected=IndexOutOfBoundsException.class)
+ @Test
public void testFailToWrite() throws IOException {
File dir = TempFile.createTempFile("TestPOIFSDump", ".tst");
- assertTrue("Had: " + dir, dir.exists());
- assertTrue("Had: " + dir, dir.delete());
- assertTrue("Had: " + dir, dir.mkdirs());
+ assertTrue(dir.exists(), "Had: " + dir);
+ assertTrue(dir.delete(), "Had: " + dir);
+ assertTrue(dir.mkdirs(), "Had: " + dir);
FileInputStream is = new FileInputStream(TEST_FILE);
POIFSFileSystem fs = new POIFSFileSystem(is);
@@ -204,6 +181,6 @@ public class TestPOIFSDump {
// try with an invalid startBlock to trigger an exception
// to validate that file-handles are closed properly
- POIFSDump.dump(fs, 999999999, "mini-stream", dir);
+ assertThrows(IndexOutOfBoundsException.class, () -> POIFSDump.dump(fs, 999999999, "mini-stream", dir));
}
} \ No newline at end of file