You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/12/27 23:00:20 UTC

svn commit: r1872041 [22/23] - in /poi/trunk/src: excelant/testcases/org/apache/poi/ss/examples/formula/ excelant/testcases/org/apache/poi/ss/excelant/ excelant/testcases/org/apache/poi/ss/excelant/util/ java/org/apache/poi/hssf/record/aggregates/ java...

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java Fri Dec 27 23:00:13 2019
@@ -24,8 +24,8 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.io.IOException;
 import java.util.Arrays;
@@ -40,9 +40,6 @@ import org.junit.Test;
 /**
  * Common superclass for testing usermodel API for array formulas.<br>
  * Formula evaluation is not tested here.
- *
- * @author Yegor Kozlov
- * @author Josh Micich
  */
 public abstract class BaseTestSheetUpdateArrayFormulas {
     protected final ITestDataProvider _testDataProvider;
@@ -53,23 +50,22 @@ public abstract class BaseTestSheetUpdat
 
     @Test
     public final void testAutoCreateOtherCells() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet1");
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet("Sheet1");
 
-        Row row1 = sheet.createRow(0);
-        Cell cellA1 = row1.createCell(0);
-        Cell cellB1 = row1.createCell(1);
-        String formula = "42";
-        sheet.setArrayFormula(formula, CellRangeAddress.valueOf("A1:B2"));
-
-        assertEquals(formula, cellA1.getCellFormula());
-        assertEquals(formula, cellB1.getCellFormula());
-        Row row2 = sheet.getRow(1);
-        assertNotNull(row2);
-        assertEquals(formula, row2.getCell(0).getCellFormula());
-        assertEquals(formula, row2.getCell(1).getCellFormula());
-        
-        workbook.close();
+            Row row1 = sheet.createRow(0);
+            Cell cellA1 = row1.createCell(0);
+            Cell cellB1 = row1.createCell(1);
+            String formula = "42";
+            sheet.setArrayFormula(formula, CellRangeAddress.valueOf("A1:B2"));
+
+            assertEquals(formula, cellA1.getCellFormula());
+            assertEquals(formula, cellB1.getCellFormula());
+            Row row2 = sheet.getRow(1);
+            assertNotNull(row2);
+            assertEquals(formula, row2.getCell(0).getCellFormula());
+            assertEquals(formula, row2.getCell(1).getCellFormula());
+        }
     }
 
     /**
@@ -77,36 +73,33 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public final void testSetArrayFormula_singleCell() throws IOException {
-        Cell[] cells;
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+            Cell cell = sheet.createRow(0).createCell(0);
+            assertFalse(cell.isPartOfArrayFormulaGroup());
+            try {
+                cell.getArrayFormulaRange();
+                fail("expected exception");
+            } catch (IllegalStateException e) {
+                assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
+            }
+
+            // row 3 does not yet exist
+            assertNull(sheet.getRow(2));
+            CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2);
+            Cell[] cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells();
+            assertEquals(1, cells.length);
+            // sheet.setArrayFormula creates rows and cells for the designated range
+            assertNotNull(sheet.getRow(2));
+            cell = sheet.getRow(2).getCell(2);
+            assertNotNull(cell);
 
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
-        Cell cell = sheet.createRow(0).createCell(0);
-        assertFalse(cell.isPartOfArrayFormulaGroup());
-        try {
-            cell.getArrayFormulaRange();
-            fail("expected exception");
-        } catch (IllegalStateException e){
-            assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
-        }
-
-        // row 3 does not yet exist
-        assertNull(sheet.getRow(2));
-        CellRangeAddress range = new CellRangeAddress(2, 2, 2, 2);
-        cells = sheet.setArrayFormula("SUM(C11:C12*D11:D12)", range).getFlattenedCells();
-        assertEquals(1, cells.length);
-        // sheet.setArrayFormula creates rows and cells for the designated range
-        assertNotNull(sheet.getRow(2));
-        cell = sheet.getRow(2).getCell(2);
-        assertNotNull(cell);
-
-        assertTrue(cell.isPartOfArrayFormulaGroup());
-        //retrieve the range and check it is the same
-        assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString());
-        //check the formula
-        assertEquals("SUM(C11:C12*D11:D12)", cell.getCellFormula());
-        
-        workbook.close();
+            assertTrue(cell.isPartOfArrayFormulaGroup());
+            //retrieve the range and check it is the same
+            assertEquals(range.formatAsString(), cell.getArrayFormulaRange().formatAsString());
+            //check the formula
+            assertEquals("SUM(C11:C12*D11:D12)", cell.getCellFormula());
+        }
     }
 
     /**
@@ -114,53 +107,45 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public final void testSetArrayFormula_multiCell() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        // multi-cell formula
-        // rows 3-5 don't exist yet
-        assertNull(sheet.getRow(3));
-        assertNull(sheet.getRow(4));
-        assertNull(sheet.getRow(5));
-
-        CellRangeAddress range = CellRangeAddress.valueOf("C4:C6");
-        Cell[] cells = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range).getFlattenedCells();
-        assertEquals(3, cells.length);
-
-        // sheet.setArrayFormula creates rows and cells for the designated range
-        assertSame(cells[0], sheet.getRow(3).getCell(2));
-        assertSame(cells[1], sheet.getRow(4).getCell(2));
-        assertSame(cells[2], sheet.getRow(5).getCell(2));
-
-        for(Cell acell : cells){
-            assertTrue(acell.isPartOfArrayFormulaGroup());
-            assertEquals(CellType.FORMULA, acell.getCellType());
-            assertEquals("SUM(A1:A3*B1:B3)", acell.getCellFormula());
-            //retrieve the range and check it is the same
-            assertEquals(range.formatAsString(), acell.getArrayFormulaRange().formatAsString());
+            // multi-cell formula
+            // rows 3-5 don't exist yet
+            assertNull(sheet.getRow(3));
+            assertNull(sheet.getRow(4));
+            assertNull(sheet.getRow(5));
+
+            CellRangeAddress range = CellRangeAddress.valueOf("C4:C6");
+            Cell[] cells = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range).getFlattenedCells();
+            assertEquals(3, cells.length);
+
+            // sheet.setArrayFormula creates rows and cells for the designated range
+            assertSame(cells[0], sheet.getRow(3).getCell(2));
+            assertSame(cells[1], sheet.getRow(4).getCell(2));
+            assertSame(cells[2], sheet.getRow(5).getCell(2));
+
+            for (Cell acell : cells) {
+                assertTrue(acell.isPartOfArrayFormulaGroup());
+                assertEquals(CellType.FORMULA, acell.getCellType());
+                assertEquals("SUM(A1:A3*B1:B3)", acell.getCellFormula());
+                //retrieve the range and check it is the same
+                assertEquals(range.formatAsString(), acell.getArrayFormulaRange().formatAsString());
+            }
         }
-        
-        workbook.close();
     }
 
     /**
      * Passing an incorrect formula to sheet.setArrayFormula
      *  should throw FormulaParseException
      */
-    @Test
+    @Test(expected = FormulaParseException.class)
     public final void testSetArrayFormula_incorrectFormula() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
-
-        try {
-            sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)",
-                    new CellRangeAddress(10, 10, 10, 10));
-            fail("expected exception");
-        } catch (FormulaParseException e){
-            //expected exception
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+            CellRangeAddress cra = new CellRangeAddress(10, 10, 10, 10);
+            sheet.setArrayFormula("incorrect-formula(C11_C12*D11_D12)", cra);
         }
