Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java Thu Dec 24 18:42:29 2020 @@ -17,16 +17,16 @@ package org.apache.poi.xssf.usermodel; -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.IOException; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; @@ -52,26 +52,26 @@ public class TestXSSFColGrouping { */ @Test public void testNoColsWithoutWidthWhenGrouping() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - sheet.setColumnWidth(4, 5000); - sheet.setColumnWidth(5, 5000); + sheet.setColumnWidth(4, 5000); + sheet.setColumnWidth(5, 5000); - sheet.groupColumn((short) 4, (short) 7); - sheet.groupColumn((short) 9, (short) 12); + sheet.groupColumn((short) 4, (short) 7); + sheet.groupColumn((short) 9, (short) 12); - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping"); - sheet = wb2.getSheet("test"); - - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "test52186/cols:" + cols); - for (CTCol col : cols.getColArray()) { - assertTrue("Col width attribute is unset: " + col, col.isSetWidth()); - } + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping")) { + sheet = wb2.getSheet("test"); - wb2.close(); - wb1.close(); + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "test52186/cols:" + cols); + for (CTCol col : cols.getColArray()) { + assertTrue(col.isSetWidth(), "Col width attribute is unset: " + col); + } + + } + } } /** @@ -80,31 +80,31 @@ public class TestXSSFColGrouping { */ @Test public void testNoColsWithoutWidthWhenGroupingAndCollapsing() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); - - sheet.setColumnWidth(4, 5000); - sheet.setColumnWidth(5, 5000); - - sheet.groupColumn((short) 4, (short) 5); - - sheet.setColumnGroupCollapsed(4, true); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols); + sheet.setColumnWidth(4, 5000); + sheet.setColumnWidth(5, 5000); - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing"); - sheet = wb2.getSheet("test"); + sheet.groupColumn((short) 4, (short) 5); - for (int i = 4; i <= 5; i++) { - assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i)); + sheet.setColumnGroupCollapsed(4, true); + + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols); + + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing")) { + sheet = wb2.getSheet("test"); + + for (int i = 4; i <= 5; i++) { + assertEquals(5000, sheet.getColumnWidth(i), "Unexpected width of column " + i); + } + cols = sheet.getCTWorksheet().getColsArray(0); + for (CTCol col : cols.getColArray()) { + assertTrue(col.isSetWidth(), "Col width attribute is unset: " + col); + } + } } - cols = sheet.getCTWorksheet().getColsArray(0); - for (CTCol col : cols.getColArray()) { - assertTrue("Col width attribute is unset: " + col, col.isSetWidth()); - } - wb2.close(); - wb1.close(); } /** @@ -112,47 +112,47 @@ public class TestXSSFColGrouping { */ @Test public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - CTCol col = cols.addNewCol(); - col.setMin(1 + 1); - col.setMax(4 + 1); - col.setWidth(20); - col.setCustomWidth(true); - - sheet.groupColumn((short) 2, (short) 3); - - sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:" + cols); - - assertEquals(0, cols.getColArray(0).getOutlineLevel()); - assertEquals(2, cols.getColArray(0).getMin()); // 1 based - assertEquals(2, cols.getColArray(0).getMax()); // 1 based - assertTrue(cols.getColArray(0).getCustomWidth()); - - assertEquals(1, cols.getColArray(1).getOutlineLevel()); - assertEquals(3, cols.getColArray(1).getMin()); // 1 based - assertEquals(4, cols.getColArray(1).getMax()); // 1 based - assertTrue(cols.getColArray(1).getCustomWidth()); - - assertEquals(0, cols.getColArray(2).getOutlineLevel()); - assertEquals(5, cols.getColArray(2).getMin()); // 1 based - assertEquals(5, cols.getColArray(2).getMax()); // 1 based - assertTrue(cols.getColArray(2).getCustomWidth()); + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + CTCol col = cols.addNewCol(); + col.setMin(1 + 1); + col.setMax(4 + 1); + col.setWidth(20); + col.setCustomWidth(true); + + sheet.groupColumn((short) 2, (short) 3); + + sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:" + cols); + + assertEquals(0, cols.getColArray(0).getOutlineLevel()); + assertEquals(2, cols.getColArray(0).getMin()); // 1 based + assertEquals(2, cols.getColArray(0).getMax()); // 1 based + assertTrue(cols.getColArray(0).getCustomWidth()); + + assertEquals(1, cols.getColArray(1).getOutlineLevel()); + assertEquals(3, cols.getColArray(1).getMin()); // 1 based + assertEquals(4, cols.getColArray(1).getMax()); // 1 based + assertTrue(cols.getColArray(1).getCustomWidth()); + + assertEquals(0, cols.getColArray(2).getOutlineLevel()); + assertEquals(5, cols.getColArray(2).getMin()); // 1 based + assertEquals(5, cols.getColArray(2).getMax()); // 1 based + assertTrue(cols.getColArray(2).getCustomWidth()); + + assertEquals(3, cols.sizeOfColArray()); + + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS")) { + sheet = wb2.getSheet("test"); + + for (int i = 1; i <= 4; i++) { + assertEquals(20 * 256, sheet.getColumnWidth(i), "Unexpected width of column " + i); + } - assertEquals(3, cols.sizeOfColArray()); - - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS"); - sheet = wb2.getSheet("test"); - - for (int i = 1; i <= 4; i++) { - assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i)); + } } - - wb2.close(); - wb1.close(); } /** @@ -160,47 +160,47 @@ public class TestXSSFColGrouping { */ @Test public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); - - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - CTCol col = cols.addNewCol(); - col.setMin(2 + 1); - col.setMax(4 + 1); - col.setWidth(20); - col.setCustomWidth(true); - - sheet.groupColumn((short) 1, (short) 5); - - cols = sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:" + cols); - - assertEquals(1, cols.getColArray(0).getOutlineLevel()); - assertEquals(2, cols.getColArray(0).getMin()); // 1 based - assertEquals(2, cols.getColArray(0).getMax()); // 1 based - assertFalse(cols.getColArray(0).getCustomWidth()); - - assertEquals(1, cols.getColArray(1).getOutlineLevel()); - assertEquals(3, cols.getColArray(1).getMin()); // 1 based - assertEquals(5, cols.getColArray(1).getMax()); // 1 based - assertTrue(cols.getColArray(1).getCustomWidth()); - - assertEquals(1, cols.getColArray(2).getOutlineLevel()); - assertEquals(6, cols.getColArray(2).getMin()); // 1 based - assertEquals(6, cols.getColArray(2).getMax()); // 1 based - assertFalse(cols.getColArray(2).getCustomWidth()); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - assertEquals(3, cols.sizeOfColArray()); + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + CTCol col = cols.addNewCol(); + col.setMin(2 + 1); + col.setMax(4 + 1); + col.setWidth(20); + col.setCustomWidth(true); + + sheet.groupColumn((short) 1, (short) 5); + + cols = sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:" + cols); + + assertEquals(1, cols.getColArray(0).getOutlineLevel()); + assertEquals(2, cols.getColArray(0).getMin()); // 1 based + assertEquals(2, cols.getColArray(0).getMax()); // 1 based + assertFalse(cols.getColArray(0).getCustomWidth()); + + assertEquals(1, cols.getColArray(1).getOutlineLevel()); + assertEquals(3, cols.getColArray(1).getMin()); // 1 based + assertEquals(5, cols.getColArray(1).getMax()); // 1 based + assertTrue(cols.getColArray(1).getCustomWidth()); + + assertEquals(1, cols.getColArray(2).getOutlineLevel()); + assertEquals(6, cols.getColArray(2).getMin()); // 1 based + assertEquals(6, cols.getColArray(2).getMax()); // 1 based + assertFalse(cols.getColArray(2).getCustomWidth()); + + assertEquals(3, cols.sizeOfColArray()); + + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS")) { + sheet = wb2.getSheet("test"); + + for (int i = 2; i <= 4; i++) { + assertEquals(20 * 256, sheet.getColumnWidth(i), "Unexpected width of column " + i); + } - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS"); - sheet = wb2.getSheet("test"); - - for (int i = 2; i <= 4; i++) { - assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i)); + } } - - wb2.close(); - wb1.close(); } /** @@ -208,48 +208,48 @@ public class TestXSSFColGrouping { */ @Test public void testMergingOverlappingCols_OVERLAPS_1_MINOR() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); - - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - CTCol col = cols.addNewCol(); - col.setMin(2 + 1); - col.setMax(4 + 1); - col.setWidth(20); - col.setCustomWidth(true); - - sheet.groupColumn((short) 3, (short) 5); - - cols = sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:" + cols); - - assertEquals(0, cols.getColArray(0).getOutlineLevel()); - assertEquals(3, cols.getColArray(0).getMin()); // 1 based - assertEquals(3, cols.getColArray(0).getMax()); // 1 based - assertTrue(cols.getColArray(0).getCustomWidth()); - - assertEquals(1, cols.getColArray(1).getOutlineLevel()); - assertEquals(4, cols.getColArray(1).getMin()); // 1 based - assertEquals(5, cols.getColArray(1).getMax()); // 1 based - assertTrue(cols.getColArray(1).getCustomWidth()); - - assertEquals(1, cols.getColArray(2).getOutlineLevel()); - assertEquals(6, cols.getColArray(2).getMin()); // 1 based - assertEquals(6, cols.getColArray(2).getMax()); // 1 based - assertFalse(cols.getColArray(2).getCustomWidth()); - - assertEquals(3, cols.sizeOfColArray()); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_MINOR"); - sheet = wb2.getSheet("test"); + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + CTCol col = cols.addNewCol(); + col.setMin(2 + 1); + col.setMax(4 + 1); + col.setWidth(20); + col.setCustomWidth(true); + + sheet.groupColumn((short) 3, (short) 5); + + cols = sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:" + cols); + + assertEquals(0, cols.getColArray(0).getOutlineLevel()); + assertEquals(3, cols.getColArray(0).getMin()); // 1 based + assertEquals(3, cols.getColArray(0).getMax()); // 1 based + assertTrue(cols.getColArray(0).getCustomWidth()); + + assertEquals(1, cols.getColArray(1).getOutlineLevel()); + assertEquals(4, cols.getColArray(1).getMin()); // 1 based + assertEquals(5, cols.getColArray(1).getMax()); // 1 based + assertTrue(cols.getColArray(1).getCustomWidth()); + + assertEquals(1, cols.getColArray(2).getOutlineLevel()); + assertEquals(6, cols.getColArray(2).getMin()); // 1 based + assertEquals(6, cols.getColArray(2).getMax()); // 1 based + assertFalse(cols.getColArray(2).getCustomWidth()); + + assertEquals(3, cols.sizeOfColArray()); + + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_MINOR")) { + sheet = wb2.getSheet("test"); + + for (int i = 2; i <= 4; i++) { + assertEquals(20 * 256L, sheet.getColumnWidth(i), "Unexpected width of column " + i); + } + assertEquals(sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(5), "Unexpected width of column " + 5); - for (int i = 2; i <= 4; i++) { - assertEquals("Unexpected width of column "+ i, 20 * 256L, sheet.getColumnWidth(i)); + } } - assertEquals("Unexpected width of column "+ 5, sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(5)); - - wb2.close(); - wb1.close(); } /** @@ -257,48 +257,48 @@ public class TestXSSFColGrouping { */ @Test public void testMergingOverlappingCols_OVERLAPS_2_MINOR() throws IOException { - XSSFWorkbook wb1 = new XSSFWorkbook(); - XSSFSheet sheet = wb1.createSheet("test"); - - CTCols cols = sheet.getCTWorksheet().getColsArray(0); - CTCol col = cols.addNewCol(); - col.setMin(2 + 1); - col.setMax(4 + 1); - col.setWidth(20); - col.setCustomWidth(true); - - sheet.groupColumn((short) 1, (short) 3); - - cols = sheet.getCTWorksheet().getColsArray(0); - logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:" + cols); - - assertEquals(1, cols.getColArray(0).getOutlineLevel()); - assertEquals(2, cols.getColArray(0).getMin()); // 1 based - assertEquals(2, cols.getColArray(0).getMax()); // 1 based - assertFalse(cols.getColArray(0).getCustomWidth()); - - assertEquals(1, cols.getColArray(1).getOutlineLevel()); - assertEquals(3, cols.getColArray(1).getMin()); // 1 based - assertEquals(4, cols.getColArray(1).getMax()); // 1 based - assertTrue(cols.getColArray(1).getCustomWidth()); - - assertEquals(0, cols.getColArray(2).getOutlineLevel()); - assertEquals(5, cols.getColArray(2).getMin()); // 1 based - assertEquals(5, cols.getColArray(2).getMax()); // 1 based - assertTrue(cols.getColArray(2).getCustomWidth()); + try (XSSFWorkbook wb1 = new XSSFWorkbook()) { + XSSFSheet sheet = wb1.createSheet("test"); - assertEquals(3, cols.sizeOfColArray()); + CTCols cols = sheet.getCTWorksheet().getColsArray(0); + CTCol col = cols.addNewCol(); + col.setMin(2 + 1); + col.setMax(4 + 1); + col.setWidth(20); + col.setCustomWidth(true); + + sheet.groupColumn((short) 1, (short) 3); + + cols = sheet.getCTWorksheet().getColsArray(0); + logger.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:" + cols); + + assertEquals(1, cols.getColArray(0).getOutlineLevel()); + assertEquals(2, cols.getColArray(0).getMin()); // 1 based + assertEquals(2, cols.getColArray(0).getMax()); // 1 based + assertFalse(cols.getColArray(0).getCustomWidth()); + + assertEquals(1, cols.getColArray(1).getOutlineLevel()); + assertEquals(3, cols.getColArray(1).getMin()); // 1 based + assertEquals(4, cols.getColArray(1).getMax()); // 1 based + assertTrue(cols.getColArray(1).getCustomWidth()); + + assertEquals(0, cols.getColArray(2).getOutlineLevel()); + assertEquals(5, cols.getColArray(2).getMin()); // 1 based + assertEquals(5, cols.getColArray(2).getMax()); // 1 based + assertTrue(cols.getColArray(2).getCustomWidth()); + + assertEquals(3, cols.sizeOfColArray()); + + try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_MINOR")) { + sheet = wb2.getSheet("test"); + + for (int i = 2; i <= 4; i++) { + assertEquals(20 * 256L, sheet.getColumnWidth(i), "Unexpected width of column " + i); + } + assertEquals(sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(1), "Unexpected width of column " + 1); - XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_MINOR"); - sheet = wb2.getSheet("test"); - - for (int i = 2; i <= 4; i++) { - assertEquals("Unexpected width of column "+ i, 20 * 256L, sheet.getColumnWidth(i)); + } } - assertEquals("Unexpected width of column "+ 1, sheet.getDefaultColumnWidth() * 256L, sheet.getColumnWidth(1)); - - wb2.close(); - wb1.close(); } }
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColor.java Thu Dec 24 18:42:29 2020 @@ -17,20 +17,20 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColors; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRgbColor; public final class TestXSSFColor { - + @Test public void testIndexedColour() throws Exception { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx")) { @@ -181,7 +181,7 @@ public final class TestXSSFColor { assertEquals(102, rgb4.getRGBWithTint()[2]); } } - + @Test public void testCustomIndexedColour() throws Exception { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("customIndexedColors.xlsx")) { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java Thu Dec 24 18:42:29 2020 @@ -18,13 +18,14 @@ package org.apache.poi.xssf.usermodel; import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_SPREADSHEETML; -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.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.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.FileOutputStream; import java.io.IOException; @@ -49,8 +50,8 @@ import org.apache.poi.xssf.XSSFTestDataS import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.xmlbeans.XmlObject; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; @@ -131,12 +132,9 @@ public final class TestXSSFComment exten XSSFComment comment = sh.createDrawingPatriarch().createCellComment(new XSSFClientAnchor()); //passing HSSFRichTextString is incorrect - try { - comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING)); - fail("expected exception"); - } catch (IllegalArgumentException e){ - assertEquals("Only XSSFRichTextString argument is supported", e.getMessage()); - } + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, + () -> comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING))); + assertEquals("Only XSSFRichTextString argument is supported", e.getMessage()); //simple string argument comment.setString(TEST_RICHTEXTSTRING); @@ -174,7 +172,7 @@ public final class TestXSSFComment exten assertEquals(8.5, rPr.getSzArray(0).getVal(), 0); assertEquals(IndexedColors.BLUE_GREY.getIndex(), rPr.getColorArray(0).getIndexed()); assertEquals("Tahoma", rPr.getRFontArray(0).getVal()); - + assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); } @@ -198,7 +196,7 @@ public final class TestXSSFComment exten @Test public void testBug58175() throws IOException { - try (Workbook wb = new SXSSFWorkbook()) { + try (SXSSFWorkbook wb = new SXSSFWorkbook()) { Sheet sheet = wb.createSheet(); Row row = sheet.createRow(1); @@ -218,9 +216,9 @@ public final class TestXSSFComment exten XSSFClientAnchor ca = (XSSFClientAnchor) anchor; // create comments and vmlDrawing parts if they don't exist - CommentsTable comments = ((SXSSFWorkbook) wb).getXSSFWorkbook() + CommentsTable comments = wb.getXSSFWorkbook() .getSheetAt(0).getCommentsTable(true); - XSSFVMLDrawing vml = ((SXSSFWorkbook) wb).getXSSFWorkbook() + XSSFVMLDrawing vml = wb.getXSSFWorkbook() .getSheetAt(0).getVMLDrawing(true); CTShape vmlShape1 = vml.newCommentShape(); if (ca.isSet()) { @@ -259,12 +257,12 @@ public final class TestXSSFComment exten assertEquals(table1.getNumberOfComments(), table2.getNumberOfComments()); assertEquals(table1.getRelations(), table2.getRelations());*/ - assertEquals("The vmlShapes should have equal content afterwards", - vmlShape1.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000"), vmlShape2.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000")); + assertEquals(vmlShape1.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000"), vmlShape2.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000"), + "The vmlShapes should have equal content afterwards"); } } - @Ignore("Used for manual testing with opening the resulting Workbook in Excel") + @Disabled("Used for manual testing with opening the resulting Workbook in Excel") @Test public void testBug58175a() throws IOException { try (Workbook wb = new SXSSFWorkbook()) { @@ -323,7 +321,7 @@ public final class TestXSSFComment exten //wb.write(new FileOutputStream("/tmp/outnocomment.xlsx")); comment = newsheet.getRow(0).getCell(0).getCellComment(); - assertNotNull("Should have a comment on A1 in the new sheet", comment); + assertNotNull(comment, "Should have a comment on A1 in the new sheet"); assertEquals("Comment Here\n", comment.getString().getString()); Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java Thu Dec 24 18:42:29 2020 @@ -18,8 +18,8 @@ */ package org.apache.poi.xssf.usermodel; -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; @@ -35,7 +35,7 @@ import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.XSSFITestDataProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * XSSF-specific Conditional Formatting tests @@ -47,13 +47,13 @@ public class TestXSSFConditionalFormatti } @Override - protected void assertColour(String hexExpected, Color actual) { - assertNotNull("Colour must be given", actual); - XSSFColor colour = (XSSFColor)actual; + protected void assertColor(String hexExpected, Color actual) { + assertNotNull(actual, "Color must be given"); + XSSFColor color = (XSSFColor)actual; if (hexExpected.length() == 8) { - assertEquals(hexExpected, colour.getARGBHex()); + assertEquals(hexExpected, color.getARGBHex()); } else { - assertEquals(hexExpected, colour.getARGBHex().substring(2)); + assertEquals(hexExpected, color.getARGBHex().substring(2)); } } @@ -61,7 +61,7 @@ public class TestXSSFConditionalFormatti public void testRead() throws IOException { testRead("WithConditionalFormatting.xlsx"); } - + @Test public void testReadOffice2007() throws IOException { testReadOffice2007("NewStyleConditionalFormattings.xlsx"); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java Thu Dec 24 18:42:29 2020 @@ -17,18 +17,16 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; -import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.formula.ConditionalFormattingEvaluator; import org.apache.poi.ss.formula.WorkbookEvaluatorProvider; import org.apache.poi.ss.usermodel.BaseTestDataFormat; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.FormulaEvaluator; @@ -36,7 +34,7 @@ import org.apache.poi.ss.usermodel.Workb import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link XSSFDataFormat} @@ -55,7 +53,7 @@ public final class TestXSSFDataFormat ex public void test49928() throws IOException { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx"); doTest49928Core(wb); - + DataFormat dataFormat = wb.createDataFormat(); // As of 2015-12-27, there is no way to override a built-in number format with POI XSSFWorkbook @@ -64,18 +62,18 @@ public final class TestXSSFDataFormat ex assertEquals(poundFmtIdx, dataFormat.getFormat(poundFmt)); // now create a custom format with Pound (\u00a3) - + String customFmt = "\u00a3##.00[Yellow]"; assertNotBuiltInFormat(customFmt); short customFmtIdx = dataFormat.getFormat(customFmt); assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX); assertEquals(customFmt, dataFormat.getFormat(customFmtIdx)); - + wb.close(); } - + /** - * [Bug 58532] Handle formats that go numnum, numK, numM etc + * [Bug 58532] Handle formats that go numnum, numK, numM etc */ @Override @Test @@ -84,7 +82,7 @@ public final class TestXSSFDataFormat ex doTest58532Core(wb); wb.close(); } - + /** * [Bug 58778] Built-in number formats can be overridden with XSSFDataFormat.putFormat(int id, String fmt) */ @@ -94,23 +92,23 @@ public final class TestXSSFDataFormat ex Cell cell = wb1.createSheet("bug58778").createRow(0).createCell(0); cell.setCellValue(5.25); CellStyle style = wb1.createCellStyle(); - + XSSFDataFormat dataFormat = wb1.createDataFormat(); - + short poundFmtIdx = 6; dataFormat.putFormat(poundFmtIdx, poundFmt); style.setDataFormat(poundFmtIdx); cell.setCellStyle(style); // Cell should appear as "<poundsymbol>5" - + XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutCloseAndReadBack(wb1); cell = wb2.getSheet("bug58778").getRow(0).getCell(0); assertEquals(5.25, cell.getNumericCellValue(), 0); - + style = cell.getCellStyle(); assertEquals(poundFmt, style.getDataFormatString()); assertEquals(poundFmtIdx, style.getDataFormat()); - + // manually check the file to make sure the cell is rendered as "<poundsymbol>5" // Verified with LibreOffice 4.2.8.2 on 2015-12-28 wb2.close(); @@ -136,17 +134,17 @@ public final class TestXSSFDataFormat ex assertEquals("-2.00E+03", formatter.formatCellValue(cell, evaluator, cfEvaluator)); // verify cell format without the conditional rule applied assertEquals("-2000", formatter.formatCellValue(cell, evaluator)); - + ref = new CellReference("A4"); cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); assertEquals("100", formatter.formatCellValue(cell, evaluator, cfEvaluator)); - + ref = new CellReference("A5"); cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); assertEquals("$1,000", formatter.formatCellValue(cell, evaluator, cfEvaluator)); // verify cell format without the conditional rule applied assertEquals("1000", formatter.formatCellValue(cell, evaluator)); - + wb.close(); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java Thu Dec 24 18:42:29 2020 @@ -16,9 +16,9 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; -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.IOException; import java.math.BigDecimal; @@ -40,7 +40,7 @@ import org.apache.poi.ss.util.CellRangeA import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestXSSFDataValidation extends BaseTestDataValidation { @@ -51,24 +51,23 @@ public class TestXSSFDataValidation exte @Test public void testAddValidations() throws Exception { XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("DataValidations-49244.xlsx"); - Sheet sheet = wb1.getSheetAt(0); - List<XSSFDataValidation> dataValidations = ((XSSFSheet)sheet).getDataValidations(); + XSSFSheet sheet = wb1.getSheetAt(0); + List<XSSFDataValidation> dataValidations = sheet.getDataValidations(); + + // For each validation type, there are two cells with the same validation. This tests + // application of a single validation definition to multiple cells. + // + // For list ( 3 validations for explicit and 3 for formula ) + // - one validation that allows blank. + // - one that does not allow blank. + // - one that does not show the drop down arrow. + // = 2 + // + // For number validations ( integer/decimal and text length ) with 8 different types of operators. + // = 50 + // + // = 52 ( Total ) -/** - * For each validation type, there are two cells with the same validation. This tests - * application of a single validation definition to multiple cells. - * - * For list ( 3 validations for explicit and 3 for formula ) - * - one validation that allows blank. - * - one that does not allow blank. - * - one that does not show the drop down arrow. - * = 2 - * - * For number validations ( integer/decimal and text length ) with 8 different types of operators. - * = 50 - * - * = 52 ( Total ) - */ assertEquals(52,dataValidations.size()); DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); @@ -111,7 +110,7 @@ public class TestXSSFDataValidation exte Cell thirdCell = row.createCell(3);thirdCell.setCellValue("IL"); int rowNum = row.getRowNum() + 1; - String listFormula = new StringBuilder("$B$").append(rowNum).append(":").append("$D$").append(rowNum).toString(); + String listFormula = "$B$" + rowNum + ":" + "$D$" + rowNum; DataValidationConstraint formulaListValidation = dataValidationHelper.createFormulaListConstraint(listFormula); dataValidation = dataValidationHelper.createValidation(formulaListValidation, cellRangeAddressList); @@ -153,7 +152,7 @@ public class TestXSSFDataValidation exte DataValidation validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters(validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations,((XSSFSheet)sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); //Now create real formula based validation. String formula1 = new CellReference(cell_13.getRowIndex(),cell_13.getColumnIndex()).formatAsString(); @@ -164,7 +163,7 @@ public class TestXSSFDataValidation exte validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters(validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations, ((XSSFSheet) sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); cellRangeAddressList = new CellRangeAddressList(); if (cell_22 != null) { @@ -173,7 +172,7 @@ public class TestXSSFDataValidation exte validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters( validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations, ((XSSFSheet) sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); } else if(i==0 && j==1 ){ cellRangeAddressList = new CellRangeAddressList(); cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_21.getRowIndex(), cell_21.getRowIndex(), cell_21.getColumnIndex(), cell_21.getColumnIndex())); @@ -183,14 +182,14 @@ public class TestXSSFDataValidation exte validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters( validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations, ((XSSFSheet) sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); } else { cellRangeAddressList = new CellRangeAddressList(); cellRangeAddressList.addCellRangeAddress(new CellRangeAddress(cell_21.getRowIndex(), cell_21.getRowIndex(), cell_21.getColumnIndex(), cell_21.getColumnIndex())); validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters(validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations, ((XSSFSheet) sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); } } @@ -221,7 +220,7 @@ public class TestXSSFDataValidation exte DataValidation validation = dataValidationHelper.createValidation(constraint, cellRangeAddressList); setOtherValidationParameters(validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations,((XSSFSheet)sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); //Now create real formula based validation. @@ -234,14 +233,14 @@ public class TestXSSFDataValidation exte setOtherValidationParameters(validation); sheet.addValidationData(validation); - assertEquals(++lastKnownNumValidations,((XSSFSheet)sheet).getDataValidations().size()); + assertEquals(++lastKnownNumValidations, sheet.getDataValidations().size()); } } XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1); wb1.close(); - Sheet sheetAt = wb2.getSheetAt(0); - assertEquals(lastKnownNumValidations,((XSSFSheet)sheetAt).getDataValidations().size()); + XSSFSheet sheetAt = wb2.getSheetAt(0); + assertEquals(lastKnownNumValidations, sheetAt.getDataValidations().size()); wb2.close(); } @@ -376,7 +375,7 @@ public class TestXSSFDataValidation exte XSSFFormulaEvaluator fEval = wb.getCreationHelper().createFormulaEvaluator(); DataValidationEvaluator dve = new DataValidationEvaluator(wb, fEval); List<ValueEval> values = dve.getValidationValuesForCell(new CellReference("County Ranking", 8, 6, false, false)); - assertEquals("wrong # of valid values", 32, values.size()); + assertEquals(32, values.size(), "wrong # of valid values"); } } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java Thu Dec 24 18:42:29 2020 @@ -16,7 +16,7 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.apache.poi.ss.formula.DataValidationEvaluator; import org.apache.poi.ss.usermodel.DataValidationConstraint; @@ -24,7 +24,7 @@ import org.apache.poi.ss.usermodel.DataV import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType; import org.apache.poi.ss.util.CellReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.stream.IntStream; Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java Thu Dec 24 18:42:29 2020 @@ -17,17 +17,17 @@ package org.apache.poi.xssf.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.assertTrue; +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.assertTrue; import java.io.IOException; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet; Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Thu Dec 24 18:42:29 2020 @@ -24,10 +24,9 @@ import org.apache.poi.ss.usermodel.Clien import org.apache.poi.ss.usermodel.FontUnderline; import org.apache.poi.ss.usermodel.ShapeTypes; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.util.Units; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; @@ -35,21 +34,17 @@ import org.openxmlformats.schemas.drawin import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; import java.awt.*; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TestXSSFDrawing { @Test public void bug54803() throws Exception { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("bug54803.xlsx")) { XSSFSheet sheet = wb.getSheetAt(0); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); + sheet.createDrawingPatriarch(); XSSFTestDataSamples.writeOutAndReadBack(wb).close(); } } @@ -835,22 +830,19 @@ public class TestXSSFDrawing { wb2.close(); } - @Test(expected=IllegalArgumentException.class) + @Test public void testBug56835CellComment() throws IOException { - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + + // first comment works + ClientAnchor anchor = new XSSFClientAnchor(1, 1, 2, 2, 3, 3, 4, 4); + XSSFComment comment = drawing.createCellComment(anchor); + assertNotNull(comment); - // first comment works - ClientAnchor anchor = new XSSFClientAnchor(1, 1, 2, 2, 3, 3, 4, 4); - XSSFComment comment = drawing.createCellComment(anchor); - assertNotNull(comment); - - // Should fail if we try to add the same comment for the same cell - try { - drawing.createCellComment(anchor); - } finally { - wb.close(); + // Should fail if we try to add the same comment for the same cell + assertThrows(IllegalArgumentException.class, () -> drawing.createCellComment(anchor)); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvaluationSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvaluationSheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvaluationSheet.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvaluationSheet.java Thu Dec 24 18:42:29 2020 @@ -16,17 +16,17 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; -import org.apache.poi.ss.formula.EvaluationSheet; -import org.apache.poi.ss.usermodel.BaseTestXEvaluationSheet; -import org.apache.poi.ss.usermodel.Sheet; -import org.junit.Test; +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 java.util.AbstractMap; import java.util.Map; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.poi.ss.formula.EvaluationSheet; +import org.apache.poi.ss.usermodel.BaseTestXEvaluationSheet; +import org.apache.poi.ss.usermodel.Sheet; +import org.junit.jupiter.api.Test; public class TestXSSFEvaluationSheet extends BaseTestXEvaluationSheet { @@ -38,24 +38,24 @@ public class TestXSSFEvaluationSheet ext row.createCell(0); XSSFEvaluationSheet evalsheet = new XSSFEvaluationSheet(sheet); - assertNotNull("Cell 0,0 is found", evalsheet.getCell(0, 0)); - assertNull("Cell 0,1 is not found", evalsheet.getCell(0, 1)); - assertNull("Cell 1,0 is not found", evalsheet.getCell(1, 0)); + assertNotNull(evalsheet.getCell(0, 0), "Cell 0,0 is found"); + assertNull(evalsheet.getCell(0, 1), "Cell 0,1 is not found"); + assertNull(evalsheet.getCell(1, 0), "Cell 1,0 is not found"); // now add Cell 0,1 row.createCell(1); - assertNotNull("Cell 0,0 is found", evalsheet.getCell(0, 0)); - assertNotNull("Cell 0,1 is now also found", evalsheet.getCell(0, 1)); - assertNull("Cell 1,0 is not found", evalsheet.getCell(1, 0)); + assertNotNull(evalsheet.getCell(0, 0), "Cell 0,0 is found"); + assertNotNull(evalsheet.getCell(0, 1), "Cell 0,1 is now also found"); + assertNull(evalsheet.getCell(1, 0), "Cell 1,0 is not found"); // after clearing all values it also works row.createCell(2); evalsheet.clearAllCachedResultValues(); - assertNotNull("Cell 0,0 is found", evalsheet.getCell(0, 0)); - assertNotNull("Cell 0,2 is now also found", evalsheet.getCell(0, 2)); - assertNull("Cell 1,0 is not found", evalsheet.getCell(1, 0)); + assertNotNull(evalsheet.getCell(0, 0), "Cell 0,0 is found"); + assertNotNull(evalsheet.getCell(0, 2), "Cell 0,2 is now also found"); + assertNull(evalsheet.getCell(1, 0), "Cell 1,0 is not found"); // other things assertEquals(sheet, evalsheet.getXSSFSheet()); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenFooter.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -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 TestXSSFEvenFooter { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFEvenHeader.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -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 TestXSSFEvenHeader { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstFooter.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -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 TestXSSFFirstFooter { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFirstHeader.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -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 TestXSSFFirstHeader { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java Thu Dec 24 18:42:29 2020 @@ -17,7 +17,7 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; @@ -34,7 +34,7 @@ import org.apache.poi.ss.util.SheetUtil; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; @@ -107,29 +107,24 @@ public final class TestXSSFFont extends // This one isn't allowed assertNull(org.apache.poi.ss.usermodel.FontCharset.valueOf(9999)); - try { - xssfFont.setCharSet(9999); - fail("Shouldn't be able to set an invalid charset"); - } catch(POIXMLException e) { - // expected here - } - + assertThrows(POIXMLException.class, () -> xssfFont.setCharSet(9999), + "Shouldn't be able to set an invalid charset"); // Now try with a few sample files // Normal charset - XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); - assertEquals(0, - wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet() - ); - wb1.close(); + try (XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx")) { + assertEquals(0, + wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet() + ); + } // GB2312 charset - XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx"); - assertEquals(134, - wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet() - ); - wb2.close(); + try (XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx")) { + assertEquals(134, + wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet() + ); + } } @Test @@ -157,12 +152,7 @@ public final class TestXSSFFont extends // This one isn't allowed assertNull(FontCharset.valueOf(9999)); - try { - xssfFont.setCharSet(9999); - fail("Shouldn't be able to set an invalid charset"); - } catch(POIXMLException e) { - // expected here - } + assertThrows(POIXMLException.class, () -> xssfFont.setCharSet(9999), "Shouldn't be able to set an invalid charset"); // Now try with a few sample files Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java Thu Dec 24 18:42:29 2020 @@ -17,10 +17,11 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -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.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.HashMap; @@ -37,8 +38,8 @@ import org.apache.poi.ss.usermodel.Workb import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator { @@ -104,12 +105,12 @@ public final class TestXSSFFormulaEvalua CellValue cv_noformula = evaluator.evaluate(cell_noformula); CellValue cv_formula = evaluator.evaluate(cell_formula); - assertEquals("Wrong evaluation result in " + ref_formula.formatAsString(), - cv_noformula.getNumberValue(), cv_formula.getNumberValue(), 0); + assertEquals(cv_noformula.getNumberValue(), cv_formula.getNumberValue(), 0, + "Wrong evaluation result in " + ref_formula.formatAsString()); } } } - + /** * Related to bugs #56737 and #56752 - XSSF workbooks which have * formulas that refer to cells and named ranges in multiple other @@ -149,74 +150,56 @@ public final class TestXSSFFormulaEvalua // Try to evaluate without references, won't work // (At least, not unit we fix bug #56752 that is) - try { - evaluator.evaluate(cXSL_cell); - fail("Without a fix for #56752, shouldn't be able to evaluate a " + - "reference to a non-provided linked workbook"); - } catch (Exception e) { - // expected here - } + assertThrows(Exception.class, () -> evaluator.evaluate(cXSL_cell), + "Without a fix for #56752, shouldn't be able to evaluate a reference to a non-provided linked workbook"); // Setup the environment Map<String, FormulaEvaluator> evaluators = new HashMap<>(); evaluators.put("ref2-56737.xlsx", evaluator); - Workbook wbEval1 = _testDataProvider.openSampleWorkbook("56737.xlsx"); - evaluators.put("56737.xlsx", - wbEval1.getCreationHelper().createFormulaEvaluator()); - Workbook wbEval2 = HSSFTestDataSamples.openSampleWorkbook("56737.xls"); - evaluators.put("56737.xls", - wbEval2.getCreationHelper().createFormulaEvaluator()); - evaluator.setupReferencedWorkbooks(evaluators); - - // Try evaluating all of them, ensure we don't blow up - for (Row r : s) { - for (Cell c : r) { - evaluator.evaluate(c); + try (Workbook wbEval1 = _testDataProvider.openSampleWorkbook("56737.xlsx"); + Workbook wbEval2 = HSSFTestDataSamples.openSampleWorkbook("56737.xls")) { + evaluators.put("56737.xlsx", wbEval1.getCreationHelper().createFormulaEvaluator()); + evaluators.put("56737.xls", wbEval2.getCreationHelper().createFormulaEvaluator()); + evaluator.setupReferencedWorkbooks(evaluators); + + // Try evaluating all of them, ensure we don't blow up + for (Row r : s) { + for (Cell c : r) { + evaluator.evaluate(c); + } } - } - // And evaluate the other way too - evaluator.evaluateAll(); + // And evaluate the other way too + evaluator.evaluateAll(); - // Static evaluator won't work, as no references passed in - try { - XSSFFormulaEvaluator.evaluateAllFormulaCells(wb); - fail("Static method lacks references, shouldn't work"); - } catch (Exception e) { - // expected here + // Static evaluator won't work, as no references passed in + assertThrows(Exception.class, () -> XSSFFormulaEvaluator.evaluateAllFormulaCells(wb), + "Static method lacks references, shouldn't work"); + + // Evaluate specific cells and check results + assertEquals("\"Hello!\"", evaluator.evaluate(cXSLX_cell).formatAsString()); + assertEquals("\"Test A1\"", evaluator.evaluate(cXSLX_sNR).formatAsString()); + assertEquals("142.0", evaluator.evaluate(cXSLX_gNR).formatAsString()); + + assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell).formatAsString()); + assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString()); + assertEquals("142.0", evaluator.evaluate(cXSL_gNR).formatAsString()); + + + // Add another formula referencing these workbooks + Cell cXSL_cell2 = rXSL.createCell(40); + cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1"); + // TODO Shouldn't it become [2] like the others? + assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula()); + assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell2).formatAsString()); + + + // Now add a formula that refers to yet another (different) workbook + // Won't work without the workbook being linked + Cell cXSLX_nw_cell = rXSLX.createCell(42); + assertThrows(Exception.class, () -> cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1"), + "New workbook not linked, shouldn't be able to add"); } - - // Evaluate specific cells and check results - assertEquals("\"Hello!\"", evaluator.evaluate(cXSLX_cell).formatAsString()); - assertEquals("\"Test A1\"", evaluator.evaluate(cXSLX_sNR).formatAsString()); - assertEquals("142.0", evaluator.evaluate(cXSLX_gNR).formatAsString()); - - assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell).formatAsString()); - assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString()); - assertEquals("142.0", evaluator.evaluate(cXSL_gNR).formatAsString()); - - - // Add another formula referencing these workbooks - Cell cXSL_cell2 = rXSL.createCell(40); - cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1"); - // TODO Shouldn't it become [2] like the others? - assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula()); - assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell2).formatAsString()); - - - // Now add a formula that refers to yet another (different) workbook - // Won't work without the workbook being linked - Cell cXSLX_nw_cell = rXSLX.createCell(42); - try { - cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1"); - fail("New workbook not linked, shouldn't be able to add"); - } catch (Exception e) { - // expected here - } - - wbEval1.close(); - wbEval2.close(); - // Link and re-try try (Workbook alt = new XSSFWorkbook()) { alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook"); @@ -229,10 +212,8 @@ public final class TestXSSFFormulaEvalua assertEquals("[alt.xlsx]Sheet1!$A$1", cXSLX_nw_cell.getCellFormula()); // Evaluate it, without a link to that workbook - try { - evaluator.evaluate(cXSLX_nw_cell); - fail("No cached value and no link to workbook, shouldn't evaluate"); - } catch(Exception e) {} + assertThrows(Exception.class, () -> evaluator.evaluate(cXSLX_nw_cell), + "No cached value and no link to workbook, shouldn't evaluate"); // Add a link, check it does evaluators.put("alt.xlsx", alt.getCreationHelper().createFormulaEvaluator()); @@ -244,7 +225,7 @@ public final class TestXSSFFormulaEvalua } } } - + /** * If a formula references cells or named ranges in another workbook, * but that isn't available at evaluation time, the cached values @@ -252,13 +233,10 @@ public final class TestXSSFFormulaEvalua * TODO Add the support then add a unit test * See bug #56752 */ - @Test - @Ignore + @Disabled public void testCachedReferencesToOtherWorkbooks() { - // TODO - fail("unit test not written yet"); } - + /** * A handful of functions (such as SUM, COUNTA, MIN) support * multi-sheet references (eg Sheet1:Sheet3!A1 = Cell A1 from @@ -275,57 +253,57 @@ public final class TestXSSFFormulaEvalua FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); Sheet s1 = wb.getSheetAt(0); - + // Simple SUM over numbers Cell sumF = s1.getRow(2).getCell(0); assertNotNull(sumF); assertEquals("SUM(Sheet1:Sheet3!A1)", sumF.getCellFormula()); - assertEquals("Failed for " + wb.getClass(), "66.0", evaluator.evaluate(sumF).formatAsString()); - - + assertEquals("66.0", evaluator.evaluate(sumF).formatAsString(), "Failed for " + wb.getClass()); + + // Various Stats formulas on numbers Cell avgF = s1.getRow(2).getCell(1); assertNotNull(avgF); assertEquals("AVERAGE(Sheet1:Sheet3!A1)", avgF.getCellFormula()); assertEquals("22.0", evaluator.evaluate(avgF).formatAsString()); - + Cell minF = s1.getRow(3).getCell(1); assertNotNull(minF); assertEquals("MIN(Sheet1:Sheet3!A$1)", minF.getCellFormula()); assertEquals("11.0", evaluator.evaluate(minF).formatAsString()); - + Cell maxF = s1.getRow(4).getCell(1); assertNotNull(maxF); assertEquals("MAX(Sheet1:Sheet3!A$1)", maxF.getCellFormula()); assertEquals("33.0", evaluator.evaluate(maxF).formatAsString()); - + Cell countF = s1.getRow(5).getCell(1); assertNotNull(countF); assertEquals("COUNT(Sheet1:Sheet3!A$1)", countF.getCellFormula()); assertEquals("3.0", evaluator.evaluate(countF).formatAsString()); - - + + // Various CountAs on Strings Cell countA_1F = s1.getRow(2).getCell(2); assertNotNull(countA_1F); assertEquals("COUNTA(Sheet1:Sheet3!C1)", countA_1F.getCellFormula()); assertEquals("3.0", evaluator.evaluate(countA_1F).formatAsString()); - + Cell countA_2F = s1.getRow(2).getCell(3); assertNotNull(countA_2F); assertEquals("COUNTA(Sheet1:Sheet3!D1)", countA_2F.getCellFormula()); assertEquals("0.0", evaluator.evaluate(countA_2F).formatAsString()); - + Cell countA_3F = s1.getRow(2).getCell(4); assertNotNull(countA_3F); assertEquals("COUNTA(Sheet1:Sheet3!E1)", countA_3F.getCellFormula()); assertEquals("3.0", evaluator.evaluate(countA_3F).formatAsString()); } - + wb2.close(); wb1.close(); } - + /** * A handful of functions (such as SUM, COUNTA, MIN) support * multi-sheet areas (eg Sheet1:Sheet3!A1:B2 = Cell A1 to Cell B2, @@ -342,36 +320,36 @@ public final class TestXSSFFormulaEvalua FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); Sheet s1 = wb.getSheetAt(0); - + // SUM over a range Cell sumFA = s1.getRow(2).getCell(7); assertNotNull(sumFA); assertEquals("SUM(Sheet1:Sheet3!A1:B2)", sumFA.getCellFormula()); - assertEquals("Failed for " + wb.getClass(), "110.0", evaluator.evaluate(sumFA).formatAsString()); + assertEquals("110.0", evaluator.evaluate(sumFA).formatAsString(), "Failed for " + wb.getClass()); + - // Various Stats formulas on ranges of numbers Cell avgFA = s1.getRow(2).getCell(8); assertNotNull(avgFA); assertEquals("AVERAGE(Sheet1:Sheet3!A1:B2)", avgFA.getCellFormula()); assertEquals("27.5", evaluator.evaluate(avgFA).formatAsString()); - + Cell minFA = s1.getRow(3).getCell(8); assertNotNull(minFA); assertEquals("MIN(Sheet1:Sheet3!A$1:B$2)", minFA.getCellFormula()); assertEquals("11.0", evaluator.evaluate(minFA).formatAsString()); - + Cell maxFA = s1.getRow(4).getCell(8); assertNotNull(maxFA); assertEquals("MAX(Sheet1:Sheet3!A$1:B$2)", maxFA.getCellFormula()); assertEquals("44.0", evaluator.evaluate(maxFA).formatAsString()); - + Cell countFA = s1.getRow(5).getCell(8); assertNotNull(countFA); assertEquals("COUNT(Sheet1:Sheet3!$A$1:$B$2)", countFA.getCellFormula()); assertEquals("4.0", evaluator.evaluate(countFA).formatAsString()); } - + wb2.close(); wb1.close(); } @@ -381,9 +359,9 @@ public final class TestXSSFFormulaEvalua public void structuredReferences() throws IOException { verifyAllFormulasInWorkbookCanBeEvaluated("evaluate_formula_with_structured_table_references.xlsx"); } - + // bug 57840 - @Ignore("Takes over a minute to evaluate all formulas in this large workbook. Run this test when profiling for formula evaluation speed.") + @Disabled("Takes over a minute to evaluate all formulas in this large workbook. Run this test when profiling for formula evaluation speed.") @Test public void testLotsOfFormulasWithStructuredReferencesToCalculatedTableColumns() throws IOException { verifyAllFormulasInWorkbookCanBeEvaluated("StructuredRefs-lots-with-lookups.xlsx"); @@ -412,7 +390,7 @@ public final class TestXSSFFormulaEvalua assertEquals(1, value.getNumberValue(), 0.001); } } - + @Test public void evaluateInCellReturnsSameDataType() throws IOException { try (XSSFWorkbook wb = new XSSFWorkbook()) { @@ -423,7 +401,7 @@ public final class TestXSSFFormulaEvalua assertSame(cell, same); } } - + @Test public void testBug61468() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("simple-monthly-budget.xlsx")) { @@ -435,9 +413,9 @@ public final class TestXSSFFormulaEvalua assertEquals(3750, value.getNumberValue(), 0.001); } } - + @Test - @Ignore // this is from an open bug/discussion over handling localization for number formats + @Disabled // this is from an open bug/discussion over handling localization for number formats public void testBug61495() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61495-test.xlsm")) { FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); @@ -453,7 +431,7 @@ public final class TestXSSFFormulaEvalua } } - + /** * see bug 62834, handle when a shared formula range doesn't contain only formula cells */ @@ -464,17 +442,17 @@ public final class TestXSSFFormulaEvalua Cell a2 = wb.getSheetAt(0).getRow(1).getCell(0); Cell value = evaluator.evaluateInCell(a2); - assertEquals("wrong value A2", "a value", value.getStringCellValue()); - + assertEquals("a value", value.getStringCellValue(), "wrong value A2"); + // evaluator.clearAllCachedResultValues(); - + Cell a3 = wb.getSheetAt(0).getRow(2).getCell(0); value = evaluator.evaluateInCell(a3); - assertEquals("wrong value A3", "a value", value.getStringCellValue()); - + assertEquals("a value", value.getStringCellValue(), "wrong value A3"); + Cell a5 = wb.getSheetAt(0).getRow(4).getCell(0); value = evaluator.evaluateInCell(a5); - assertEquals("wrong value A5", "another value", value.getStringCellValue()); + assertEquals("another value", value.getStringCellValue(), "wrong value A5"); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org