Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.poifs.filesystem; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -35,7 +35,7 @@ import java.util.stream.Stream; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.poifs.property.DirectoryProperty; import org.apache.poi.poifs.property.Property; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Verify the order of entries <code>DirectoryProperty</code> .
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java Thu Dec 24 18:42:29 2020 @@ -21,13 +21,13 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.StringUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; 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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.File; import java.io.FileInputStream; @@ -52,7 +52,7 @@ public class TestVBAMacroReader { } String testMacroContents = new String(bytes, StringUtil.UTF8); - + if (! testMacroContents.startsWith("Sub ")) { throw new IllegalArgumentException("Not a macro"); } @@ -73,7 +73,7 @@ public class TestVBAMacroReader { } expectedMacroContents = Collections.unmodifiableMap(_expectedMacroContents); } - + //////////////////////////////// From Stream ///////////////////////////// @Test public void HSSFFromStream() throws Exception { @@ -83,7 +83,7 @@ public class TestVBAMacroReader { public void XSSFFromStream() throws Exception { fromStream(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm"); } - @Ignore("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" + + @Disabled("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" + "for an example of how to get macros out of ppt. TODO: make integration across file formats more elegant") @Test public void HSLFFromStream() throws Exception { @@ -101,7 +101,7 @@ public class TestVBAMacroReader { public void XWPFFromStream() throws Exception { fromStream(POIDataSamples.getDocumentInstance(), "SimpleMacro.docm"); } - @Ignore("Found 0 macros") + @Disabled("Found 0 macros") @Test public void HDGFFromStream() throws Exception { fromStream(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd"); @@ -120,7 +120,7 @@ public class TestVBAMacroReader { public void XSSFFromFile() throws Exception { fromFile(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xlsm"); } - @Ignore("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" + + @Disabled("bug 59302: Found 0 macros; See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF()" + "for an example of how to get macros out of ppt. TODO: make integration across file formats more elegant") @Test public void HSLFFromFile() throws Exception { @@ -138,7 +138,7 @@ public class TestVBAMacroReader { public void XWPFFromFile() throws Exception { fromFile(POIDataSamples.getDocumentInstance(), "SimpleMacro.docm"); } - @Ignore("Found 0 macros") + @Disabled("Found 0 macros") @Test public void HDGFFromFile() throws Exception { fromFile(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd"); @@ -153,7 +153,7 @@ public class TestVBAMacroReader { public void HSSFFromPOIFS() throws Exception { fromPOIFS(POIDataSamples.getSpreadSheetInstance(), "SimpleMacro.xls"); } - @Ignore("bug 59302: Found 0 macros") + @Disabled("bug 59302: Found 0 macros") @Test public void HSLFFromPOIFS() throws Exception { fromPOIFS(POIDataSamples.getSlideShowInstance(), "SimpleMacro.ppt"); @@ -162,7 +162,7 @@ public class TestVBAMacroReader { public void HWPFFromPOIFS() throws Exception { fromPOIFS(POIDataSamples.getDocumentInstance(), "SimpleMacro.doc"); } - @Ignore("Found 0 macros") + @Disabled("Found 0 macros") @Test public void HDGFFromPOIFS() throws Exception { fromPOIFS(POIDataSamples.getDiagramInstance(), "SimpleMacro.vsd"); @@ -191,21 +191,21 @@ public class TestVBAMacroReader { } } } - + private void assertMacroContents(POIDataSamples samples, VBAMacroReader r) throws IOException { assertNotNull(r); Map<String,Module> contents = r.readMacroModules(); assertNotNull(contents); - assertFalse("Found 0 macros", contents.isEmpty()); + assertFalse(contents.isEmpty(), "Found 0 macros"); /* assertEquals(5, contents.size()); - + // Check the ones without scripts String[] noScripts = new String[] { "ThisWorkbook", "Sheet1", "Sheet2", "Sheet3" }; for (String entry : noScripts) { assertTrue(entry, contents.containsKey(entry)); - + String content = contents.get(entry); assertContains(content, "Attribute VB_Exposed = True"); assertContains(content, "Attribute VB_Customizable = True"); @@ -214,7 +214,7 @@ public class TestVBAMacroReader { assertContains(content, "Attribute VB_Exposed = True"); } */ - + // Check the script one assertContains(contents, "Module1"); Module module = contents.get("Module1"); Modified: poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java Thu Dec 24 18:42:29 2020 @@ -19,10 +19,10 @@ package org.apache.poi.poifs.nio; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileOutputStream; @@ -35,31 +35,25 @@ import java.nio.ByteBuffer; import org.apache.poi.POIDataSamples; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for the datasource implementations */ public class TestDataSource { - private static POIDataSamples data = POIDataSamples.getPOIFSInstance(); + private static final POIDataSamples data = POIDataSamples.getPOIFSInstance(); @Test public void testFile() throws Exception { File f = data.getFile("Notes.ole2"); - FileBackedDataSource ds = new FileBackedDataSource(f); - try { + try (FileBackedDataSource ds = new FileBackedDataSource(f)) { checkDataSource(ds, false); - } finally { - ds.close(); } // try a second time - ds = new FileBackedDataSource(f); - try { + try (FileBackedDataSource ds = new FileBackedDataSource(f)) { checkDataSource(ds, false); - } finally { - ds.close(); } } @@ -69,25 +63,19 @@ public class TestDataSource { try { writeDataToFile(temp); - FileBackedDataSource ds = new FileBackedDataSource(temp, false); - try { + try (FileBackedDataSource ds = new FileBackedDataSource(temp, false)) { checkDataSource(ds, true); - } finally { - ds.close(); } // try a second time - ds = new FileBackedDataSource(temp, false); - try { + try (FileBackedDataSource ds = new FileBackedDataSource(temp, false)) { checkDataSource(ds, true); - } finally { - ds.close(); } writeDataToFile(temp); } finally { assertTrue(temp.exists()); - assertTrue("Could not delete file " + temp, temp.delete()); + assertTrue(temp.delete(), "Could not delete file " + temp); } } @@ -98,25 +86,21 @@ public class TestDataSource { try { writeDataToFile(temp); - FileBackedDataSource ds = new FileBackedDataSource(temp, true); - try { + ; + try (FileBackedDataSource ds = new FileBackedDataSource(temp, true)) { ByteBuffer buf = ds.read(0, 10); assertNotNull(buf); buf = ds.read(8, 0x400); assertNotNull(buf); - } finally { - ds.close(); } // try a second time - ds = new FileBackedDataSource(temp, true); - try { + ; + try (FileBackedDataSource ds = new FileBackedDataSource(temp, true)) { ByteBuffer buf = ds.read(0, 10); assertNotNull(buf); buf = ds.read(8, 0x400); assertNotNull(buf); - } finally { - ds.close(); } writeDataToFile(temp); @@ -140,7 +124,7 @@ public class TestDataSource { // rewriting changes the size if (writeable) { - assertTrue("Had: " + ds.size(), ds.size() == 8192 || ds.size() == 8198); + assertTrue(ds.size() == 8192 || ds.size() == 8198, "Had: " + ds.size()); } else { assertEquals(8192, ds.size()); } @@ -174,21 +158,16 @@ public class TestDataSource { // Can go to the end, but not past it bs = ds.read(8, 8190); - assertEquals(0, bs.position()); // TODO How best to warn of a short read? + // TODO How best to warn of a short read? + assertEquals(0, bs.position()); // Can't go off the end - try { - ds.read(4, 8192); - if (!writeable) { - fail("Shouldn't be able to read off the end of the file"); - } - } catch (IndexOutOfBoundsException e) { - // expected here - } + assertThrows(IndexOutOfBoundsException.class, () -> ds.read(4, ds.size()), + "Shouldn't be able to read off the end of the file"); } @Test - public void testByteArray() throws Exception { + public void testByteArray() { byte[] data = new byte[256]; byte b; for (int i = 0; i < data.length; i++) { @@ -226,20 +205,10 @@ public class TestDataSource { bs = ds.read(4, 254); assertEquals(-2, bs.get()); assertEquals(-1, bs.get()); - try { - bs.get(); - fail("Shouldn't be able to read off the end"); - } catch (BufferUnderflowException e) { - // expected here - } + assertThrows(BufferUnderflowException.class, bs::get, "Shouldn't be able to read off the end"); // Past the end - try { - ds.read(4, 256); - fail("Shouldn't be able to read off the end"); - } catch (IndexOutOfBoundsException e) { - // expected here - } + assertThrows(IndexOutOfBoundsException.class, () -> ds.read(4, 256), "Shouldn't be able to read off the end"); // Overwrite Modified: poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,10 @@ package org.apache.poi.poifs.property; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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 java.io.ByteArrayOutputStream; import java.io.IOException; @@ -31,7 +31,7 @@ import java.util.List; import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test DirectoryProperty functionality @@ -154,7 +154,7 @@ public final class TestDirectoryProperty } private void createBasicDirectoryProperty() { - String name = "MyDirectory"; + final String name = "MyDirectory"; _property = new DirectoryProperty(name); _testblock = new byte[ 128 ]; @@ -164,7 +164,7 @@ public final class TestDirectoryProperty { _testblock[ index ] = ( byte ) 0; } - int limit = Math.min(31, name.length()); + int limit = name.length(); _testblock[ index++ ] = ( byte ) (2 * (limit + 1)); _testblock[ index++ ] = ( byte ) 0; @@ -195,8 +195,7 @@ public final class TestDirectoryProperty assertEquals(_testblock.length, output.length); for (int j = 0; j < _testblock.length; j++) { - assertEquals("mismatch at offset " + j, _testblock[ j ], - output[ j ]); + assertEquals(_testblock[ j ], output[ j ], "mismatch at offset " + j); } } @@ -205,26 +204,8 @@ public final class TestDirectoryProperty createBasicDirectoryProperty(); _property.addChild(new LocalProperty(1)); _property.addChild(new LocalProperty(2)); - try - { - _property.addChild(new LocalProperty(1)); - fail("should have caught IOException"); - } - catch (IOException ignored) - { - - // as expected - } - try - { - _property.addChild(new LocalProperty(2)); - fail("should have caught IOException"); - } - catch (IOException ignored) - { - - // as expected - } + assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(1))); + assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(2))); _property.addChild(new LocalProperty(3)); } @@ -234,16 +215,7 @@ public final class TestDirectoryProperty Property p1 = new LocalProperty(1); _property.addChild(p1); - try - { - _property.addChild(new LocalProperty(1)); - fail("should have caught IOException"); - } - catch (IOException ignored) - { - - // as expected - } + assertThrows(IOException.class, () -> _property.addChild(new LocalProperty(1))); assertTrue(_property.deleteChild(p1)); assertFalse(_property.deleteChild(p1)); _property.addChild(new LocalProperty(1)); @@ -292,7 +264,7 @@ public final class TestDirectoryProperty assertEquals(128, output.length); for (int j = 0; j < 128; j++) { - assertEquals("mismatch at offset " + j, expected[j], output[j]); + assertEquals(expected[j], output[j], "mismatch at offset " + j); } assertEquals(index, property.getIndex()); assertEquals(name, property.getName()); Modified: poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.poifs.property; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -29,7 +29,7 @@ import org.apache.poi.hpsf.DocumentSumma import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test DocumentProperty functionality @@ -88,10 +88,8 @@ public final class TestDocumentProperty byte[] output = stream.toByteArray(); assertEquals(128, output.length); - for (int j = 0; j < 128; j++) - { - assertEquals("mismatch at offset " + j, expected[ j ], - output[ j ]); + for (int j = 0; j < 128; j++) { + assertEquals(expected[ j ], output[ j ], "mismatch at offset " + j); } assertEquals(index, property.getIndex()); assertEquals(name, property.getName()); @@ -156,8 +154,7 @@ public final class TestDocumentProperty assertEquals(testblock.length, output.length); for (int j = 0; j < testblock.length; j++) { - assertEquals("mismatch at offset " + j, testblock[ j ], - output[ j ]); + assertEquals(testblock[ j ], output[ j ], "mismatch at offset " + j); } } } Modified: poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,10 @@ package org.apache.poi.poifs.property; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -29,7 +29,7 @@ import java.util.Arrays; import java.util.List; import org.apache.poi.poifs.storage.RawDataUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test PropertyFactory functionality @@ -145,21 +145,19 @@ public final class TestPropertyFactory { for (int j = 0; j < 64; j++) { if (isNull[j]) { - assertNull("Checking property " + j, properties.get(j)); + assertNull(properties.get(j), "Checking property " + j); } else { - assertNotNull("Checking property " + j, properties.get(j)); + assertNotNull(properties.get(j), "Checking property " + j); if (isRoot[j]) { - assertTrue("Checking property " + j, properties.get(j) instanceof RootProperty); + assertTrue(properties.get(j) instanceof RootProperty, "Checking property " + j); } if (isDirectory[j]) { - assertTrue("Checking property " + j, - properties.get(j) instanceof DirectoryProperty); + assertTrue(properties.get(j) instanceof DirectoryProperty, "Checking property " + j); } if (isDocument[j]) { - assertTrue("Checking property " + j, - properties.get(j) instanceof DocumentProperty); + assertTrue(properties.get(j) instanceof DocumentProperty, "Checking property " + j); } - assertEquals("Checking property " + j, names[j], properties.get(j).getName()); + assertEquals(names[j], properties.get(j).getName(), "Checking property " + j); } } } Modified: poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,10 @@ package org.apache.poi.poifs.property; -import static org.junit.Assert.assertArrayEquals; -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.assertArrayEquals; +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 java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -37,7 +37,7 @@ import org.apache.poi.poifs.common.POIFS import org.apache.poi.poifs.filesystem.POIFSStream; import org.apache.poi.poifs.storage.HeaderBlock; import org.apache.poi.poifs.storage.RawDataUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test PropertyTable functionality @@ -180,7 +180,7 @@ public final class TestPropertyTable { } } - + // get property table from the document PropertyTable table = new PropertyTable(header_block, data_blocks); @@ -192,8 +192,8 @@ public final class TestPropertyTable { lastChild = p; ++count; } - - assertNotNull("no children found", lastChild); + + assertNotNull(lastChild, "no children found"); assertEquals(1, count); assertTrue(lastChild.isDirectory()); count = 0; Modified: poi/trunk/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java Thu Dec 24 18:42:29 2020 @@ -17,8 +17,8 @@ package org.apache.poi.poifs.property; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,7 +27,7 @@ import java.util.Arrays; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.LocaleUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test RootProperty functionality @@ -53,7 +53,7 @@ public final class TestRootProperty { _testblock[index] = (byte) 0; } String name = "Root Entry"; - int limit = Math.min(31, name.length()); + int limit = name.length(); _testblock[index++] = (byte) (2 * (limit + 1)); _testblock[index++] = (byte) 0; @@ -87,7 +87,7 @@ public final class TestRootProperty { assertEquals(_testblock.length, output.length); for (int j = 0; j < _testblock.length; j++) { - assertEquals("mismatch at offset " + j, _testblock[j], output[j]); + assertEquals(_testblock[j], output[j], "mismatch at offset " + j); } } @@ -96,7 +96,7 @@ public final class TestRootProperty { for (int j = 0; j < 10; j++) { createBasicRootProperty(); _property.setSize(j); - assertEquals("trying block count of " + j, j * 64, _property.getSize()); + assertEquals(j * 64, _property.getSize(), "trying block count of " + j); } } @@ -126,7 +126,7 @@ public final class TestRootProperty { assertEquals(128, output.length); for (int j = 0; j < 128; j++) { - assertEquals("mismatch at offset " + j, expected[j], output[j]); + assertEquals(expected[j], output[j], "mismatch at offset " + j); } assertEquals(index, property.getIndex()); assertEquals(name, property.getName()); Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.poifs.storage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -27,7 +27,7 @@ import java.util.List; import org.apache.poi.poifs.common.POIFSBigBlockSize; import org.apache.poi.poifs.common.POIFSConstants; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test BATBlock functionality Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java Thu Dec 24 18:42:29 2020 @@ -17,14 +17,14 @@ package org.apache.poi.poifs.storage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Class to test HeaderBlockReader functionality @@ -58,24 +58,13 @@ public final class TestHeaderBlockReadin // verify we can't read a short block byte[] shortblock = Arrays.copyOf(content, 511); - try { - new HeaderBlock(new ByteArrayInputStream(shortblock)); - fail("Should have caught IOException reading a short block"); - } catch (IOException ignored) { - - // as expected - } + assertThrows(IOException.class, () -> new HeaderBlock(new ByteArrayInputStream(shortblock))); // try various forms of corruption for (int index = 0; index < 8; index++) { content[index] = (byte) (content[index] - 1); - try { - new HeaderBlock(new ByteArrayInputStream(content)); - fail("Should have caught IOException corrupting byte " + index); - } catch (IOException ignored) { - - // as expected - } + assertThrows(IOException.class, () -> new HeaderBlock(new ByteArrayInputStream(content)), + "Should have caught IOException corrupting byte " + index); // restore byte value content[index] = (byte) (content[index] + 1); Modified: poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java (original) +++ poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestFormulaParser.java Thu Dec 24 18:42:29 2020 @@ -18,9 +18,9 @@ */ package org.apache.poi.sl.draw.geom; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Date: 10/24/11 Modified: poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java (original) +++ poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java Thu Dec 24 18:42:29 2020 @@ -18,17 +18,17 @@ */ package org.apache.poi.sl.draw.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.net.URL; import java.util.Enumeration; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class TestPresetGeometries { @Test @@ -50,7 +50,7 @@ public class TestPresetGeometries { assertSame(shapes, PresetGeometries.getInstance()); } - @Ignore("problem solved? Turn back on if this debugging is still in process.") + @Disabled("problem solved? Turn back on if this debugging is still in process.") @Test public void testCheckXMLParser() throws Exception{ // Gump reports a strange error because of an unavailable XML Parser, let's try to find out where Modified: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java (original) +++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java Thu Dec 24 18:42:29 2020 @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.sl.usermodel; -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.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 java.awt.Color; import java.awt.geom.Rectangle2D; @@ -34,7 +34,7 @@ import org.apache.poi.common.usermodel.f import org.apache.poi.sl.draw.DrawPaint; import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.TabStop.TabStopType; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class BaseTestSlideShow< S extends Shape<S,P>, @@ -44,7 +44,7 @@ public abstract class BaseTestSlideShow< public abstract SlideShow<S,P> createSlideShow(); - public abstract SlideShow<S,P> reopen(SlideShow<S,P> show); + public abstract SlideShow<S,P> reopen(SlideShow<S,P> show) throws IOException; @Test public void addPicture_File() throws IOException { Modified: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java (original) +++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.sl.usermodel; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.File; @@ -54,23 +54,21 @@ public abstract class BaseTestSlideShowF @SuppressWarnings("resource") protected static void testFactoryFromNative(String file) throws Exception { + assertNotNull(file); + assertTrue(file.endsWith(".ppt") || file.endsWith(".pptx"), "Unexpected file extension: " + file); + SlideShow<?,?> ss; - // from POIFS if (file.endsWith(".ppt")) { - POIFSFileSystem poifs = new POIFSFileSystem(fromFile(file)); - ss = SlideShowFactory.create(poifs); - assertNotNull(ss); - poifs.close(); + // from POIFS + try (POIFSFileSystem poifs = new POIFSFileSystem(fromFile(file))) { + ss = SlideShowFactory.create(poifs); + assertNotNull(ss); + } assertCloseDoesNotModifyFile(file, ss); - } - // from OPCPackage - else if (file.endsWith(".pptx")) { - // not implemented + } else { + // from OPCPackage ... not implemented throw new UnsupportedOperationException("Test not implemented"); } - else { - fail("Unexpected file extension: " + file); - } } @SuppressWarnings("resource") @@ -91,21 +89,19 @@ public abstract class BaseTestSlideShowF @SuppressWarnings("resource") protected static void testFactoryFromProtectedNative(String protectedFile, String password) throws Exception { + assertTrue(protectedFile.endsWith(".ppt") || protectedFile.endsWith(".pptx"), + "Unrecognized file extension: " + protectedFile); + SlideShow<?,?> ss; // Encryption layer is a BIFF8 binary format that can be read by POIFSFileSystem, // used for both HSLF and XSLF // from protected POIFS - if (protectedFile.endsWith(".ppt") || protectedFile.endsWith(".pptx")) { - POIFSFileSystem poifs = new POIFSFileSystem(fromFile(protectedFile)); + try (POIFSFileSystem poifs = new POIFSFileSystem(fromFile(protectedFile))) { ss = SlideShowFactory.create(poifs.getRoot(), password); assertNotNull(ss); - poifs.close(); - assertCloseDoesNotModifyFile(protectedFile, ss); - } - else { - fail("Unrecognized file extension: " + protectedFile); } + assertCloseDoesNotModifyFile(protectedFile, ss); } @SuppressWarnings("SameParameterValue") @@ -169,8 +165,7 @@ public abstract class BaseTestSlideShowF final byte[] after = readFile(filename); try { - assertArrayEquals(filename + " sample file was modified as a result of closing the slideshow", - before, after); + assertArrayEquals(before, after, filename + " sample file was modified as a result of closing the slideshow"); } catch (AssertionError e) { // if the file after closing is different, then re-set // the file to the state before in order to not have a dirty SCM Modified: poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Check that all enum values are properly set Modified: poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java Thu Dec 24 18:42:29 2020 @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.ss.format; -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 java.io.IOException; import java.text.ParseException; @@ -38,23 +38,23 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.LocaleUtil; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestCellFormat { private static TimeZone userTimeZone; - @BeforeClass + @BeforeAll public static void setTimeZone() { userTimeZone = LocaleUtil.getUserTimeZone(); LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET")); LocaleUtil.setUserLocale(Locale.US); } - @AfterClass + @AfterAll public static void resetTimeZone() { LocaleUtil.setUserTimeZone(userTimeZone); LocaleUtil.setUserLocale(Locale.ROOT); @@ -1024,6 +1024,6 @@ public class TestCellFormat { assertTrue(CellFormatPart.NAMED_COLORS.size() >= HSSFColor.HSSFColorPredefined.values().length); Stream.of("GREEN", "Green", "RED", "Red", "BLUE", "Blue", "YELLOW", "Yellow") .map(CellFormatPart.NAMED_COLORS::get) - .forEach(Assert::assertNotNull); + .forEach(Assertions::assertNotNull); } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatCondition.java Thu Dec 24 18:42:29 2020 @@ -16,10 +16,10 @@ ==================================================================== */ package org.apache.poi.ss.format; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestCellFormatCondition { @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormatResult.java Thu Dec 24 18:42:29 2020 @@ -16,20 +16,20 @@ ==================================================================== */ package org.apache.poi.ss.format; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.awt.Color; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestCellFormatResult { - @Test(expected = IllegalArgumentException.class) + @Test public void testNullTextRaisesException() { final boolean applies = true; final String text = null; final Color textColor = Color.BLACK; - final CellFormatResult result = new CellFormatResult(applies, text, textColor); - fail("Cannot initialize CellFormatResult with null text parameter"); + assertThrows(IllegalArgumentException.class, () -> new CellFormatResult(applies, text, textColor), + "Cannot initialize CellFormatResult with null text parameter"); } } \ No newline at end of file Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestExternalFunctions.java Thu Dec 24 18:42:29 2020 @@ -16,10 +16,10 @@ ==================================================================== */ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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 java.io.IOException; @@ -37,7 +37,7 @@ import org.apache.poi.ss.usermodel.CellT import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test setting / evaluating of Analysis Toolpack and user-defined functions @@ -96,42 +96,38 @@ public abstract class BaseTestExternalFu @Test public void testExternalFunctions() throws IOException { - Workbook wb = _testDataProvider.createWorkbook(); - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + try (Workbook wb = _testDataProvider.createWorkbook()) { + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - Sheet sh = wb.createSheet(); + Sheet sh = wb.createSheet(); - Cell cell1 = sh.createRow(0).createCell(0); - // functions from the Excel Analysis Toolpack - cell1.setCellFormula("ISODD(1)+ISEVEN(2)"); - assertEquals("ISODD(1)+ISEVEN(2)", cell1.getCellFormula()); - - Cell cell2 = sh.createRow(1).createCell(0); - // unregistered functions are parseable and renderable, but may not be evaluateable - cell2.setCellFormula("MYFUNC(\"B1\")"); - try { - evaluator.evaluate(cell2); - fail("Expected NotImplementedFunctionException/NotImplementedException"); - } catch (final NotImplementedException e) { + Cell cell1 = sh.createRow(0).createCell(0); + // functions from the Excel Analysis Toolpack + cell1.setCellFormula("ISODD(1)+ISEVEN(2)"); + assertEquals("ISODD(1)+ISEVEN(2)", cell1.getCellFormula()); + + Cell cell2 = sh.createRow(1).createCell(0); + // unregistered functions are parseable and renderable, but may not be evaluateable + cell2.setCellFormula("MYFUNC(\"B1\")"); + NotImplementedException e = assertThrows(NotImplementedException.class, () -> evaluator.evaluate(cell2), + "Expected NotImplementedFunctionException/NotImplementedException"); assertTrue(e.getCause() instanceof NotImplementedFunctionException); // Alternatively, a future implementation of evaluate could return #NAME? error to align behavior with Excel // assertEquals(ErrorEval.NAME_INVALID, ErrorEval.valueOf(evaluator.evaluate(cell2).getErrorValue())); - } - - wb.addToolPack(customToolpack); - cell2.setCellFormula("MYFUNC(\"B1\")"); - assertEquals("MYFUNC(\"B1\")", cell2.getCellFormula()); + wb.addToolPack(customToolpack); - Cell cell3 = sh.createRow(2).createCell(0); - cell3.setCellFormula("MYFUNC2(\"C1\")&\"-\"&A2"); //where A2 is defined above - assertEquals("MYFUNC2(\"C1\")&\"-\"&A2", cell3.getCellFormula()); + cell2.setCellFormula("MYFUNC(\"B1\")"); + assertEquals("MYFUNC(\"B1\")", cell2.getCellFormula()); - assertEquals(2.0, evaluator.evaluate(cell1).getNumberValue(), 0); - assertEquals("B1abc", evaluator.evaluate(cell2).getStringValue()); - assertEquals("C1abc2-B1abc", evaluator.evaluate(cell3).getStringValue()); - - wb.close(); + Cell cell3 = sh.createRow(2).createCell(0); + cell3.setCellFormula("MYFUNC2(\"C1\")&\"-\"&A2"); //where A2 is defined above + assertEquals("MYFUNC2(\"C1\")&\"-\"&A2", cell3.getCellFormula()); + + assertEquals(2.0, evaluator.evaluate(cell1).getNumberValue(), 0); + assertEquals("B1abc", evaluator.evaluate(cell2).getStringValue()); + assertEquals("C1abc2-B1abc", evaluator.evaluate(cell3).getStringValue()); + } } /** Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/BaseTestMissingWorkbook.java Thu Dec 24 18:42:29 2020 @@ -19,11 +19,11 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.Map; @@ -35,9 +35,9 @@ import org.apache.poi.ss.usermodel.Formu import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -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; public class BaseTestMissingWorkbook { protected Workbook mainWorkbook; @@ -58,7 +58,7 @@ public class BaseTestMissingWorkbook { this.SOURCE_WORKBOOK_FILENAME = SOURCE_WORKBOOK_FILENAME; } - @Before + @BeforeEach public void setUp() throws Exception { mainWorkbook = HSSFTestDataSamples.openSampleWorkbook(MAIN_WORKBOOK_FILENAME); sourceWorkbook = HSSFTestDataSamples.openSampleWorkbook(SOURCE_WORKBOOK_FILENAME); @@ -67,7 +67,7 @@ public class BaseTestMissingWorkbook { assertNotNull(sourceWorkbook); } - @After + @AfterEach public void tearDown() throws Exception { if(mainWorkbook != null) { mainWorkbook.close(); @@ -87,12 +87,9 @@ public class BaseTestMissingWorkbook { Cell lA1Cell = lARow.getCell(0); assertEquals(CellType.FORMULA, lA1Cell.getCellType()); - try { - evaluator.evaluateFormulaCell(lA1Cell); - fail("Missing external workbook reference exception expected!"); - } catch(RuntimeException re) { - assertTrue("Unexpected exception: " + re, re.getMessage().contains(SOURCE_DUMMY_WORKBOOK_FILENAME)); - } + RuntimeException re = assertThrows(RuntimeException.class, () -> evaluator.evaluateFormulaCell(lA1Cell), + "Missing external workbook reference exception expected!"); + assertTrue(re.getMessage().contains(SOURCE_DUMMY_WORKBOOK_FILENAME)); } @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/SheetRangeAndWorkbookIndexFormatterTest.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; public class SheetRangeAndWorkbookIndexFormatterTest { @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestCellCacheEntry.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,11 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.ValueEval; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests {@link org.apache.poi.ss.formula.CellCacheEntry}. Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestEvaluationCache.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.util.ArrayList; import java.util.Arrays; @@ -52,7 +52,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests {@link org.apache.poi.ss.formula.EvaluationCache}. Makes sure that where possible (previously calculated) cached @@ -219,11 +219,10 @@ public class TestEvaluationCache { private final HSSFSheet _sheet; private final WorkbookEvaluator _evaluator; - private final HSSFWorkbook _wb; private final EvalListener _evalListener; public MySheet() { - _wb = new HSSFWorkbook(); + HSSFWorkbook _wb = new HSSFWorkbook(); _evalListener = new EvalListener(_wb); _evaluator = WorkbookEvaluatorTestHelper.createEvaluator(_wb, _evalListener); _sheet = _wb.createSheet("Sheet1"); @@ -621,7 +620,7 @@ public class TestEvaluationCache { cv = fe.evaluate(cellA1); // looks like left-over cached result from before change to B1 - assertNotEquals("Identified bug 46053", 2.2, cv.getNumberValue()); + assertNotEquals(2.2, cv.getNumberValue(), "Identified bug 46053"); assertEquals(2.6, cv.getNumberValue(), 0.0); } @@ -666,7 +665,7 @@ public class TestEvaluationCache { private static void confirmLog(MySheet ms, String[] expectedLog) { String[] actualLog = ms.getAndClearLog(); - assertArrayEquals("Log entry mismatch", expectedLog, actualLog); + assertArrayEquals(expectedLog, actualLog, "Log entry mismatch"); } @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,10 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.ptg.AreaErrPtg; @@ -28,8 +28,7 @@ import org.apache.poi.ss.formula.ptg.Are import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ref3DPtg; import org.apache.poi.ss.util.CellReference; - -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link FormulaShifter}. @@ -121,7 +120,7 @@ public final class TestFormulaShifter { confirmAreaColumnShift(aptg, 18, 22, 5, 10, 25); // simple expansion at bottom } - + @Test public void testCopyAreasSourceRowsRelRel() { @@ -131,7 +130,7 @@ public final class TestFormulaShifter { confirmAreaRowCopy(aptg, 0, 30, 20, 30, 40, true); confirmAreaRowCopy(aptg, 15, 25, -15, -1, -1, true); //DeletedRef } - + @Test public void testCopyAreasSourceRowsRelAbs() { @@ -142,7 +141,7 @@ public final class TestFormulaShifter { confirmAreaRowCopy(aptg, 0, 30, 20, 20, 30, true); confirmAreaRowCopy(aptg, 15, 25, -15, -1, -1, true); //DeletedRef } - + @Test public void testCopyAreasSourceRowsAbsRel() { // aptg is part of a formula in a cell that was just copied to another row @@ -158,7 +157,7 @@ public final class TestFormulaShifter { confirmAreaRowCopy(aptg, 0, 30, 20, 10, 40, true); confirmAreaRowCopy(aptg, 15, 25, -15, 5, 10, true); //sortTopLeftToBottomRight swapped firstRow and lastRow because firstRow is absolute } - + @Test public void testCopyAreasSourceRowsAbsAbs() { // aptg is part of a formula in a cell that was just copied to another row @@ -166,7 +165,7 @@ public final class TestFormulaShifter { // No other references besides the cells that were involved in the copy need to be updated // this makes the row copy significantly different from the row shift, where all references // in the workbook need to track the row shift - + // all these operations are on an area ref spanning rows 10 to 20 final AreaPtg aptg = createAreaPtgRow(10, 20, false, false); @@ -227,9 +226,9 @@ public final class TestFormulaShifter { confirmAreaColumnCopy(aptg, 0, 30, 20, 10, 20, false); confirmAreaColumnCopy(aptg, 15, 25, -15, 10, 20, false); } - - - + + + /** * Tests what happens to an area ref when some outside rows are moved to overlap * that area ref @@ -278,7 +277,8 @@ public final class TestFormulaShifter { FormulaShifter fs = FormulaShifter.createForRowShift(0, "", firstRowMoved, lastRowMoved, numberRowsMoved, SpreadsheetVersion.EXCEL2007); boolean expectedChanged = aptg.getFirstRow() != expectedAreaFirstRow || aptg.getLastRow() != expectedAreaLastRow; - AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method + // clone so we can re-use aptg in calling method + AreaPtg copyPtg = aptg.copy(); Ptg[] ptgs = { copyPtg, }; boolean actualChanged = fs.adjustFormula(ptgs, 0); if (expectedAreaFirstRow < 0) { @@ -286,7 +286,8 @@ public final class TestFormulaShifter { return; } assertEquals(expectedChanged, actualChanged); - assertEquals(copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement) + // expected to change in place (although this is not a strict requirement) + assertEquals(copyPtg, ptgs[0]); assertEquals(expectedAreaFirstRow, copyPtg.getFirstRow()); assertEquals(expectedAreaLastRow, copyPtg.getLastRow()); @@ -300,7 +301,8 @@ public final class TestFormulaShifter { FormulaShifter fs = FormulaShifter.createForColumnShift(0, "", firstColumnMoved, lastColumnMoved, numberColumnsMoved, SpreadsheetVersion.EXCEL2007); boolean expectedChanged = aptg.getFirstColumn() != expectedAreaFirstColumn || aptg.getLastColumn() != expectedAreaLastColumn; - AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method + // clone so we can re-use aptg in calling method + AreaPtg copyPtg = aptg.copy(); Ptg[] ptgs = { copyPtg, }; boolean actualChanged = fs.adjustFormula(ptgs, 0); if (expectedAreaFirstColumn < 0) { @@ -308,59 +310,61 @@ public final class TestFormulaShifter { return; } assertEquals(expectedChanged, actualChanged); - assertEquals(copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement) + // expected to change in place (although this is not a strict requirement) + assertEquals(copyPtg, ptgs[0]); assertEquals(expectedAreaFirstColumn, copyPtg.getFirstColumn()); assertEquals(expectedAreaLastColumn, copyPtg.getLastColumn()); } - - + + private static void confirmAreaRowCopy(AreaPtg aptg, int firstRowCopied, int lastRowCopied, int rowOffset, int expectedFirstRow, int expectedLastRow, boolean expectedChanged) { - - final AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method + // clone so we can re-use aptg in calling method + final AreaPtg copyPtg = aptg.copy(); final Ptg[] ptgs = { copyPtg, }; final FormulaShifter fs = FormulaShifter.createForRowCopy(0, null, firstRowCopied, lastRowCopied, rowOffset, SpreadsheetVersion.EXCEL2007); final boolean actualChanged = fs.adjustFormula(ptgs, 0); - + // DeletedAreaRef if (expectedFirstRow < 0 || expectedLastRow < 0) { - assertEquals("Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0], - AreaErrPtg.class, ptgs[0].getClass()); + assertEquals(AreaErrPtg.class, ptgs[0].getClass(), "Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0]); return; } - - assertEquals("Should this AreaPtg change due to row copy?", expectedChanged, actualChanged); - assertEquals("AreaPtgs should be modified in-place when a row containing the AreaPtg is copied", copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement) - assertEquals("AreaPtg first row", expectedFirstRow, copyPtg.getFirstRow()); - assertEquals("AreaPtg last row", expectedLastRow, copyPtg.getLastRow()); + + assertEquals(expectedChanged, actualChanged, "Should this AreaPtg change due to row copy?"); + // expected to change in place (although this is not a strict requirement) + assertEquals(copyPtg, ptgs[0], "AreaPtgs should be modified in-place when a row containing the AreaPtg is copied"); + assertEquals(expectedFirstRow, copyPtg.getFirstRow(), "AreaPtg first row"); + assertEquals(expectedLastRow, copyPtg.getLastRow(), "AreaPtg last row"); } private static void confirmAreaColumnCopy(AreaPtg aptg, int firstColumnCopied, int lastColumnCopied, int columnOffset, int expectedFirstColumn, int expectedLastColumn, boolean expectedChanged) { - - final AreaPtg copyPtg = (AreaPtg) aptg.copy(); // clone so we can re-use aptg in calling method + // clone so we can re-use aptg in calling method + final AreaPtg copyPtg = aptg.copy(); final Ptg[] ptgs = { copyPtg, }; final FormulaShifter fs = FormulaShifter.createForColumnCopy(0, null, firstColumnCopied, lastColumnCopied, columnOffset, SpreadsheetVersion.EXCEL2007); final boolean actualChanged = fs.adjustFormula(ptgs, 0); // DeletedAreaRef if (expectedFirstColumn < 0 || expectedLastColumn < 0) { - assertEquals("Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0], - AreaErrPtg.class, ptgs[0].getClass()); + assertEquals(AreaErrPtg.class, ptgs[0].getClass(), + "Reference should have shifted off worksheet, producing #REF! error: " + ptgs[0]); return; } - assertEquals("Should this AreaPtg change due to column copy?", expectedChanged, actualChanged); - assertEquals("AreaPtgs should be modified in-place when a column containing the AreaPtg is copied", copyPtg, ptgs[0]); // expected to change in place (although this is not a strict requirement) - assertEquals("AreaPtg first column", expectedFirstColumn, copyPtg.getFirstColumn()); - assertEquals("AreaPtg last column", expectedLastColumn, copyPtg.getLastColumn()); + assertEquals(expectedChanged, actualChanged, "Should this AreaPtg change due to column copy?"); + // expected to change in place (although this is not a strict requirement) + assertEquals(copyPtg, ptgs[0], "AreaPtgs should be modified in-place when a column containing the AreaPtg is copied"); + assertEquals(expectedFirstColumn, copyPtg.getFirstColumn(), "AreaPtg first column"); + assertEquals(expectedLastColumn, copyPtg.getLastColumn(), "AreaPtg last column"); } - + private static AreaPtg createAreaPtgRow(int initialAreaFirstRow, int initialAreaLastRow) { return createAreaPtgRow(initialAreaFirstRow, initialAreaLastRow, false, false); } @@ -368,7 +372,7 @@ public final class TestFormulaShifter { private static AreaPtg createAreaPtgColumn(int initialAreaFirstColumn, int initialAreaLastColumn) { return createAreaPtgColumn(initialAreaFirstColumn, initialAreaLastColumn, false, false); } - + private static AreaPtg createAreaPtgRow(int initialAreaFirstRow, int initialAreaLastRow, boolean firstRowRelative, boolean lastRowRelative) { return new AreaPtg(initialAreaFirstRow, initialAreaLastRow, 2, 5, firstRowRelative, lastRowRelative, false, false); } @@ -379,33 +383,33 @@ public final class TestFormulaShifter { @Test public void testShiftSheet() { - // 4 sheets, move a sheet from pos 2 to pos 0, i.e. current 0 becomes 1, current 1 becomes pos 2 + // 4 sheets, move a sheet from pos 2 to pos 0, i.e. current 0 becomes 1, current 1 becomes pos 2 FormulaShifter shifter = FormulaShifter.createForSheetShift(2, 0); - + Ptg[] ptgs = new Ptg[] { new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0), new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1), new Ref3DPtg(new CellReference("third", 0, 0, true, true), 2), new Ref3DPtg(new CellReference("fourth", 0, 0, true, true), 3), }; - + shifter.adjustFormula(ptgs, -1); - - assertEquals("formula previously pointing to sheet 0 should now point to sheet 1", - 1, ((Ref3DPtg)ptgs[0]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 1 should now point to sheet 2", - 2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 2 should now point to sheet 0", - 0, ((Ref3DPtg)ptgs[2]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 3 should be unchanged", - 3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex()); + + assertEquals(1, ((Ref3DPtg)ptgs[0]).getExternSheetIndex(), + "formula previously pointing to sheet 0 should now point to sheet 1"); + assertEquals(2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex(), + "formula previously pointing to sheet 1 should now point to sheet 2"); + assertEquals(0, ((Ref3DPtg)ptgs[2]).getExternSheetIndex(), + "formula previously pointing to sheet 2 should now point to sheet 0"); + assertEquals(3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex(), + "formula previously pointing to sheet 3 should be unchanged"); } @Test public void testShiftSheet2() { - // 4 sheets, move a sheet from pos 1 to pos 2, i.e. current 2 becomes 1, current 1 becomes pos 2 + // 4 sheets, move a sheet from pos 1 to pos 2, i.e. current 2 becomes 1, current 1 becomes pos 2 FormulaShifter shifter = FormulaShifter.createForSheetShift(1, 2); - + Ptg[] ptgs = new Ptg[] { new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0), new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1), @@ -414,34 +418,25 @@ public final class TestFormulaShifter { }; shifter.adjustFormula(ptgs, -1); - - assertEquals("formula previously pointing to sheet 0 should be unchanged", - 0, ((Ref3DPtg)ptgs[0]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 1 should now point to sheet 2", - 2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 2 should now point to sheet 1", - 1, ((Ref3DPtg)ptgs[2]).getExternSheetIndex()); - assertEquals("formula previously pointing to sheet 3 should be unchanged", - 3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex()); + + assertEquals(0, ((Ref3DPtg)ptgs[0]).getExternSheetIndex(), + "formula previously pointing to sheet 0 should be unchanged"); + assertEquals(2, ((Ref3DPtg)ptgs[1]).getExternSheetIndex(), + "formula previously pointing to sheet 1 should now point to sheet 2"); + assertEquals(1, ((Ref3DPtg)ptgs[2]).getExternSheetIndex(), + "formula previously pointing to sheet 2 should now point to sheet 1"); + assertEquals(3, ((Ref3DPtg)ptgs[3]).getExternSheetIndex(), + "formula previously pointing to sheet 3 should be unchanged"); } - + @Test public void testInvalidArgument() { - try { - FormulaShifter.createForRowShift(1, "name", 1, 2, 0, SpreadsheetVersion.EXCEL97); - fail("Should catch exception here"); - } catch (IllegalArgumentException e) { - // expected here - } - - try { - FormulaShifter.createForRowShift(1, "name", 2, 1, 2, SpreadsheetVersion.EXCEL97); - fail("Should catch exception here"); - } catch (IllegalArgumentException e) { - // expected here - } + assertThrows(IllegalArgumentException.class, () -> + FormulaShifter.createForRowShift(1, "name", 1, 2, 0, SpreadsheetVersion.EXCEL97)); + assertThrows(IllegalArgumentException.class, () -> + FormulaShifter.createForRowShift(1, "name", 2, 1, 2, SpreadsheetVersion.EXCEL97)); } - + @Test public void testConstructor() { assertNotNull(FormulaShifter.createForRowShift(1, "name", 1, 2, 2, SpreadsheetVersion.EXCEL97)); Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestFunctionRegistry.java Thu Dec 24 18:42:29 2020 @@ -19,9 +19,9 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; @@ -36,13 +36,13 @@ import org.apache.poi.ss.formula.eval.Fu import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.CellValue; -import org.junit.After; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class TestFunctionRegistry { HSSFWorkbook wb; @@ -50,7 +50,7 @@ public class TestFunctionRegistry { HSSFRow row; HSSFFormulaEvaluator fe; - @Before + @BeforeEach public void setup() { wb = new HSSFWorkbook(); sheet = wb.createSheet("Sheet1"); @@ -58,7 +58,7 @@ public class TestFunctionRegistry { fe = new HSSFFormulaEvaluator(wb); } - @After + @AfterEach public void teardown() throws IOException { wb.close(); wb = null; @@ -67,11 +67,11 @@ public class TestFunctionRegistry { fe = null; } - @Test(expected = NotImplementedException.class) + @Test public void testRegisterInRuntimeA() { HSSFCell cellA = row.createCell(0); cellA.setCellFormula("FISHER(A5)"); - fe.evaluate(cellA); + assertThrows(NotImplementedException.class, () -> fe.evaluate(cellA)); } @Test @@ -83,11 +83,11 @@ public class TestFunctionRegistry { assertEquals(ErrorEval.NA.getErrorCode(), cv.getErrorValue()); } - @Test(expected = NotImplementedException.class) + @Test public void testRegisterInRuntimeC() { HSSFCell cellB = row.createCell(1); cellB.setCellFormula("CUBEMEMBERPROPERTY(A5)"); - fe.evaluate(cellB); + assertThrows(NotImplementedException.class, () -> fe.evaluate(cellB)); } @Test Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestPlainCellCache.java Thu Dec 24 18:42:29 2020 @@ -19,13 +19,13 @@ package org.apache.poi.ss.formula; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import org.apache.poi.ss.formula.PlainCellCache.Loc; import org.apache.poi.ss.formula.eval.NumberEval; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestPlainCellCache { Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/formula/TestSheetNameFormatter.java Thu Dec 24 18:42:29 2020 @@ -17,37 +17,38 @@ package org.apache.poi.ss.formula; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link SheetNameFormatter} - * + * * @author Josh Micich */ public final class TestSheetNameFormatter { /** - * Tests main public method 'format' + * Tests main public method 'format' */ @Test public void testFormat() { - + confirmFormat("abc", "abc"); confirmFormat("123", "'123'"); - + confirmFormat("my sheet", "'my sheet'"); // space confirmFormat("A:MEM", "'A:MEM'"); // colon confirmFormat("O'Brian", "'O''Brian'"); // single quote gets doubled - + confirmFormat("3rdTimeLucky", "'3rdTimeLucky'"); // digit in first pos confirmFormat("_", "_"); // plain underscore OK confirmFormat("my_3rd_sheet", "my_3rd_sheet"); // underscores and digits OK - confirmFormat("A12220", "'A12220'"); + confirmFormat("A12220", "'A12220'"); confirmFormat("TAXRETURN19980415", "TAXRETURN19980415"); confirmFormat(null, "#REF"); @@ -130,19 +131,8 @@ public final class TestSheetNameFormatte } }; - try { - SheetNameFormatter.appendFormat(mock, null, null); - fail("Should catch exception here"); - } catch (RuntimeException e) { - // expected here - } - - try { - SheetNameFormatter.appendFormat(mock, null); - fail("Should catch exception here"); - } catch (RuntimeException e) { - // expected here - } + assertThrows(RuntimeException.class, () -> SheetNameFormatter.appendFormat(mock, null, null)); + assertThrows(RuntimeException.class, () -> SheetNameFormatter.appendFormat(mock, null)); } @Test @@ -151,22 +141,22 @@ public final class TestSheetNameFormatte confirmFormat("FALSE", "'FALSE'"); confirmFormat("True", "'True'"); confirmFormat("fAlse", "'fAlse'"); - + confirmFormat("Yes", "Yes"); confirmFormat("No", "No"); } - + private static void confirmCellNameMatch(String rawSheetName, boolean expected) { assertEquals(expected, SheetNameFormatter.nameLooksLikePlainCellReference(rawSheetName)); } - + /** * Tests functionality to determine whether a sheet name containing only letters and digits * would look (to Excel) like a cell name. */ @Test public void testLooksLikePlainCellReference() { - + confirmCellNameMatch("A1", true); confirmCellNameMatch("a111", true); confirmCellNameMatch("AA", false); @@ -176,13 +166,13 @@ public final class TestSheetNameFormatte confirmCellNameMatch("Sh3", false); confirmCellNameMatch("SALES20080101", false); // out of range } - + private static void confirmCellRange(String text, int numberOfPrefixLetters, boolean expected) { String prefix = text.substring(0, numberOfPrefixLetters); String suffix = text.substring(numberOfPrefixLetters); assertEquals(expected, SheetNameFormatter.cellReferenceIsWithinRange(prefix, suffix)); } - + /** * Tests exact boundaries for names that look very close to cell names (i.e. contain 1 or more * letters followed by one or more digits). --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org