-        
-        workbook.close();
     }
 
     /**
@@ -169,26 +154,25 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public final void testArrayFormulas_illegalCalls() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+
+            Cell cell = sheet.createRow(0).createCell(0);
+            assertFalse(cell.isPartOfArrayFormulaGroup());
+            try {
+                cell.getArrayFormulaRange();
+                fail("expected exception");
+            } catch (IllegalStateException e) {
+                assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
+            }
 
-        Cell cell = sheet.createRow(0).createCell(0);
-        assertFalse(cell.isPartOfArrayFormulaGroup());
-        try {
-            cell.getArrayFormulaRange();
-            fail("expected exception");
-        } catch (IllegalStateException e){
-            assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
-        }
-
-        try {
-            sheet.removeArrayFormula(cell);
-            fail("expected exception");
-        } catch (IllegalArgumentException e){
-            assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
+            try {
+                sheet.removeArrayFormula(cell);
+                fail("expected exception");
+            } catch (IllegalArgumentException e) {
+                assertEquals("Cell Sheet0!A1 is not part of an array formula.", e.getMessage());
+            }
         }
-        
-        workbook.close();
     }
 
     /**
@@ -196,37 +180,36 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public final void testRemoveArrayFormula() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        CellRangeAddress range = new CellRangeAddress(3, 5, 2, 2);
-        assertEquals("C4:C6", range.formatAsString());
-        CellRange<?> cr = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range);
-        assertEquals(3, cr.size());
-
-        // remove the formula cells in C4:C6
-        CellRange<?> dcells = sheet.removeArrayFormula(cr.getTopLeftCell());
-        // removeArrayFormula should return the same cells as setArrayFormula
-        assertArrayEquals(cr.getFlattenedCells(), dcells.getFlattenedCells());
-
-        for(Cell acell : cr){
-            assertFalse(acell.isPartOfArrayFormulaGroup());
-            assertEquals(CellType.BLANK, acell.getCellType());
-        }
-
-        // cells C4:C6 are not included in array formula,
-        // invocation of sheet.removeArrayFormula on any of them throws IllegalArgumentException
-        for(Cell acell : cr){
-            try {
-                sheet.removeArrayFormula(acell);
-                fail("expected exception");
-            } catch (IllegalArgumentException e){
-                String ref = new CellReference(acell).formatAsString();
-                assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage());
+            CellRangeAddress range = new CellRangeAddress(3, 5, 2, 2);
+            assertEquals("C4:C6", range.formatAsString());
+            CellRange<?> cr = sheet.setArrayFormula("SUM(A1:A3*B1:B3)", range);
+            assertEquals(3, cr.size());
+
+            // remove the formula cells in C4:C6
+            CellRange<?> dcells = sheet.removeArrayFormula(cr.getTopLeftCell());
+            // removeArrayFormula should return the same cells as setArrayFormula
+            assertArrayEquals(cr.getFlattenedCells(), dcells.getFlattenedCells());
+
+            for (Cell acell : cr) {
+                assertFalse(acell.isPartOfArrayFormulaGroup());
+                assertEquals(CellType.BLANK, acell.getCellType());
+            }
+
+            // cells C4:C6 are not included in array formula,
+            // invocation of sheet.removeArrayFormula on any of them throws IllegalArgumentException
+            for (Cell acell : cr) {
+                try {
+                    sheet.removeArrayFormula(acell);
+                    fail("expected exception");
+                } catch (IllegalArgumentException e) {
+                    String ref = new CellReference(acell).formatAsString();
+                    assertEquals("Cell " + ref + " is not part of an array formula.", e.getMessage());
+                }
             }
         }
-        
-        workbook.close();
     }
 
     /**
@@ -234,38 +217,35 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public final void testReadArrayFormula() throws IOException {
-        Cell[] cells;
-
-        Workbook workbook1 = _testDataProvider.createWorkbook();
-        Sheet sheet1 = workbook1.createSheet();
-        cells = sheet1.setArrayFormula("SUM(A1:A3*B1:B3)", CellRangeAddress.valueOf("C4:C6")).getFlattenedCells();
-        assertEquals(3, cells.length);
-
-        cells = sheet1.setArrayFormula("MAX(A1:A3*B1:B3)", CellRangeAddress.valueOf("A4:A6")).getFlattenedCells();
-        assertEquals(3, cells.length);
-
-        Sheet sheet2 = workbook1.createSheet();
-        cells = sheet2.setArrayFormula("MIN(A1:A3*B1:B3)", CellRangeAddress.valueOf("D2:D4")).getFlattenedCells();
-        assertEquals(3, cells.length);
-
-        Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook1);
-        workbook1.close();
-        sheet1 = workbook2.getSheetAt(0);
-        for(int rownum=3; rownum <= 5; rownum++) {
-            Cell cell1 = sheet1.getRow(rownum).getCell(2);
-            assertTrue( cell1.isPartOfArrayFormulaGroup());
-
-            Cell cell2 = sheet1.getRow(rownum).getCell(0);
-            assertTrue( cell2.isPartOfArrayFormulaGroup());
-        }
-
-        sheet2 = workbook2.getSheetAt(1);
-        for(int rownum=1; rownum <= 3; rownum++) {
-            Cell cell1 = sheet2.getRow(rownum).getCell(3);
-            assertTrue( cell1.isPartOfArrayFormulaGroup());
+        try (Workbook workbook1 = _testDataProvider.createWorkbook()) {
+            Sheet sheet1 = workbook1.createSheet();
+            Cell[] cells = sheet1.setArrayFormula("SUM(A1:A3*B1:B3)", CellRangeAddress.valueOf("C4:C6")).getFlattenedCells();
+            assertEquals(3, cells.length);
+
+            cells = sheet1.setArrayFormula("MAX(A1:A3*B1:B3)", CellRangeAddress.valueOf("A4:A6")).getFlattenedCells();
+            assertEquals(3, cells.length);
+
+            Sheet sheet2 = workbook1.createSheet();
+            cells = sheet2.setArrayFormula("MIN(A1:A3*B1:B3)", CellRangeAddress.valueOf("D2:D4")).getFlattenedCells();
+            assertEquals(3, cells.length);
+
+            try (Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook1)) {
+                sheet1 = workbook2.getSheetAt(0);
+                for (int rownum = 3; rownum <= 5; rownum++) {
+                    Cell cell1 = sheet1.getRow(rownum).getCell(2);
+                    assertTrue(cell1.isPartOfArrayFormulaGroup());
+
+                    Cell cell2 = sheet1.getRow(rownum).getCell(0);
+                    assertTrue(cell2.isPartOfArrayFormulaGroup());
+                }
+
+                sheet2 = workbook2.getSheetAt(1);
+                for (int rownum = 1; rownum <= 3; rownum++) {
+                    Cell cell1 = sheet2.getRow(rownum).getCell(3);
+                    assertTrue(cell1.isPartOfArrayFormulaGroup());
+                }
+            }
         }
-        
-        workbook2.close();
     }
 
     /**
@@ -273,293 +253,291 @@ public abstract class BaseTestSheetUpdat
      */
     @Test
     public void testModifyArrayCells_setFormulaResult() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        //single-cell array formula
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
-        Cell scell = srange.getTopLeftCell();
-        assertEquals(CellType.FORMULA, scell.getCellType());
-        assertEquals(0.0, scell.getNumericCellValue(), 0);
-        scell.setCellValue(1.1);
-        assertEquals(1.1, scell.getNumericCellValue(), 0);
-
-        //multi-cell array formula
-        CellRange<? extends Cell> mrange =
-                sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-        for(Cell mcell : mrange){
-            assertEquals(CellType.FORMULA, mcell.getCellType());
-            assertEquals(0.0, mcell.getNumericCellValue(), 0);
-            double fmlaResult = 1.2;
-            mcell.setCellValue(fmlaResult);
-            assertEquals(fmlaResult, mcell.getNumericCellValue(), 0);
+            //single-cell array formula
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+            Cell scell = srange.getTopLeftCell();
+            assertEquals(CellType.FORMULA, scell.getCellType());
+            assertEquals(0.0, scell.getNumericCellValue(), 0);
+            scell.setCellValue(1.1);
+            assertEquals(1.1, scell.getNumericCellValue(), 0);
+
+            //multi-cell array formula
+            CellRange<? extends Cell> mrange =
+                    sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            for (Cell mcell : mrange) {
+                assertEquals(CellType.FORMULA, mcell.getCellType());
+                assertEquals(0.0, mcell.getNumericCellValue(), 0);
+                double fmlaResult = 1.2;
+                mcell.setCellValue(fmlaResult);
+                assertEquals(fmlaResult, mcell.getNumericCellValue(), 0);
+            }
         }
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_setCellType() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        // single-cell array formulas behave just like normal cells -
-        // changing cell type removes the array formula and associated cached result
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
-        Cell scell = srange.getTopLeftCell();
-        assertEquals(CellType.FORMULA, scell.getCellType());
-        assertEquals(0.0, scell.getNumericCellValue(), 0);
-        scell.setCellType(CellType.STRING);
-        assertEquals(CellType.STRING, scell.getCellType());
-        scell.setCellValue("string cell");
-        assertEquals("string cell", scell.getStringCellValue());
-
-        //once you create a multi-cell array formula, you cannot change the type of its cells
-        CellRange<? extends Cell> mrange =
-                sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-        for(Cell mcell : mrange){
-            try {
+            // single-cell array formulas behave just like normal cells -
+            // changing cell type removes the array formula and associated cached result
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+            Cell scell = srange.getTopLeftCell();
+            assertEquals(CellType.FORMULA, scell.getCellType());
+            assertEquals(0.0, scell.getNumericCellValue(), 0);
+            scell.setCellType(CellType.STRING);
+            assertEquals(CellType.STRING, scell.getCellType());
+            scell.setCellValue("string cell");
+            assertEquals("string cell", scell.getStringCellValue());
+
+            //once you create a multi-cell array formula, you cannot change the type of its cells
+            CellRange<? extends Cell> mrange =
+                    sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            for (Cell mcell : mrange) {
+                try {
+                    assertEquals(CellType.FORMULA, mcell.getCellType());
+                    mcell.setCellType(CellType.NUMERIC);
+                    fail("expected exception");
+                } catch (IllegalStateException e) {
+                    CellReference ref = new CellReference(mcell);
+                    String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+                    assertEquals(msg, e.getMessage());
+                }
+                // a failed invocation of Cell.setCellType leaves the cell
+                // in the state that it was in prior to the invocation
                 assertEquals(CellType.FORMULA, mcell.getCellType());
-                mcell.setCellType(CellType.NUMERIC);
-                fail("expected exception");
-            } catch (IllegalStateException e){
-                CellReference ref = new CellReference(mcell);
-                String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array.";
-                assertEquals(msg, e.getMessage());
+                assertTrue(mcell.isPartOfArrayFormulaGroup());
             }
-            // a failed invocation of Cell.setCellType leaves the cell
-            // in the state that it was in prior to the invocation
-            assertEquals(CellType.FORMULA, mcell.getCellType());
-            assertTrue(mcell.isPartOfArrayFormulaGroup());
         }
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_setCellFormula() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
-        Cell scell = srange.getTopLeftCell();
-        assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
-        assertEquals(CellType.FORMULA, scell.getCellType());
-        assertTrue(scell.isPartOfArrayFormulaGroup());
-        scell.setCellFormula("SUM(A4,A6)");
-        //we are now a normal formula cell
-        assertEquals("SUM(A4,A6)", scell.getCellFormula());
-        assertFalse(scell.isPartOfArrayFormulaGroup());
-        assertEquals(CellType.FORMULA, scell.getCellType());
-        //check that setting formula result works
-        assertEquals(0.0, scell.getNumericCellValue(), 0);
-        scell.setCellValue(33.0);
-        assertEquals(33.0, scell.getNumericCellValue(), 0);
-
-        //multi-cell array formula
-        CellRange<? extends Cell> mrange =
-                sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-        for(Cell mcell : mrange){
-            //we cannot set individual formulas for cells included in an array formula
-            try {
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+            Cell scell = srange.getTopLeftCell();
+            assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
+            assertEquals(CellType.FORMULA, scell.getCellType());
+            assertTrue(scell.isPartOfArrayFormulaGroup());
+            scell.setCellFormula("SUM(A4,A6)");
+            //we are now a normal formula cell
+            assertEquals("SUM(A4,A6)", scell.getCellFormula());
+            assertFalse(scell.isPartOfArrayFormulaGroup());
+            assertEquals(CellType.FORMULA, scell.getCellType());
+            //check that setting formula result works
+            assertEquals(0.0, scell.getNumericCellValue(), 0);
+            scell.setCellValue(33.0);
+            assertEquals(33.0, scell.getNumericCellValue(), 0);
+
+            //multi-cell array formula
+            CellRange<? extends Cell> mrange =
+                    sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            for (Cell mcell : mrange) {
+                //we cannot set individual formulas for cells included in an array formula
+                try {
+                    assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
+                    mcell.setCellFormula("A1+A2");
+                    fail("expected exception");
+                } catch (IllegalStateException e) {
+                    CellReference ref = new CellReference(mcell);
+                    String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+                    assertEquals(msg, e.getMessage());
+                }
+                // a failed invocation of Cell.setCellFormula leaves the cell
+                // in the state that it was in prior to the invocation
                 assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
-                mcell.setCellFormula("A1+A2");
-                fail("expected exception");
-            } catch (IllegalStateException e){
-                CellReference ref = new CellReference(mcell);
-                String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array.";
-                assertEquals(msg, e.getMessage());
+                assertTrue(mcell.isPartOfArrayFormulaGroup());
             }
-            // a failed invocation of Cell.setCellFormula leaves the cell
-            // in the state that it was in prior to the invocation
-            assertEquals("A1:A3*B1:B3", mcell.getCellFormula());
-            assertTrue(mcell.isPartOfArrayFormulaGroup());
         }
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_removeCell() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        //single-cell array formulas behave just like normal cells
-        CellRangeAddress cra = CellRangeAddress.valueOf("B5");
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra);
-        Cell scell = srange.getTopLeftCell();
-
-        Row srow = sheet.getRow(cra.getFirstRow());
-        assertSame(srow, scell.getRow());
-        srow.removeCell(scell);
-        assertNull(srow.getCell(cra.getFirstColumn()));
-
-        //re-create the removed cell
-        scell = srow.createCell(cra.getFirstColumn());
-        assertEquals(CellType.BLANK, scell.getCellType());
-        assertFalse(scell.isPartOfArrayFormulaGroup());
-
-        //we cannot remove cells included in a multi-cell array formula
-        CellRange<? extends Cell> mrange =
-                sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-        for(Cell mcell : mrange){
-            int columnIndex = mcell.getColumnIndex();
-            Row mrow = mcell.getRow();
-            try {
-                mrow.removeCell(mcell);
-                fail("expected exception");
-            } catch (IllegalStateException e){
-                CellReference ref = new CellReference(mcell);
-                String msg = "Cell "+ref.formatAsString()+" is part of a multi-cell array formula. You cannot change part of an array.";
-                assertEquals(msg, e.getMessage());
+            //single-cell array formulas behave just like normal cells
+            CellRangeAddress cra = CellRangeAddress.valueOf("B5");
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra);
+            Cell scell = srange.getTopLeftCell();
+
+            Row srow = sheet.getRow(cra.getFirstRow());
+            assertSame(srow, scell.getRow());
+            srow.removeCell(scell);
+            assertNull(srow.getCell(cra.getFirstColumn()));
+
+            //re-create the removed cell
+            scell = srow.createCell(cra.getFirstColumn());
+            assertEquals(CellType.BLANK, scell.getCellType());
+            assertFalse(scell.isPartOfArrayFormulaGroup());
+
+            //we cannot remove cells included in a multi-cell array formula
+            CellRange<? extends Cell> mrange =
+                    sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            for (Cell mcell : mrange) {
+                int columnIndex = mcell.getColumnIndex();
+                Row mrow = mcell.getRow();
+                try {
+                    mrow.removeCell(mcell);
+                    fail("expected exception");
+                } catch (IllegalStateException e) {
+                    CellReference ref = new CellReference(mcell);
+                    String msg = "Cell " + ref.formatAsString() + " is part of a multi-cell array formula. You cannot change part of an array.";
+                    assertEquals(msg, e.getMessage());
+                }
+                // a failed invocation of Row.removeCell leaves the row
+                // in the state that it was in prior to the invocation
+                assertSame(mcell, mrow.getCell(columnIndex));
+                assertTrue(mcell.isPartOfArrayFormulaGroup());
+                assertEquals(CellType.FORMULA, mcell.getCellType());
             }
-            // a failed invocation of Row.removeCell leaves the row
-            // in the state that it was in prior to the invocation
-            assertSame(mcell, mrow.getCell(columnIndex));
-            assertTrue(mcell.isPartOfArrayFormulaGroup());
-            assertEquals(CellType.FORMULA, mcell.getCellType());
+
         }
-        
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_removeRow() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        //single-cell array formulas behave just like normal cells
-        CellRangeAddress cra = CellRangeAddress.valueOf("B5");
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra);
-        Cell scell = srange.getTopLeftCell();
-        assertEquals(CellType.FORMULA, scell.getCellType());
-
-        Row srow = scell.getRow();
-        assertSame(srow, sheet.getRow(cra.getFirstRow()));
-        sheet.removeRow(srow);
-        assertNull(sheet.getRow(cra.getFirstRow()));
-
-        //re-create the removed row and cell
-        scell = sheet.createRow(cra.getFirstRow()).createCell(cra.getFirstColumn());
-        assertEquals(CellType.BLANK, scell.getCellType());
-        assertFalse(scell.isPartOfArrayFormulaGroup());
-
-        //we cannot remove rows with cells included in a multi-cell array formula
-        CellRange<? extends Cell> mrange =
-                sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
-        for(Cell mcell : mrange){
-            int columnIndex = mcell.getColumnIndex();
-            Row mrow = mcell.getRow();
-            try {
-                sheet.removeRow(mrow);
-                fail("expected exception");
-            } catch (IllegalStateException e){
-                // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
-                // assertEquals(msg, e.getMessage());
-            }
-            // a failed invocation of Row.removeCell leaves the row
-            // in the state that it was in prior to the invocation
-            assertSame(mrow, sheet.getRow(mrow.getRowNum()));
-            assertSame(mcell, mrow.getCell(columnIndex));
-            assertTrue(mcell.isPartOfArrayFormulaGroup());
-            assertEquals(CellType.FORMULA, mcell.getCellType());
+            //single-cell array formulas behave just like normal cells
+            CellRangeAddress cra = CellRangeAddress.valueOf("B5");
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", cra);
+            Cell scell = srange.getTopLeftCell();
+            assertEquals(CellType.FORMULA, scell.getCellType());
+
+            Row srow = scell.getRow();
+            assertSame(srow, sheet.getRow(cra.getFirstRow()));
+            sheet.removeRow(srow);
+            assertNull(sheet.getRow(cra.getFirstRow()));
+
+            //re-create the removed row and cell
+            scell = sheet.createRow(cra.getFirstRow()).createCell(cra.getFirstColumn());
+            assertEquals(CellType.BLANK, scell.getCellType());
+            assertFalse(scell.isPartOfArrayFormulaGroup());
+
+            //we cannot remove rows with cells included in a multi-cell array formula
+            CellRange<? extends Cell> mrange =
+                    sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            for (Cell mcell : mrange) {
+                int columnIndex = mcell.getColumnIndex();
+                Row mrow = mcell.getRow();
+                try {
+                    sheet.removeRow(mrow);
+                    fail("expected exception");
+                } catch (IllegalStateException e) {
+                    // String msg = "Row[rownum="+mrow.getRowNum()+"] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
+                    // assertEquals(msg, e.getMessage());
+                }
+                // a failed invocation of Row.removeCell leaves the row
+                // in the state that it was in prior to the invocation
+                assertSame(mrow, sheet.getRow(mrow.getRowNum()));
+                assertSame(mcell, mrow.getCell(columnIndex));
+                assertTrue(mcell.isPartOfArrayFormulaGroup());
+                assertEquals(CellType.FORMULA, mcell.getCellType());
+            }
         }
-        
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_mergeCellsSingle() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
-        assertEquals(0, sheet.getNumMergedRegions());
-
-        //single-cell array formulas behave just like normal cells
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
-        Cell scell = srange.getTopLeftCell();
-        assertEquals(0, sheet.addMergedRegion(CellRangeAddress.valueOf("B5:C6")));
-        //we are still an array formula
-        assertEquals(CellType.FORMULA, scell.getCellType());
-        assertTrue(scell.isPartOfArrayFormulaGroup());
-        assertEquals(1, sheet.getNumMergedRegions());
-        
-        workbook.close();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+            assertEquals(0, sheet.getNumMergedRegions());
+
+            //single-cell array formulas behave just like normal cells
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+            Cell scell = srange.getTopLeftCell();
+            assertEquals(0, sheet.addMergedRegion(CellRangeAddress.valueOf("B5:C6")));
+            //we are still an array formula
+            assertEquals(CellType.FORMULA, scell.getCellType());
+            assertTrue(scell.isPartOfArrayFormulaGroup());
+            assertEquals(1, sheet.getNumMergedRegions());
+        }
     }
-    
+
     @Test
     public void testModifyArrayCells_mergeCellsMulti() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
-        int expectedNumMergedRegions = 0;
-        assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
-
-        // we cannot merge cells included in an array formula
-        sheet.setArrayFormula("A1:A4*B1:B4", CellRangeAddress.valueOf("C2:F5"));
-        for (String ref : Arrays.asList(
-                "C2:F5", // identity
-                "D3:E4", "B1:G6", // contains
-                "B1:C2", "F1:G2", "F5:G6", "B5:C6", // 1x1 corner intersection
-                "B1:C6", "B1:G2", "F1:G6", "B5:G6", // 1-row/1-column intersection
-                "B1:D3", "E1:G3", "E4:G6", "B4:D6", // 2x2 corner intersection
-                "B1:D6", "B1:G3", "E1:G6", "B4:G6"  // 2-row/2-column intersection
-        )) {
-            CellRangeAddress cra = CellRangeAddress.valueOf(ref);
-            try {
-                sheet.addMergedRegion(cra);
-                fail("expected exception with ref " + ref);
-            } catch (IllegalStateException e) {
-                String msg = "The range "+cra.formatAsString()+" intersects with a multi-cell array formula. You cannot merge cells of an array.";
-                assertEquals(msg, e.getMessage());
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+            int expectedNumMergedRegions = 0;
+            assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
+
+            // we cannot merge cells included in an array formula
+            sheet.setArrayFormula("A1:A4*B1:B4", CellRangeAddress.valueOf("C2:F5"));
+            for (String ref : Arrays.asList(
+                    "C2:F5", // identity
+                    "D3:E4", "B1:G6", // contains
+                    "B1:C2", "F1:G2", "F5:G6", "B5:C6", // 1x1 corner intersection
+                    "B1:C6", "B1:G2", "F1:G6", "B5:G6", // 1-row/1-column intersection
+                    "B1:D3", "E1:G3", "E4:G6", "B4:D6", // 2x2 corner intersection
+                    "B1:D6", "B1:G3", "E1:G6", "B4:G6"  // 2-row/2-column intersection
+            )) {
+                CellRangeAddress cra = CellRangeAddress.valueOf(ref);
+                try {
+                    sheet.addMergedRegion(cra);
+                    fail("expected exception with ref " + ref);
+                } catch (IllegalStateException e) {
+                    String msg = "The range " + cra.formatAsString() + " intersects with a multi-cell array formula. You cannot merge cells of an array.";
+                    assertEquals(msg, e.getMessage());
+                }
             }
-        }
-        //the number of merged regions remains the same
-        assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
-        
-        // we can merge non-intersecting cells
-        for (String ref : Arrays.asList(
-                "C1:F1", //above
-                "G2:G5", //right
-                "C6:F6",  //bottom
-                "B2:B5", "H7:J9")) {
-            CellRangeAddress cra = CellRangeAddress.valueOf(ref);
-            try {
-                sheet.addMergedRegion(cra);
-                expectedNumMergedRegions++;
-                assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
-            } catch (IllegalStateException e) {
-                fail("did not expect exception with ref: " + ref + "\n" + e.getMessage());
+            //the number of merged regions remains the same
+            assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
+
+            // we can merge non-intersecting cells
+            for (String ref : Arrays.asList(
+                    "C1:F1", //above
+                    "G2:G5", //right
+                    "C6:F6",  //bottom
+                    "B2:B5", "H7:J9")) {
+                CellRangeAddress cra = CellRangeAddress.valueOf(ref);
+                try {
+                    sheet.addMergedRegion(cra);
+                    expectedNumMergedRegions++;
+                    assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions());
+                } catch (IllegalStateException e) {
+                    fail("did not expect exception with ref: " + ref + "\n" + e.getMessage());
+                }
             }
+
         }
-        
-        workbook.close();
     }
 
     @Test
     public void testModifyArrayCells_shiftRows() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
 
-        //single-cell array formulas behave just like normal cells - we can change the cell type
-        CellRange<? extends Cell> srange =
-                sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
-        Cell scell = srange.getTopLeftCell();
-        assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
-        sheet.shiftRows(0, 0, 1);
-        sheet.shiftRows(0, 1, 1);
+            //single-cell array formulas behave just like normal cells - we can change the cell type
+            CellRange<? extends Cell> srange =
+                    sheet.setArrayFormula("SUM(A4:A6,B4:B6)", CellRangeAddress.valueOf("B5"));
+            Cell scell = srange.getTopLeftCell();
+            assertEquals("SUM(A4:A6,B4:B6)", scell.getCellFormula());
+            sheet.shiftRows(0, 0, 1);
+            sheet.shiftRows(0, 1, 1);
 
-        //we cannot set individual formulas for cells included in an array formula
-        sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
+            //we cannot set individual formulas for cells included in an array formula
+            sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3"));
 
-        try {
-            sheet.shiftRows(0, 0, 1);
-            fail("expected exception");
-        } catch (IllegalStateException e){
-            String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
-            assertEquals(msg, e.getMessage());
-        }
+            try {
+                sheet.shiftRows(0, 0, 1);
+                fail("expected exception");
+            } catch (IllegalStateException e) {
+                String msg = "Row[rownum=0] contains cell(s) included in a multi-cell array formula. You cannot change part of an array.";
+                assertEquals(msg, e.getMessage());
+            }
         /*
          TODO: enable shifting the whole array
 
@@ -575,37 +553,32 @@ public abstract class BaseTestSheetUpdat
         }
 
         */
-        workbook.close();
+        }
     }
 
     @Ignore("See bug 59728")
-    @Test
+    @Test(expected = IllegalStateException.class)
     public void shouldNotBeAbleToCreateArrayFormulaOnPreexistingMergedRegion() throws IOException {
         /*
          *  m  = merged region
          *  f  = array formula
          *  fm = cell belongs to a merged region and an array formula (illegal, that's what this tests for)
-         *  
+         *
          *   A  B  C
          * 1    f  f
          * 2    fm fm
          * 3    f  f
          */
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
-        
-        CellRangeAddress mergedRegion = CellRangeAddress.valueOf("B2:C2");
-        assertEquals(0, sheet.addMergedRegion(mergedRegion));
-        CellRangeAddress arrayFormula = CellRangeAddress.valueOf("C1:C3");
-        assumeTrue(mergedRegion.intersects(arrayFormula));
-        assumeTrue(arrayFormula.intersects(mergedRegion));
-        try {
-            sheet.setArrayFormula("SUM(A1:A3)",  arrayFormula);
-            fail("expected exception: should not be able to create an array formula that intersects with a merged region");
-        } catch (IllegalStateException e) {
-            // expected
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
+            Sheet sheet = workbook.createSheet();
+
+            CellRangeAddress mergedRegion = CellRangeAddress.valueOf("B2:C2");
+            assertEquals(0, sheet.addMergedRegion(mergedRegion));
+            CellRangeAddress arrayFormula = CellRangeAddress.valueOf("C1:C3");
+            assumeTrue(mergedRegion.intersects(arrayFormula));
+            assumeTrue(arrayFormula.intersects(mergedRegion));
+            // expected exception: should not be able to create an array formula that intersects with a merged region
+            sheet.setArrayFormula("SUM(A1:A3)", arrayFormula);
         }
-        
-        workbook.close();
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/charts/TestDataSources.java Fri Dec 27 23:00:13 2019
@@ -16,19 +16,24 @@
 ==================================================================== */
 package org.apache.poi.ss.usermodel.charts;
 
-import junit.framework.TestCase;
+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 org.apache.poi.hssf.usermodel.HSSFWorkbook;
 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.ss.util.SheetBuilder;
+import org.junit.Test;
 
 /**
  * Tests for {@link org.apache.poi.ss.usermodel.charts.DataSources}.
- *
- * @author Roman Kashitsyn
  */
-public class TestDataSources extends TestCase {
+@SuppressWarnings("deprecation")
+public class TestDataSources {
 
     private static final Object[][] numericCells = {
             {0.0,      1.0,       2.0,     3.0,      4.0},
@@ -44,6 +49,7 @@ public class TestDataSources extends Tes
             {1.0, "2.0", 3.0, "4.0", 5.0, "6.0"}
     };
 
+    @Test
     public void testNumericArrayDataSource() {
         Double[] doubles = new Double[]{1.0, 2.0, 3.0, 4.0, 5.0};
         ChartDataSource<Double> doubleDataSource = DataSources.fromArray(doubles);
@@ -52,6 +58,7 @@ public class TestDataSources extends Tes
         assertDataSourceIsEqualToArray(doubleDataSource, doubles);
     }
 
+    @Test
     public void testStringArrayDataSource() {
         String[] strings = new String[]{"one", "two", "three", "four", "five"};
         ChartDataSource<String> stringDataSource = DataSources.fromArray(strings);
@@ -60,6 +67,7 @@ public class TestDataSources extends Tes
         assertDataSourceIsEqualToArray(stringDataSource, strings);
     }
 
+    @Test
     public void testNumericCellDataSource() {
         Workbook wb = new HSSFWorkbook();
         Sheet sheet = new SheetBuilder(wb, numericCells).build();
@@ -74,6 +82,7 @@ public class TestDataSources extends Tes
         }
     }
 
+    @Test
     public void testStringCellDataSource() {
         Workbook wb = new HSSFWorkbook();
         Sheet sheet = new SheetBuilder(wb, stringCells).build();
@@ -87,6 +96,7 @@ public class TestDataSources extends Tes
         }
     }
 
+    @Test
     public void testMixedCellDataSource() {
         Workbook wb = new HSSFWorkbook();
         Sheet sheet = new SheetBuilder(wb, mixedCells).build();
@@ -105,6 +115,7 @@ public class TestDataSources extends Tes
         }
     }
 
+    @Test
     public void testIOBExceptionOnInvalidIndex() {
         Workbook wb = new HSSFWorkbook();
         Sheet sheet = new SheetBuilder(wb, numericCells).build();

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java Fri Dec 27 23:00:13 2019
@@ -18,19 +18,15 @@
 package org.apache.poi.ss.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
 
-import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.math.RoundingMode;
 
-import org.apache.poi.util.HexDump;
 import org.junit.Test;
 
-import junit.framework.AssertionFailedError;
 /**
  * Tests for {@link ExpandedDouble}
- *
- * @author Josh Micich
  */
 public final class TestExpandedDouble {
 	private static final BigInteger BIG_POW_10 = BigInteger.valueOf(1000000000);
@@ -38,10 +34,7 @@ public final class TestExpandedDouble {
 	@Test
 	public void testNegative() {
 		ExpandedDouble hd = new ExpandedDouble(0xC010000000000000L);
-
-		if (hd.getBinaryExponent() == -2046) {
-			throw new AssertionFailedError("identified bug - sign bit not masked out of exponent");
-		}
+		assertNotEquals("identified bug - sign bit not masked out of exponent", -2046, hd.getBinaryExponent());
 		assertEquals(2, hd.getBinaryExponent());
 		BigInteger frac = hd.getSignificand();
 		assertEquals(64, frac.bitLength());
@@ -51,10 +44,7 @@ public final class TestExpandedDouble {
 	@Test
 	public void testSubnormal() {
 		ExpandedDouble hd = new ExpandedDouble(0x0000000000000001L);
-
-		if (hd.getBinaryExponent() == -1023) {
-			throw new AssertionFailedError("identified bug - subnormal numbers not decoded properly");
-		}
+		assertNotEquals("identified bug - subnormal numbers not decoded properly", -1023, hd.getBinaryExponent());
 		assertEquals(-1086, hd.getBinaryExponent());
 		BigInteger frac = hd.getSignificand();
 		assertEquals(64, frac.bitLength());
@@ -85,115 +75,36 @@ public final class TestExpandedDouble {
 				0x403CE0FFFFFFFFF0L, // has single digit round trip error
 				0x2B2BFFFF10001079L,
 		};
-		boolean success = true;
 		for (int i = 0; i < rawValues.length; i++) {
-			success &= confirmRoundTrip(i, rawValues[i]);
-		}
-		if (!success) {
-			throw new AssertionFailedError("One or more test examples failed.  See stderr.");
+			confirmRoundTrip(i, rawValues[i]);
 		}
 	}
-	
-	public static boolean confirmRoundTrip(int i, long rawBitsA) {
+
+	public static void confirmRoundTrip(int i, long rawBitsA) {
 		double a = Double.longBitsToDouble(rawBitsA);
 		if (a == 0.0) {
 			// Can't represent 0.0 or -0.0 with NormalisedDecimal
-			return true;
-		}
-		ExpandedDouble ed1;
-		NormalisedDecimal nd2;
-		ExpandedDouble ed3;
-		try {
-			ed1 = new ExpandedDouble(rawBitsA);
-			nd2 = ed1.normaliseBaseTen();
-			checkNormaliseBaseTenResult(ed1, nd2);
-
-			ed3 = nd2.normaliseBaseTwo();
-		} catch (RuntimeException e) {
-			System.err.println("example[" + i + "] ("
-					+ formatDoubleAsHex(a) + ") exception:");
-			e.printStackTrace();
-			return false;
-		}
-		if (ed3.getBinaryExponent() != ed1.getBinaryExponent()) {
-			System.err.println("example[" + i + "] ("
-					+ formatDoubleAsHex(a) + ") bin exp mismatch");
-			return false;
+			return;
 		}
+		ExpandedDouble ed1 = new ExpandedDouble(rawBitsA);
+		NormalisedDecimal nd2 = ed1.normaliseBaseTen();
+		checkNormaliseBaseTenResult(ed1, nd2);
+
+		ExpandedDouble ed3 = nd2.normaliseBaseTwo();
+		assertEquals("bin exp mismatch", ed3.getBinaryExponent(), ed1.getBinaryExponent());
+
 		BigInteger diff = ed3.getSignificand().subtract(ed1.getSignificand()).abs();
 		if (diff.signum() == 0) {
-			return true;
+			return;
 		}
 		// original quantity only has 53 bits of precision
 		// these quantities may have errors in the 64th bit, which hopefully don't make any difference
 
-		if (diff.bitLength() < 2) {
-			// errors in the 64th bit happen from time to time
-			// this is well below the 53 bits of precision required
-			return true;
-		}
-
-		// but bigger errors are a concern
-		System.out.println("example[" + i + "] ("
-				+ formatDoubleAsHex(a) + ") frac mismatch: " + diff);
-
-		for (int j=-2; j<3; j++) {
-			System.out.println((j<0?"":"+") + j + ": " + getNearby(ed1, j));
-		}
-		for (int j=-2; j<3; j++) {
-			System.out.println((j<0?"":"+") + j + ": " + getNearby(nd2, j));
-		}
-
-
-		return false;
+		// errors in the 64th bit happen from time to time
+		// this is well below the 53 bits of precision required
+		assertTrue(diff.bitLength() < 2);
 	}
 
-	public static String getBaseDecimal(ExpandedDouble hd) {
-		int gg = 64 - hd.getBinaryExponent() - 1;
-		BigDecimal bd = new BigDecimal(hd.getSignificand()).divide(new BigDecimal(BigInteger.ONE.shiftLeft(gg)));
-		int excessPrecision = bd.precision() - 23;
-		if (excessPrecision > 0) {
-			bd = bd.setScale(bd.scale() - excessPrecision, RoundingMode.HALF_UP);
-		}
-		return bd.unscaledValue().toString();
-	}
-	
-	public static BigInteger getNearby(NormalisedDecimal md, int offset) {
-		BigInteger frac = md.composeFrac();
-		int be = frac.bitLength() - 24 - 1;
-		int sc = frac.bitLength() - 64;
-		return getNearby(frac.shiftRight(sc), be, offset);
-	}
-
-	public static BigInteger getNearby(ExpandedDouble hd, int offset) {
-		return getNearby(hd.getSignificand(), hd.getBinaryExponent(), offset);
-	}
-
-	private static BigInteger getNearby(BigInteger significand, int binExp, int offset) {
-		int nExtraBits = 1;
-		int nDec = (int) Math.round(3.0 + (64+nExtraBits) * Math.log10(2.0));
-		BigInteger newFrac = significand.shiftLeft(nExtraBits).add(BigInteger.valueOf(offset));
-
-		int gg = 64 + nExtraBits - binExp - 1;
-
-		BigDecimal bd = new BigDecimal(newFrac);
-		if (gg > 0) {
-			bd = bd.divide(new BigDecimal(BigInteger.ONE.shiftLeft(gg)));
-		} else {
-			BigInteger frac = newFrac;
-			while (frac.bitLength() + binExp < 180) {
-				frac = frac.multiply(BigInteger.TEN);
-			}
-			int binaryExp = binExp - newFrac.bitLength() + frac.bitLength();
-
-			bd = new BigDecimal( frac.shiftRight(frac.bitLength()-binaryExp-1));
-		}
-		int excessPrecision = bd.precision() - nDec;
-		if (excessPrecision > 0) {
-			bd = bd.setScale(bd.scale() - excessPrecision, RoundingMode.HALF_UP);
-		}
-		return bd.unscaledValue();
-	}
 
 	private static void checkNormaliseBaseTenResult(ExpandedDouble orig, NormalisedDecimal result) {
 		String sigDigs = result.getSignificantDecimalDigits();
@@ -204,10 +115,7 @@ public final class TestExpandedDouble {
 		int binaryExp = orig.getBinaryExponent() - orig.getSignificand().bitLength();
 
 		String origDigs = frac.shiftLeft(binaryExp+1).toString(10);
-
-		if (!origDigs.startsWith(sigDigs)) {
-			throw new AssertionFailedError("Expected '" + origDigs + "' but got '" + sigDigs + "'.");
-		}
+		assertTrue(origDigs.startsWith(sigDigs));
 
 		double dO = Double.parseDouble("0." + origDigs.substring(sigDigs.length()));
 		double d1 = Double.parseDouble(result.getFractionalPart().toPlainString());
@@ -218,14 +126,7 @@ public final class TestExpandedDouble {
 			return;
 		}
 		BigInteger diff = subDigsB.subtract(subDigsO).abs();
-		if (diff.intValue() > 100) {
-			// 100/32768 ~= 0.003
-			throw new AssertionFailedError("minor mistake");
-		}
-	}
-
-	private static String formatDoubleAsHex(double d) {
-		long l = Double.doubleToLongBits(d);
-		return HexDump.longToHex(l)+'L';
+		// 100/32768 ~= 0.003
+		assertTrue("minor mistake", diff.intValue() <= 100);
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java Fri Dec 27 23:00:13 2019
@@ -18,7 +18,6 @@
 package org.apache.poi.ss.util;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -27,8 +26,6 @@ import org.apache.poi.util.HexDump;
 import org.junit.Test;
 /**
  * Tests for {@link NumberComparer}
- *
- * @author Josh Micich
  */
 public final class TestNumberComparer {
 
@@ -44,27 +41,24 @@ public final class TestNumberComparer {
 			success &= confirm(i, ce.getNegA(), ce.getNegB(), -ce.getExpectedResult());
 			success &= confirm(i, ce.getNegB(), ce.getNegA(), +ce.getExpectedResult());
 		}
-		
+
 		assertTrue("One or more cases failed.  See stderr", success);
 	}
 
     @Test
 	public void testRoundTripOnComparisonExamples() {
 		ComparisonExample[] examples = NumberComparisonExamples.getComparisonExamples();
-		boolean success = true;
 		for(int i=0;i<examples.length; i++) {
 			ComparisonExample ce = examples[i];
-			success &= confirmRoundTrip(i, ce.getA());
-			success &= confirmRoundTrip(i, ce.getNegA());
-			success &= confirmRoundTrip(i, ce.getB());
-			success &= confirmRoundTrip(i, ce.getNegB());
+			confirmRoundTrip(i, ce.getA());
+			confirmRoundTrip(i, ce.getNegA());
+			confirmRoundTrip(i, ce.getB());
+			confirmRoundTrip(i, ce.getNegB());
 		}
-		
-		assertTrue("One or more cases failed.  See stderr", success);
 	}
 
-	private boolean confirmRoundTrip(int i, double a) {
-		return TestExpandedDouble.confirmRoundTrip(i, Double.doubleToLongBits(a));
+	private void confirmRoundTrip(int i, double a) {
+		TestExpandedDouble.confirmRoundTrip(i, Double.doubleToLongBits(a));
 	}
 
 	/**

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestNumberToTextConverter.java Fri Dec 27 23:00:13 2019
@@ -17,68 +17,36 @@
 
 package org.apache.poi.ss.util;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.ComparisonFailure;
-import junit.framework.TestCase;
-
-import java.util.Locale;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.ss.formula.constant.ConstantValueParser;
 import org.apache.poi.ss.formula.ptg.NumberPtg;
 import org.apache.poi.ss.util.NumberToTextConversionExamples.ExampleConversion;
+import org.junit.Test;
+
 /**
  * Tests for {@link NumberToTextConverter}
- * 
- * @author Josh Micich
  */
-public final class TestNumberToTextConverter extends TestCase {
-	
-
+public final class TestNumberToTextConverter {
 	/**
 	 * Confirms that <tt>ExcelNumberToTextConverter.toText(d)</tt> produces the right results.
 	 * As part of preparing this test class, the <tt>ExampleConversion</tt> instances should be set
 	 * up to contain the rendering as produced by Excel.
 	 */
+	@Test
 	public void testAll() {
-		int failureCount = 0;
-		
 		ExampleConversion[] examples = NumberToTextConversionExamples.getExampleConversions();
 
-		for (int i = 0; i < examples.length; i++) {
-			ExampleConversion example = examples[i];
-			try {
-				if (example.isNaN()) {
-					confirmNaN(example.getRawDoubleBits(), example.getExcelRendering());
-					continue;
-				}
-				String actual = NumberToTextConverter.toText(example.getDoubleValue());
-				if (!example.getExcelRendering().equals(actual)) {
-					failureCount++;
-					String msg = "Error rendering for examples[" + i + "] "
-							+ formatExample(example) + " "
-							+ " bad-result='" + actual + "' "
-							+ new ComparisonFailure(null, example.getExcelRendering(), actual).getMessage();
-					System.err.println(msg);
-					continue;
-				}
-			} catch (RuntimeException e) {
-				failureCount++;
-				System.err.println("Error in excel rendering for examples[" + i + "] "
-						+ formatExample(example) + "':" + e.getMessage());
-				e.printStackTrace();
+		for (ExampleConversion example : examples) {
+			if (example.isNaN()) {
+				confirmNaN(example.getRawDoubleBits(), example.getExcelRendering());
+				continue;
 			}
+			String actual = NumberToTextConverter.toText(example.getDoubleValue());
+			assertEquals(example.getExcelRendering(), actual);
 		}
-		if (failureCount > 0) {
-			throw new AssertionFailedError(failureCount 
-					+ " error(s) in excel number to text conversion (see std-err)");
-		}
-	}
-
-	private static String formatExample(ExampleConversion example) {
-		String hexLong = Long.toHexString(example.getRawDoubleBits()).toUpperCase(Locale.ROOT);
-		String longRep = "0x" + "0000000000000000".substring(hexLong.length()) + hexLong+ "L";  
-		return "ec(" + longRep + ", \"" + example.getJavaRendering() + "\", \"" + example.getExcelRendering() + "\")";
 	}
 
 	/**
@@ -86,43 +54,42 @@ public final class TestNumberToTextConve
 	 * general, Excel does not attempt to use raw NaN in the IEEE sense. In {@link FormulaRecord}s,
 	 * Excel uses the NaN bit pattern to flag non-numeric (text, boolean, error) cached results.
 	 * If the formula result actually evaluates to raw NaN, Excel transforms it to <i>#NUM!</i>.
-	 * In other places (e.g. {@link NumberRecord}, {@link NumberPtg}, array items (via {@link 
-	 * ConstantValueParser}), there seems to be no special NaN translation scheme.  If a NaN bit 
-	 * pattern is somehow encoded into any of these places Excel actually attempts to render the 
-	 * values as a plain number. That is the unusual functionality that this method is testing.<p>   
-	 * 
+	 * In other places (e.g. {@link NumberRecord}, {@link NumberPtg}, array items (via {@link
+	 * ConstantValueParser}), there seems to be no special NaN translation scheme.  If a NaN bit
+	 * pattern is somehow encoded into any of these places Excel actually attempts to render the
+	 * values as a plain number. That is the unusual functionality that this method is testing.<p>
+	 *
 	 * There are multiple encodings (bit patterns) for NaN, and CPUs and applications can convert
-	 * to a preferred NaN encoding  (Java prefers <tt>0x7FF8000000000000L</tt>).  Besides the 
-	 * special encoding in {@link FormulaRecord.SpecialCachedValue}, it is not known how/whether 
+	 * to a preferred NaN encoding  (Java prefers <tt>0x7FF8000000000000L</tt>).  Besides the
+	 * special encoding in {@link FormulaRecord.SpecialCachedValue}, it is not known how/whether
 	 * Excel attempts to encode NaN values.
-	 * 
+	 *
 	 * Observed NaN behaviour on HotSpot/Windows:
 	 * <tt>Double.longBitsToDouble()</tt> will set one bit 51 (the NaN signaling flag) if it isn't
-	 *  already. <tt>Double.doubleToLongBits()</tt> will return a double with bit pattern 
+	 *  already. <tt>Double.doubleToLongBits()</tt> will return a double with bit pattern
 	 *  <tt>0x7FF8000000000000L</tt> for any NaN bit pattern supplied.<br>
 	 * Differences are likely to be observed with other architectures.<p>
-	 *  
+	 *
 	 * <p>
-	 * The few test case examples calling this method represent functionality which may not be 
+	 * The few test case examples calling this method represent functionality which may not be
 	 * important for POI to support.
 	 */
 	private void confirmNaN(long l, String excelRep) {
 		double d = Double.longBitsToDouble(l);
 		assertEquals("NaN", Double.toString(d));
-		
+
 		String strExcel = NumberToTextConverter.rawDoubleBitsToText(l);
-		
+
 		assertEquals(excelRep, strExcel);
 	}
-	
+
+	@Test
 	public void testSimpleRendering_bug56156() {
 		double dResult = 0.05+0.01; // values chosen to produce rounding anomaly
 		String actualText = NumberToTextConverter.toText(dResult);
 		String jdkText = Double.toString(dResult);
-		if (jdkText.equals(actualText)) {
-			// "0.060000000000000005"
-			throw new AssertionFailedError("Should not use default JDK IEEE double rendering");
-		}
+		// "0.060000000000000005"
+		assertNotEquals("Should not use default JDK IEEE double rendering", jdkText, actualText);
 		assertEquals("0.06", actualText);
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestSheetBuilder.java Fri Dec 27 23:00:13 2019
@@ -5,9 +5,9 @@
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
-   
+
    http://www.apache.org/licenses/LICENSE-2.0
-   
+
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,6 +17,11 @@
 
 package org.apache.poi.ss.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
 import java.util.Date;
 
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -25,15 +30,14 @@ import org.apache.poi.ss.usermodel.CellT
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-
-import junit.framework.TestCase;
+import org.junit.Test;
 
 /**
  * Tests SheetBuilder.
  *
  * @see org.apache.poi.ss.util.SheetBuilder
  */
-public final class TestSheetBuilder extends TestCase {
+public final class TestSheetBuilder {
 
     private static Object[][] testData = new Object[][]{
             {1, 2, 3},
@@ -41,45 +45,51 @@ public final class TestSheetBuilder exte
             {"one", "two", "=A1+B2"}
     };
 
-    public void testNotCreateEmptyCells() {
-        Workbook wb = new HSSFWorkbook();
-        Sheet sheet = new SheetBuilder(wb, testData).build();
+    @Test
+    public void testNotCreateEmptyCells() throws IOException {
+        try (Workbook wb = new HSSFWorkbook()) {
+            Sheet sheet = new SheetBuilder(wb, testData).build();
 
-        assertEquals(sheet.getPhysicalNumberOfRows(), 3);
+            assertEquals(sheet.getPhysicalNumberOfRows(), 3);
 
-        Row firstRow = sheet.getRow(0);
-        Cell firstCell = firstRow.getCell(0);
+            Row firstRow = sheet.getRow(0);
+            Cell firstCell = firstRow.getCell(0);
 
-        assertEquals(firstCell.getCellType(), CellType.NUMERIC);
-        assertEquals(1.0, firstCell.getNumericCellValue(), 0.00001);
+            assertEquals(firstCell.getCellType(), CellType.NUMERIC);
+            assertEquals(1.0, firstCell.getNumericCellValue(), 0.00001);
 
 
-        Row secondRow = sheet.getRow(1);
-        assertNotNull(secondRow.getCell(0));
-        assertNull(secondRow.getCell(2));
+            Row secondRow = sheet.getRow(1);
+            assertNotNull(secondRow.getCell(0));
+            assertNull(secondRow.getCell(2));
 
-        Row thirdRow = sheet.getRow(2);
-        assertEquals(CellType.STRING, thirdRow.getCell(0).getCellType());
-        String cellValue = thirdRow.getCell(0).getStringCellValue();
-        assertEquals(testData[2][0].toString(), cellValue);
+            Row thirdRow = sheet.getRow(2);
+            assertEquals(CellType.STRING, thirdRow.getCell(0).getCellType());
+            String cellValue = thirdRow.getCell(0).getStringCellValue();
+            assertEquals(testData[2][0].toString(), cellValue);
 
-        assertEquals(CellType.FORMULA, thirdRow.getCell(2).getCellType());
-        assertEquals("A1+B2", thirdRow.getCell(2).getCellFormula());
+            assertEquals(CellType.FORMULA, thirdRow.getCell(2).getCellType());
+            assertEquals("A1+B2", thirdRow.getCell(2).getCellFormula());
+        }
     }
 
-    public void testEmptyCells() {
-        Workbook wb = new HSSFWorkbook();
-        Sheet sheet = new SheetBuilder(wb, testData).setCreateEmptyCells(true).build();
-
-        Cell emptyCell = sheet.getRow(1).getCell(1);
-        assertNotNull(emptyCell);
-        assertEquals(CellType.BLANK, emptyCell.getCellType());
+    @Test
+    public void testEmptyCells() throws IOException {
+        try (Workbook wb = new HSSFWorkbook()) {
+            Sheet sheet = new SheetBuilder(wb, testData).setCreateEmptyCells(true).build();
+
+            Cell emptyCell = sheet.getRow(1).getCell(1);
+            assertNotNull(emptyCell);
+            assertEquals(CellType.BLANK, emptyCell.getCellType());
+        }
     }
 
-    public void testSheetName() {
+    @Test
+    public void testSheetName() throws IOException {
         final String sheetName = "TEST SHEET NAME";
-        Workbook wb = new HSSFWorkbook();
-        Sheet sheet = new SheetBuilder(wb, testData).setSheetName(sheetName).build();
-        assertEquals(sheetName, sheet.getSheetName());
+        try (Workbook wb = new HSSFWorkbook()) {
+            Sheet sheet = new SheetBuilder(wb, testData).setSheetName(sheetName).build();
+            assertEquals(sheetName, sheet.getSheetName());
+        }
     }
 }
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestWorkbookUtil.java Fri Dec 27 23:00:13 2019
@@ -17,67 +17,70 @@
 
 package org.apache.poi.ss.util;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
 
 /**
  * Tests WorkbookUtil.
  *
  * @see org.apache.poi.ss.util.WorkbookUtil
  */
-public final class TestWorkbookUtil extends TestCase {
+public final class TestWorkbookUtil {
 	/**
-	 * borrowed test cases from 
+	 * borrowed test cases from
 	 * {@link org.apache.poi.hssf.record.TestBoundSheetRecord#testValidNames()}
 	 */
+	@Test
 	public void testCreateSafeNames() {
-		
+
 		String p = "Sheet1";
 		String actual = WorkbookUtil.createSafeSheetName(p);
 		assertEquals(p, actual);
-		
+
 		p = "O'Brien's sales";
 		actual = WorkbookUtil.createSafeSheetName(p);
 		assertEquals(p, actual);
-		
+
 		p = " data # ";
 		actual = WorkbookUtil.createSafeSheetName(p);
 		assertEquals(p, actual);
-		
+
 		p = "data $1.00";
 		actual = WorkbookUtil.createSafeSheetName(p);
 		assertEquals(p, actual);
-		
+
 		// now the replaced versions ...
 		actual = WorkbookUtil.createSafeSheetName("data?");
 		assertEquals("data ", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("abc/def");
 		assertEquals("abc def", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("data[0]");
 		assertEquals("data 0 ", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("data*");
 		assertEquals("data ", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("abc\\def");
 		assertEquals("abc def", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("'data");
 		assertEquals(" data", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("data'");
 		assertEquals("data ", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("d'at'a");
 		assertEquals("d'at'a", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName(null);
 		assertEquals("null", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("");
 		assertEquals("empty", actual);
-		
+
 		actual = WorkbookUtil.createSafeSheetName("1234567890123456789012345678901TOOLONG");
 		assertEquals("1234567890123456789012345678901", actual);
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/cellwalk/TestCellWalk.java Fri Dec 27 23:00:13 2019
@@ -5,9 +5,9 @@
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
-   
+
    http://www.apache.org/licenses/LICENSE-2.0
-   
+
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,64 +16,41 @@
    ==================================================================== */
 package org.apache.poi.ss.util.cellwalk;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
 import java.util.Date;
 
-import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.SheetBuilder;
+import org.junit.Test;
 
-public class TestCellWalk extends TestCase {
+public class TestCellWalk {
 
-    private static Object[][] testData = new Object[][] {
-	{   1,          2,  null},
-	{null, new Date(),  null},
-	{null,       null, "str"}
+    private static Object[][] testData = new Object[][]{
+            {1, 2, null},
+            {null, new Date(), null},
+            {null, null, "str"}
     };
 
-    private final CountCellHandler countCellHandler = new CountCellHandler();
-
+    @Test
     public void testNotTraverseEmptyCells() {
-	Workbook wb = new HSSFWorkbook();
-	Sheet sheet = new SheetBuilder(wb, testData).build();
-	CellRangeAddress range = CellRangeAddress.valueOf("A1:C3");
-	
-	CellWalk cellWalk = new CellWalk(sheet, range);
-	countCellHandler.reset();
-	cellWalk.traverse(countCellHandler);
-
-	assertEquals(4, countCellHandler.getVisitedCellsNumber());
-	/* 1 + 2 + 5 + 9 */
-	assertEquals(17L, countCellHandler.getOrdinalNumberSum());
-    }
-
-
-    private static class CountCellHandler implements CellHandler {
-
-	private int cellsVisited;
-	private long ordinalNumberSum;
-
-	@Override
-    public void onCell(Cell cell, CellWalkContext ctx) {
-	    ++cellsVisited;
-	    ordinalNumberSum += ctx.getOrdinalNumber();
-	}
-
-	public int getVisitedCellsNumber() {
-	    return cellsVisited;
-	}
-
-	public long getOrdinalNumberSum() {
-	    return ordinalNumberSum;
-	}
-
-	public void reset() {
-	    cellsVisited = 0;
-	    ordinalNumberSum = 0L;
-	}
+        Workbook wb = new HSSFWorkbook();
+        Sheet sheet = new SheetBuilder(wb, testData).build();
+        CellRangeAddress range = CellRangeAddress.valueOf("A1:C3");
+
+        CellWalk cellWalk = new CellWalk(sheet, range);
+		int[] cellsVisited = { 0 };
+		long[] ordinalNumberSum = { 0 };
+        cellWalk.traverse((cell,ctx) -> {
+			cellsVisited[0]++;
+			ordinalNumberSum[0] += ctx.getOrdinalNumber();
+		});
+
+        assertEquals(4, cellsVisited[0]);
+        /* 1 + 2 + 5 + 9 */
+        assertEquals(17L, ordinalNumberSum[0]);
     }
 }
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/util/TestArrayUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestArrayUtil.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestArrayUtil.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestArrayUtil.java Fri Dec 27 23:00:13 2019
@@ -18,17 +18,21 @@
 
 package org.apache.poi.util;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+
+import org.junit.Test;
 
 /**
  * Unit test for ArrayUtil
- *
- * @author Nick Burch
  */
-public class TestArrayUtil extends TestCase {
+public class TestArrayUtil {
 	/**
 	 * Test to ensure that our own arraycopy behaves as it should do
 	 */
+	@Test
 	public void testarraycopy() {
 		byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04 };
 
@@ -36,11 +40,7 @@ public class TestArrayUtil extends TestC
 		byte[] dest = new byte[4];
 		ArrayUtil.arraycopy(bytes, 0, dest, 0, 4);
 
-		assertEquals(dest.length, bytes.length);
-		for(int i=0; i<dest.length; i++) {
-			assertEquals(bytes[i], dest[i]);
-		}
-
+		assertArrayEquals(dest, bytes);
 		// ToDo - test exceptions are as expected
 	}
 
@@ -49,234 +49,58 @@ public class TestArrayUtil extends TestC
 	 * Helper for testArrayMoveWithin
 	 */
 	private Integer[] getIntsList() {
-		return new Integer[] {
-				Integer.valueOf(0),
-				Integer.valueOf(1),
-				Integer.valueOf(2),
-				Integer.valueOf(3),
-				Integer.valueOf(4),
-				Integer.valueOf(5),
-				Integer.valueOf(6),
-				Integer.valueOf(7),
-				Integer.valueOf(8),
-				Integer.valueOf(9)
-		};
+		return new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 	}
 
-	private static void assertEquals(int exp, Integer act) {
-		assertEquals(exp, act.intValue());
-	}
-	
 	/**
 	 * Test to ensure that arrayMoveWithin works as expected
 	 */
+	@Test
 	public void testArrayMoveWithin() {
-		Integer[] ints = getIntsList();
-
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(2, ints[2]);
-		assertEquals(3, ints[3]);
-		assertEquals(4, ints[4]);
-		assertEquals(5, ints[5]);
-		assertEquals(6, ints[6]);
-		assertEquals(7, ints[7]);
-		assertEquals(8, ints[8]);
-		assertEquals(9, ints[9]);
-
-
-		//
-		// Moving to a later point in the array
-		//
-
-		// Shift 1 back
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 4, 8, 1);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(2, ints[2]);
-		assertEquals(3, ints[3]);
-		assertEquals(5, ints[4]);
-		assertEquals(6, ints[5]);
-		assertEquals(7, ints[6]);
-		assertEquals(8, ints[7]);
-		assertEquals(4, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift front 1 back
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 0, 7, 1);
-		assertEquals(1, ints[0]);
-		assertEquals(2, ints[1]);
-		assertEquals(3, ints[2]);
-		assertEquals(4, ints[3]);
-		assertEquals(5, ints[4]);
-		assertEquals(6, ints[5]);
-		assertEquals(7, ints[6]);
-		assertEquals(0, ints[7]);
-		assertEquals(8, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift 1 to end
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 4, 9, 1);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(2, ints[2]);
-		assertEquals(3, ints[3]);
-		assertEquals(5, ints[4]);
-		assertEquals(6, ints[5]);
-		assertEquals(7, ints[6]);
-		assertEquals(8, ints[7]);
-		assertEquals(9, ints[8]);
-		assertEquals(4, ints[9]);
-
-
-		//
-		// Moving to an earlier point in the array
-		//
-
-		// Shift 1 forward
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 8, 3, 1);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(2, ints[2]);
-		assertEquals(8, ints[3]);
-		assertEquals(3, ints[4]);
-		assertEquals(4, ints[5]);
-		assertEquals(5, ints[6]);
-		assertEquals(6, ints[7]);
-		assertEquals(7, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift end 1 forward
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 9, 2, 1);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(9, ints[2]);
-		assertEquals(2, ints[3]);
-		assertEquals(3, ints[4]);
-		assertEquals(4, ints[5]);
-		assertEquals(5, ints[6]);
-		assertEquals(6, ints[7]);
-		assertEquals(7, ints[8]);
-		assertEquals(8, ints[9]);
-
-		// Shift 1 to front
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 5, 0, 1);
-		assertEquals(5, ints[0]);
-		assertEquals(0, ints[1]);
-		assertEquals(1, ints[2]);
-		assertEquals(2, ints[3]);
-		assertEquals(3, ints[4]);
-		assertEquals(4, ints[5]);
-		assertEquals(6, ints[6]);
-		assertEquals(7, ints[7]);
-		assertEquals(8, ints[8]);
-		assertEquals(9, ints[9]);
-
-
-		//
-		// Moving many to a later point in the array
-		//
-
-		// Shift 3 back
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 2, 6, 3);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(5, ints[2]);
-		assertEquals(6, ints[3]);
-		assertEquals(7, ints[4]);
-		assertEquals(8, ints[5]);
-		assertEquals(2, ints[6]);
-		assertEquals(3, ints[7]);
-		assertEquals(4, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift 3 to back
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 2, 7, 3);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(5, ints[2]);
-		assertEquals(6, ints[3]);
-		assertEquals(7, ints[4]);
-		assertEquals(8, ints[5]);
-		assertEquals(9, ints[6]);
-		assertEquals(2, ints[7]);
-		assertEquals(3, ints[8]);
-		assertEquals(4, ints[9]);
-
-		// Shift from 3 front
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 0, 5, 3);
-		assertEquals(3, ints[0]);
-		assertEquals(4, ints[1]);
-		assertEquals(5, ints[2]);
-		assertEquals(6, ints[3]);
-		assertEquals(7, ints[4]);
-		assertEquals(0, ints[5]);
-		assertEquals(1, ints[6]);
-		assertEquals(2, ints[7]);
-		assertEquals(8, ints[8]);
-		assertEquals(9, ints[9]);
-
-
-		//
-		// Moving many to an earlier point in the array
-		//
-
-		// Shift 3 forward
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 6, 2, 3);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(6, ints[2]);
-		assertEquals(7, ints[3]);
-		assertEquals(8, ints[4]);
-		assertEquals(2, ints[5]);
-		assertEquals(3, ints[6]);
-		assertEquals(4, ints[7]);
-		assertEquals(5, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift 3 to front
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 6, 0, 3);
-		assertEquals(6, ints[0]);
-		assertEquals(7, ints[1]);
-		assertEquals(8, ints[2]);
-		assertEquals(0, ints[3]);
-		assertEquals(1, ints[4]);
-		assertEquals(2, ints[5]);
-		assertEquals(3, ints[6]);
-		assertEquals(4, ints[7]);
-		assertEquals(5, ints[8]);
-		assertEquals(9, ints[9]);
-
-		// Shift from 3 back
-		ints = getIntsList();
-		ArrayUtil.arrayMoveWithin(ints, 7, 3, 3);
-		assertEquals(0, ints[0]);
-		assertEquals(1, ints[1]);
-		assertEquals(2, ints[2]);
-		assertEquals(7, ints[3]);
-		assertEquals(8, ints[4]);
-		assertEquals(9, ints[5]);
-		assertEquals(3, ints[6]);
-		assertEquals(4, ints[7]);
-		assertEquals(5, ints[8]);
-		assertEquals(6, ints[9]);
+		// moveFrom, moveTo, numToMove, values...
+		Integer[][] data = {
+			// Moving to a later point in the array
+			// Shift 1 back
+			{ 4, 8, 1,      0, 1, 2, 3, 5, 6, 7, 8, 4, 9 },
+			// Shift front 1 back
+			{ 0, 7, 1,      1, 2, 3, 4, 5, 6, 7, 0, 8, 9 },
+			// Shift 1 to end
+			{ 4, 9, 1,      0, 1, 2, 3, 5, 6, 7, 8, 9, 4 },
+
+			// Moving to an earlier point in the array
+			// Shift 1 forward
+			{ 8, 3, 1,      0, 1, 2, 8, 3, 4, 5, 6, 7, 9 },
+			// Shift end 1 forward
+			{ 9, 2, 1,      0, 1, 9, 2, 3, 4, 5, 6, 7, 8 },
+			// Shift 1 to front
+			{ 5, 0, 1,      5, 0, 1, 2, 3, 4, 6, 7, 8, 9 },
+
+			// Moving many to a later point in the array
+			// Shift 3 back
+			{ 2, 6, 3,      0, 1, 5, 6, 7, 8, 2, 3, 4, 9 },
+			// Shift 3 to back
+			{ 2, 7, 3,      0, 1, 5, 6, 7, 8, 9, 2, 3, 4 },
+			// Shift from 3 front
+			{ 0, 5, 3,      3, 4, 5, 6, 7, 0, 1, 2, 8, 9 },
+
+			// Moving many to an earlier point in the array
+			// Shift 3 forward
+			{ 6, 2, 3,      0, 1, 6, 7, 8, 2, 3, 4, 5, 9 },
+			// Shift 3 to front
+			{ 6, 0, 3,      6, 7, 8, 0, 1, 2, 3, 4, 5, 9 },
+			// Shift from 3 back
+			{ 7, 3, 3,      0, 1, 2, 7, 8, 9, 3, 4, 5, 6 }
+		};
 
+		for (Integer[] entry : data) {
+			Integer[] ints = getIntsList();
+			ArrayUtil.arrayMoveWithin(ints, entry[0], entry[1], entry[2]);
+			assertArrayEquals(ints, Arrays.copyOfRange(entry, 3, 13));
+		}
 
 		// Check can't shift more than we have
 		try {
-			ints = getIntsList();
-			ArrayUtil.arrayMoveWithin(ints, 7, 3, 5);
+			ArrayUtil.arrayMoveWithin(getIntsList(), 7, 3, 5);
 			fail();
 		} catch(IllegalArgumentException e) {
 			// Good, we don't have 5 from 7 onwards
@@ -284,8 +108,7 @@ public class TestArrayUtil extends TestC
 
 		// Check can't shift where would overshoot
 		try {
-			ints = getIntsList();
-			ArrayUtil.arrayMoveWithin(ints, 2, 7, 5);
+			ArrayUtil.arrayMoveWithin(getIntsList(), 2, 7, 5);
 			fail();
 		} catch(IllegalArgumentException e) {
 			// Good, we can't fit 5 in starting at 7



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org