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 2020/12/24 18:42:38 UTC
svn commit: r1884783 [13/40] - in /poi:
site/src/documentation/content/xdocs/ trunk/ trunk/sonar/
trunk/sonar/integration-test/ trunk/sonar/ooxml/
trunk/src/excelant/poi-ant-contrib/
trunk/src/excelant/testcases/org/apache/poi/ss/excelant/ trunk/src/ex...
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Thu Dec 24 18:42:29 2020
@@ -17,15 +17,17 @@
package org.apache.poi.xssf.usermodel;
+import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-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.assertNotSame;
+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 java.io.IOException;
import java.util.Arrays;
@@ -55,6 +57,7 @@ import org.apache.poi.ss.usermodel.Index
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
@@ -67,7 +70,8 @@ import org.apache.poi.xssf.model.Comment
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
@@ -289,8 +293,8 @@ public final class TestXSSFSheet extends
sheet.removeMergedRegion(1);
sheet.removeMergedRegion(0);
assertEquals(0, sheet.getNumMergedRegions());
- assertNull(" CTMergeCells should be deleted after removing the last merged " +
- "region on the sheet.", sheet.getCTWorksheet().getMergeCells());
+ assertNull(sheet.getCTWorksheet().getMergeCells(),
+ "CTMergeCells should be deleted after removing the last merged region on the sheet.");
assertEquals(0, sheet.addMergedRegion(region_1));
assertEquals(1, sheet.addMergedRegion(region_2));
assertEquals(2, sheet.addMergedRegion(region_3));
@@ -415,23 +419,20 @@ public final class TestXSSFSheet extends
workbook.close();
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void setZoom() throws IOException {
- XSSFWorkbook workBook = new XSSFWorkbook();
- XSSFSheet sheet1 = workBook.createSheet("new sheet");
- sheet1.setZoom(75); // 75 percent magnification
- long zoom = sheet1.getCTWorksheet().getSheetViews().getSheetViewArray(0).getZoomScale();
- assertEquals(zoom, 75);
-
- sheet1.setZoom(200);
- zoom = sheet1.getCTWorksheet().getSheetViews().getSheetViewArray(0).getZoomScale();
- assertEquals(zoom, 200);
-
- // Valid scale values range from 10 to 400
- try {
- sheet1.setZoom(500);
- } finally {
- workBook.close();
+ try (XSSFWorkbook workBook = new XSSFWorkbook()) {
+ XSSFSheet sheet1 = workBook.createSheet("new sheet");
+ sheet1.setZoom(75); // 75 percent magnification
+ long zoom = sheet1.getCTWorksheet().getSheetViews().getSheetViewArray(0).getZoomScale();
+ assertEquals(zoom, 75);
+
+ sheet1.setZoom(200);
+ zoom = sheet1.getCTWorksheet().getSheetViews().getSheetViewArray(0).getZoomScale();
+ assertEquals(zoom, 200);
+
+ // Valid scale values range from 10 to 400
+ assertThrows(IllegalArgumentException.class, () -> sheet1.setZoom(500));
}
}
@@ -443,118 +444,117 @@ public final class TestXSSFSheet extends
*/
@Test
public void setColumnGroupCollapsed() throws IOException {
- XSSFWorkbook wb1 = new XSSFWorkbook();
- XSSFSheet sheet1 = wb1.createSheet();
-
- CTCols cols = sheet1.getCTWorksheet().getColsArray(0);
- assertEquals(0, cols.sizeOfColArray());
-
- sheet1.groupColumn( 4, 7 );
-
- assertEquals(1, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
-
- sheet1.groupColumn( 9, 12 );
-
- assertEquals(2, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
- checkColumnGroup(cols.getColArray(1), 9, 12); // false, true
-
- sheet1.groupColumn( 10, 11 );
-
- assertEquals(4, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
- checkColumnGroup(cols.getColArray(1), 9, 9); // false, true
- checkColumnGroup(cols.getColArray(2), 10, 11); // false, true
- checkColumnGroup(cols.getColArray(3), 12, 12); // false, true
+ try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
+ XSSFSheet sheet1 = wb1.createSheet();
- // collapse columns - 1
- sheet1.setColumnGroupCollapsed( 5, true );
+ CTCols cols = sheet1.getCTWorksheet().getColsArray(0);
+ assertEquals(0, cols.sizeOfColArray());
- // FIXME: we grew a column?
- assertEquals(5, cols.sizeOfColArray());
- checkColumnGroupIsCollapsed(cols.getColArray(0), 4, 7); // true, true
- checkColumnGroup(cols.getColArray(1), 8, 8); // false, true
- checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
- checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
- checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
-
-
- // expand columns - 1
- sheet1.setColumnGroupCollapsed( 5, false );
- assertEquals(5, cols.sizeOfColArray());
-
- checkColumnGroupIsExpanded(cols.getColArray(0), 4, 7); // false, true
- checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
- checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
- checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
- checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
-
-
- //collapse - 2
- sheet1.setColumnGroupCollapsed( 9, true );
- // it grew again?
- assertEquals(6, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
- checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
- checkColumnGroupIsCollapsed(cols.getColArray(2), 9, 9); // true, true
- checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
- checkColumnGroupIsCollapsed(cols.getColArray(4), 12, 12); // true, true
- // why was this column group added?
- checkColumnGroup(cols.getColArray(5), 13, 13); // false, true
-
-
- //expand - 2
- sheet1.setColumnGroupCollapsed( 9, false );
- assertEquals(6, cols.sizeOfColArray());
-
- //outline level 2: the line under ==> collapsed==True
- assertEquals(2, cols.getColArray(3).getOutlineLevel());
- assertTrue(cols.getColArray(4).isSetCollapsed());
-
- checkColumnGroup(cols.getColArray(0), 4, 7);
- checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
- checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
- checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
- checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
- checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
-
- //DOCUMENTARE MEGLIO IL DISCORSO DEL LIVELLO
- //collapse - 3
- sheet1.setColumnGroupCollapsed( 10, true );
- assertEquals(6, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7);
- checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
- checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
- checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
- checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
- checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
-
-
- //expand - 3
- sheet1.setColumnGroupCollapsed( 10, false );
- assertEquals(6, cols.sizeOfColArray());
- assertFalse(cols.getColArray(0).getHidden());
- assertFalse(cols.getColArray(5).getHidden());
- assertFalse(cols.getColArray(4).isSetCollapsed());
-
-// write out and give back
- // Save and re-load
- XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
- wb1.close();
- sheet1 = wb2.getSheetAt(0);
- // FIXME: forgot to reassign!
- //cols = sheet1.getCTWorksheet().getColsArray(0);
-
- assertEquals(6, cols.sizeOfColArray());
- checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
- checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
- checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
- checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
- checkColumnGroup(cols.getColArray(4), 12, 12, false, false);
- checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
+ sheet1.groupColumn(4, 7);
- wb2.close();
+ assertEquals(1, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+
+ sheet1.groupColumn(9, 12);
+
+ assertEquals(2, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+ checkColumnGroup(cols.getColArray(1), 9, 12); // false, true
+
+ sheet1.groupColumn(10, 11);
+
+ assertEquals(4, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+ checkColumnGroup(cols.getColArray(1), 9, 9); // false, true
+ checkColumnGroup(cols.getColArray(2), 10, 11); // false, true
+ checkColumnGroup(cols.getColArray(3), 12, 12); // false, true
+
+ // collapse columns - 1
+ sheet1.setColumnGroupCollapsed(5, true);
+
+ // FIXME: we grew a column?
+ assertEquals(5, cols.sizeOfColArray());
+ checkColumnGroupIsCollapsed(cols.getColArray(0), 4, 7); // true, true
+ checkColumnGroup(cols.getColArray(1), 8, 8); // false, true
+ checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
+ checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
+ checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
+
+
+ // expand columns - 1
+ sheet1.setColumnGroupCollapsed(5, false);
+ assertEquals(5, cols.sizeOfColArray());
+
+ checkColumnGroupIsExpanded(cols.getColArray(0), 4, 7); // false, true
+ checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
+ checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
+ checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
+ checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
+
+
+ //collapse - 2
+ sheet1.setColumnGroupCollapsed(9, true);
+ // it grew again?
+ assertEquals(6, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+ checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
+ checkColumnGroupIsCollapsed(cols.getColArray(2), 9, 9); // true, true
+ checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
+ checkColumnGroupIsCollapsed(cols.getColArray(4), 12, 12); // true, true
+ // why was this column group added?
+ checkColumnGroup(cols.getColArray(5), 13, 13); // false, true
+
+
+ //expand - 2
+ sheet1.setColumnGroupCollapsed(9, false);
+ assertEquals(6, cols.sizeOfColArray());
+
+ //outline level 2: the line under ==> collapsed==True
+ assertEquals(2, cols.getColArray(3).getOutlineLevel());
+ assertTrue(cols.getColArray(4).isSetCollapsed());
+
+ checkColumnGroup(cols.getColArray(0), 4, 7);
+ checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
+ checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
+ checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
+ checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
+ checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
+
+ //DOCUMENTARE MEGLIO IL DISCORSO DEL LIVELLO
+ //collapse - 3
+ sheet1.setColumnGroupCollapsed(10, true);
+ assertEquals(6, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7);
+ checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
+ checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
+ checkColumnGroupIsCollapsed(cols.getColArray(3), 10, 11); // true, true
+ checkColumnGroup(cols.getColArray(4), 12, 12); // false, true
+ checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
+
+
+ //expand - 3
+ sheet1.setColumnGroupCollapsed(10, false);
+ assertEquals(6, cols.sizeOfColArray());
+ assertFalse(cols.getColArray(0).getHidden());
+ assertFalse(cols.getColArray(5).getHidden());
+ assertFalse(cols.getColArray(4).isSetCollapsed());
+
+ // write out and give back
+ // Save and re-load
+ try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1)) {
+ sheet1 = wb2.getSheetAt(0);
+ // FIXME: forgot to reassign!
+ //cols = sheet1.getCTWorksheet().getColsArray(0);
+
+ assertEquals(6, cols.sizeOfColArray());
+ checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+ checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
+ checkColumnGroup(cols.getColArray(2), 9, 9); // false, true
+ checkColumnGroup(cols.getColArray(3), 10, 11); // false, true
+ checkColumnGroup(cols.getColArray(4), 12, 12, false, false);
+ checkColumnGroup(cols.getColArray(5), 13, 13, false, false);
+ }
+ }
}
/**
@@ -570,10 +570,10 @@ public final class TestXSSFSheet extends
int fromColumnIndex, int toColumnIndex,
boolean isSetHidden, boolean isSetCollapsed
) {
- assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
- assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertEquals("isSetHidden", isSetHidden, col.isSetHidden());
- assertEquals("isSetCollapsed", isSetCollapsed, col.isSetCollapsed()); //not necessarily set
+ assertEquals(fromColumnIndex, col.getMin() - 1, "from column index"); // 1 based
+ assertEquals(toColumnIndex, col.getMax() - 1, "to column index"); // 1 based
+ assertEquals(isSetHidden, col.isSetHidden(), "isSetHidden");
+ assertEquals(isSetCollapsed, col.isSetCollapsed(), "isSetCollapsed"); //not necessarily set
}
/**
@@ -583,15 +583,13 @@ public final class TestXSSFSheet extends
* @param fromColumnIndex 0-indexed
* @param toColumnIndex 0-indexed
*/
- private static void checkColumnGroup(
- CTCol col,
- int fromColumnIndex, int toColumnIndex
- ) {
- assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
- assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertFalse("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed()); //not necessarily set
+ private static void checkColumnGroup(CTCol col, int fromColumnIndex, int toColumnIndex) {
+ assertEquals(fromColumnIndex, col.getMin() - 1, "from column index"); // 1 based
+ assertEquals(toColumnIndex, col.getMax() - 1, "to column index"); // 1 based
+ assertFalse(col.isSetHidden(), "isSetHidden");
+ assertTrue(col.isSetCollapsed(), "isSetCollapsed"); //not necessarily set
}
+
/**
* Verify that column groups were created correctly after Sheet.groupColumn
*
@@ -599,16 +597,14 @@ public final class TestXSSFSheet extends
* @param fromColumnIndex 0-indexed
* @param toColumnIndex 0-indexed
*/
- private static void checkColumnGroupIsCollapsed(
- CTCol col,
- int fromColumnIndex, int toColumnIndex
- ) {
- assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
- assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertTrue("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed());
- //assertTrue("getCollapsed", col.getCollapsed());
+ private static void checkColumnGroupIsCollapsed(CTCol col, int fromColumnIndex, int toColumnIndex) {
+ assertEquals(fromColumnIndex, col.getMin() - 1, "from column index"); // 1 based
+ assertEquals(toColumnIndex, col.getMax() - 1, "to column index"); // 1 based
+ assertTrue(col.isSetHidden(), "isSetHidden");
+ assertTrue(col.isSetCollapsed(), "isSetCollapsed");
+ //assertTrue(col.getCollapsed(), "getCollapsed");
}
+
/**
* Verify that column groups were created correctly after Sheet.groupColumn
*
@@ -617,16 +613,13 @@ public final class TestXSSFSheet extends
* @param toColumnIndex 0-indexed
*/
@SuppressWarnings("SameParameterValue")
- private static void checkColumnGroupIsExpanded(
- CTCol col,
- int fromColumnIndex, int toColumnIndex
- ) {
- assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
- assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertFalse("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed());
- //assertTrue("isSetCollapsed", !col.isSetCollapsed() || !col.getCollapsed());
- //assertFalse("getCollapsed", col.getCollapsed());
+ private static void checkColumnGroupIsExpanded(CTCol col, int fromColumnIndex, int toColumnIndex) {
+ assertEquals(fromColumnIndex, col.getMin() - 1, "from column index"); // 1 based
+ assertEquals(toColumnIndex, col.getMax() - 1, "to column index"); // 1 based
+ assertFalse(col.isSetHidden(), "isSetHidden");
+ assertTrue(col.isSetCollapsed(), "isSetCollapsed");
+ //assertTrue(!col.isSetCollapsed() || !col.getCollapsed(), "isSetCollapsed");
+ //assertFalse(col.getCollapsed(), "getCollapsed");
}
/**
@@ -1043,20 +1036,20 @@ public final class TestXSSFSheet extends
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection();
- assertNull("CTSheetProtection should be null by default", pr);
+ assertNull(pr, "CTSheetProtection should be null by default");
String password = "Test";
sheet.protectSheet(password);
pr = sheet.getCTWorksheet().getSheetProtection();
- assertNotNull("CTSheetProtection should be not null", pr);
- assertTrue("sheet protection should be on", pr.isSetSheet());
- assertTrue("object protection should be on", pr.isSetObjects());
- assertTrue("scenario protection should be on", pr.isSetScenarios());
+ assertNotNull(pr, "CTSheetProtection should be not null");
+ assertTrue(pr.isSetSheet(), "sheet protection should be on");
+ assertTrue(pr.isSetObjects(), "object protection should be on");
+ assertTrue(pr.isSetScenarios(), "scenario protection should be on");
int hashVal = CryptoFunctions.createXorVerifier1(password);
int actualVal = Integer.parseInt(pr.xgetPassword().getStringValue(),16);
- assertEquals("well known value for top secret hash should match", hashVal, actualVal);
+ assertEquals(hashVal, actualVal, "well known value for top secret hash should match");
sheet.protectSheet(null);
- assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
+ assertNull(sheet.getCTWorksheet().getSheetProtection(), "protectSheet(null) should unset CTSheetProtection");
wb.close();
}
@@ -1066,21 +1059,21 @@ public final class TestXSSFSheet extends
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection();
- assertNull("CTSheetProtection should be null by default", pr);
+ assertNull(pr, "CTSheetProtection should be null by default");
String password = "";
sheet.protectSheet(password);
pr = sheet.getCTWorksheet().getSheetProtection();
- assertNotNull("CTSheetProtection should be not null", pr);
- assertTrue("sheet protection should be on", pr.isSetSheet());
- assertTrue("object protection should be on", pr.isSetObjects());
- assertTrue("scenario protection should be on", pr.isSetScenarios());
+ assertNotNull(pr, "CTSheetProtection should be not null");
+ assertTrue(pr.isSetSheet(), "sheet protection should be on");
+ assertTrue(pr.isSetObjects(), "object protection should be on");
+ assertTrue(pr.isSetScenarios(), "scenario protection should be on");
int hashVal = CryptoFunctions.createXorVerifier1(password);
STUnsignedShortHex xpassword = pr.xgetPassword();
int actualVal = Integer.parseInt(xpassword.getStringValue(),16);
- assertEquals("well known value for top secret hash should match", hashVal, actualVal);
+ assertEquals(hashVal, actualVal, "well known value for top secret hash should match");
sheet.protectSheet(null);
- assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
+ assertNull(sheet.getCTWorksheet().getSheetProtection(), "protectSheet(null) should unset CTSheetProtection");
wb.close();
}
@@ -1113,8 +1106,7 @@ public final class TestXSSFSheet extends
XSSFRow row = sheet.getRow(0);
sheet.removeRow(row);
- assertEquals("XSSFSheet#removeRow did not clear calcChain entries",
- 0, calcChain.getCTCalcChain().sizeOfCArray());
+ assertEquals(0, calcChain.getCTCalcChain().sizeOfCArray(), "XSSFSheet#removeRow did not clear calcChain entries");
//calcChain should be gone
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
@@ -1208,7 +1200,7 @@ public final class TestXSSFSheet extends
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
Sheet sh = wb.getSheetAt(si);
assertNotNull(sh.getSheetName());
- assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
+ assertEquals(topRows[si], sh.getTopRow(), "Did not match for sheet " + si);
}
// for XSSF also test with SXSSF
@@ -1217,7 +1209,7 @@ public final class TestXSSFSheet extends
for (int si = 0; si < swb.getNumberOfSheets(); si++) {
Sheet sh = swb.getSheetAt(si);
assertNotNull(sh.getSheetName());
- assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow());
+ assertEquals(topRows[si], sh.getTopRow(), "Did not match for sheet " + si);
}
swb.close();
}
@@ -1233,7 +1225,7 @@ public final class TestXSSFSheet extends
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
Sheet sh = wb.getSheetAt(si);
assertNotNull(sh.getSheetName());
- assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
+ assertEquals(topRows[si], sh.getLeftCol(), "Did not match for sheet " + si);
}
// for XSSF also test with SXSSF
@@ -1242,7 +1234,7 @@ public final class TestXSSFSheet extends
for (int si = 0; si < swb.getNumberOfSheets(); si++) {
Sheet sh = swb.getSheetAt(si);
assertNotNull(sh.getSheetName());
- assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol());
+ assertEquals(topRows[si], sh.getLeftCol(), "Did not match for sheet " + si);
}
swb.close();
}
@@ -1252,22 +1244,12 @@ public final class TestXSSFSheet extends
@Test
public void bug55745() throws Exception {
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55745.xlsx");
- XSSFSheet sheet = wb.getSheetAt(0);
- List<XSSFTable> tables = sheet.getTables();
- /*System.out.println(tables.size());
-
- for(XSSFTable table : tables) {
- System.out.println("XPath: " + table.getCommonXpath());
- System.out.println("Name: " + table.getName());
- System.out.println("Mapped Cols: " + table.getNumberOfMappedColumns());
- System.out.println("Rowcount: " + table.getRowCount());
- System.out.println("End Cell: " + table.getEndCellReference());
- System.out.println("Start Cell: " + table.getStartCellReference());
- }*/
- assertEquals("Sheet should contain 8 tables", 8, tables.size());
- assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false));
- wb.close();
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55745.xlsx")) {
+ XSSFSheet sheet = wb.getSheetAt(0);
+ List<XSSFTable> tables = sheet.getTables();
+ assertEquals(8, tables.size(), "Sheet should contain 8 tables");
+ assertNotNull(sheet.getCommentsTable(false), "Sheet should contain a comments table");
+ }
}
@Test
@@ -1299,7 +1281,8 @@ public final class TestXSSFSheet extends
wb.close();
}
- @Test(timeout=180000)
+ @Timeout(value = 180, unit = SECONDS)
+ @Test
public void bug51585() throws IOException {
XSSFTestDataSamples.openSampleWorkbook("51585.xlsx").close();
}
@@ -1409,29 +1392,25 @@ public final class TestXSSFSheet extends
wb.close();
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testCreatePivotTableWithConflictingDataSheets() throws IOException {
- XSSFWorkbook wb = setupSheet();
- XSSFSheet sheet = wb.getSheetAt(0);
- XSSFSheet sheet2 = wb.createSheet("TEST");
+ try (XSSFWorkbook wb = setupSheet()) {
+ XSSFSheet sheet = wb.getSheetAt(0);
+ XSSFSheet sheet2 = wb.createSheet("TEST");
+ CellReference cr = new CellReference("H5");
+ AreaReference ar = wb.getCreationHelper().createAreaReference(sheet.getSheetName() + "!A$1:B$2");
- sheet2.createPivotTable(
- wb.getCreationHelper().createAreaReference(sheet.getSheetName()+"!A$1:B$2"),
- new CellReference("H5"),
- sheet2);
- wb.close();
+ assertThrows(IllegalArgumentException.class, () -> sheet2.createPivotTable(ar, cr, sheet2));
+ }
}
- @Test(expected=POIXMLException.class)
+ @Test
public void testReadFails() throws IOException {
- XSSFWorkbook wb = new XSSFWorkbook();
- XSSFSheet sheet = wb.createSheet();
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = wb.createSheet();
- // Throws exception because we cannot read here
- try {
- sheet.onDocumentRead();
- } finally {
- wb.close();
+ // Throws exception because we cannot read here
+ assertThrows(POIXMLException.class, sheet::onDocumentRead);
}
}
@@ -1451,7 +1430,7 @@ public final class TestXSSFSheet extends
wb.close();
}
- protected void testCopyOneRow(String copyRowsTestWorkbook) throws IOException {
+ private void testCopyOneRow(String copyRowsTestWorkbook) throws IOException {
final double FLOAT_PRECISION = 1e-9;
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook);
final XSSFSheet sheet = wb.getSheetAt(0);
@@ -1468,98 +1447,91 @@ public final class TestXSSFSheet extends
// Style
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Style] B7 cell value", "Red", cell.getStringCellValue());
- assertEquals("[Style] B7 cell style", CellUtil.getCell(srcRow, 1).getCellStyle(), cell.getCellStyle());
+ assertEquals("Red", cell.getStringCellValue(), "[Style] B7 cell value");
+ assertEquals(CellUtil.getCell(srcRow, 1).getCellStyle(), cell.getCellStyle(), "[Style] B7 cell style");
// Blank
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Blank] C7 cell type", CellType.BLANK, cell.getCellType());
+ assertEquals(CellType.BLANK, cell.getCellType(), "[Blank] C7 cell type");
// Error
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Error] D7 cell type", CellType.ERROR, cell.getCellType());
+ assertEquals(CellType.ERROR, cell.getCellType(), "[Error] D7 cell type");
final FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
- assertEquals("[Error] D7 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ assertEquals(FormulaError.NA, error, "[Error] D7 cell value");
// Date
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Date] E7 cell type", CellType.NUMERIC, cell.getCellType());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Date] E7 cell type");
final Date date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 1).getTime();
- assertEquals("[Date] E7 cell value", date, cell.getDateCellValue());
+ assertEquals(date, cell.getDateCellValue(), "[Date] E7 cell value");
// Boolean
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Boolean] F7 cell type", CellType.BOOLEAN, cell.getCellType());
- assertTrue("[Boolean] F7 cell value", cell.getBooleanCellValue());
+ assertEquals(CellType.BOOLEAN, cell.getCellType(), "[Boolean] F7 cell type");
+ assertTrue(cell.getBooleanCellValue(), "[Boolean] F7 cell value");
// String
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[String] G7 cell type", CellType.STRING, cell.getCellType());
- assertEquals("[String] G7 cell value", "Hello", cell.getStringCellValue());
+ assertEquals(CellType.STRING, cell.getCellType(), "[String] G7 cell type");
+ assertEquals("Hello", cell.getStringCellValue(), "[String] G7 cell value");
// Int
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Int] H7 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Int] H7 cell value", 15, (int) cell.getNumericCellValue());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Int] H7 cell type");
+ assertEquals(15, (int) cell.getNumericCellValue(), "[Int] H7 cell value");
// Float
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Float] I7 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Float] I7 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Float] I7 cell type");
+ assertEquals(12.5, cell.getNumericCellValue(), FLOAT_PRECISION, "[Float] I7 cell value");
// Cell Formula
cell = CellUtil.getCell(destRow, col++);
assertEquals("Sheet1!J7", new CellReference(cell).formatAsString());
- assertEquals("[Cell Formula] J7 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula] J7 cell formula", "5+2", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula] J7 cell type");
+ assertEquals("5+2", cell.getCellFormula(), "[Cell Formula] J7 cell formula");
//System.out.println("Cell formula evaluation currently unsupported");
// Cell Formula with Reference
// Formula row references should be adjusted by destRowNum-srcRowNum
cell = CellUtil.getCell(destRow, col++);
assertEquals("Sheet1!K7", new CellReference(cell).formatAsString());
- assertEquals("[Cell Formula with Reference] K7 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference] K7 cell formula",
- "J7+H$2", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference] K7 cell type");
+ assertEquals("J7+H$2", cell.getCellFormula(), "[Cell Formula with Reference] K7 cell formula");
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell formula",
- "G7&\" \"&G8", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference spanning multiple rows] L7 cell type");
+ assertEquals("G7&\" \"&G8", cell.getCellFormula(), "[Cell Formula with Reference spanning multiple rows] L7 cell formula");
// Cell Formula with Reference spanning multiple rows
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Cell Formula with Area Reference] M7 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Area Reference] M7 cell formula",
- "SUM(H7:I8)", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Area Reference] M7 cell type");
+ assertEquals("SUM(H7:I8)", cell.getCellFormula(), "[Cell Formula with Area Reference] M7 cell formula");
// Array Formula
cell = CellUtil.getCell(destRow, col++);
//System.out.println("Array formulas currently unsupported");
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
/*
- assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Array Formula] N7 cell formula", "{SUM(H7:J7*{1,2,3})}", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Array Formula] N7 cell type");
+ assertEquals("{SUM(H7:J7*{1,2,3})}", cell.getCellFormula(), "[Array Formula] N7 cell formula");
*/
// Data Format
cell = CellUtil.getCell(destRow, col++);
- assertEquals("[Data Format] O7 cell type;", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Data Format] O7 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION);
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Data Format] O7 cell type");
+ assertEquals(100.20, cell.getNumericCellValue(), FLOAT_PRECISION, "[Data Format] O7 cell value");
//FIXME: currently fails
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
- assertEquals("[Data Format] O7 data format", moneyFormat, cell.getCellStyle().getDataFormatString());
+ assertEquals(moneyFormat, cell.getCellStyle().getDataFormatString(), "[Data Format] O7 data format");
// Merged
cell = CellUtil.getCell(destRow, col);
- assertEquals("[Merged] P7:Q7 cell value",
- "Merged cells", cell.getStringCellValue());
- assertTrue("[Merged] P7:Q7 merged region",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P7:Q7")));
+ assertEquals("Merged cells", cell.getStringCellValue(), "[Merged] P7:Q7 cell value");
+ assertTrue(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P7:Q7")), "[Merged] P7:Q7 merged region");
// Merged across multiple rows
// Microsoft Excel 2013 does not copy a merged region unless all rows of
@@ -1574,12 +1546,11 @@ public final class TestXSSFSheet extends
//assertFalse("[Merged across multiple rows] R7:S8 merged region",
// sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8")));
// As currently implemented, cell value is copied but merged region is not copied
- assertEquals("[Merged across multiple rows] R7:S8 cell value",
- "Merged cells across multiple rows", cell.getStringCellValue());
- assertFalse("[Merged across multiple rows] R7:S7 merged region (one row)",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S7"))); //shouldn't do 1-row merge
- assertFalse("[Merged across multiple rows] R7:S8 merged region",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8"))); //shouldn't do 2-row merge
+ assertEquals("Merged cells across multiple rows", cell.getStringCellValue(), "[Merged across multiple rows] R7:S8 cell value");
+ // shouldn't do 1-row merge
+ assertFalse(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S7")), "[Merged across multiple rows] R7:S7 merged region (one row)");
+ //shouldn't do 2-row merge
+ assertFalse(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8")), "[Merged across multiple rows] R7:S8 merged region");
// Make sure other rows are blank (off-by-one errors)
assertNull(sheet.getRow(5));
@@ -1588,7 +1559,7 @@ public final class TestXSSFSheet extends
wb.close();
}
- protected void testCopyMultipleRows(String copyRowsTestWorkbook) throws IOException {
+ private void testCopyMultipleRows(String copyRowsTestWorkbook) throws IOException {
final double FLOAT_PRECISION = 1e-9;
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(copyRowsTestWorkbook);
final XSSFSheet sheet = wb.getSheetAt(0);
@@ -1616,135 +1587,128 @@ public final class TestXSSFSheet extends
// Style
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Style] B10 cell value", "Red", cell.getStringCellValue());
- assertEquals("[Style] B10 cell style", CellUtil.getCell(srcRow1, 1).getCellStyle(), cell.getCellStyle());
+ assertEquals("Red", cell.getStringCellValue(), "[Style] B10 cell value");
+ assertEquals(CellUtil.getCell(srcRow1, 1).getCellStyle(), cell.getCellStyle(), "[Style] B10 cell style");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Style] B11 cell value", "Blue", cell.getStringCellValue());
- assertEquals("[Style] B11 cell style", CellUtil.getCell(srcRow2, 1).getCellStyle(), cell.getCellStyle());
+ assertEquals("Blue", cell.getStringCellValue(), "[Style] B11 cell value");
+ assertEquals(CellUtil.getCell(srcRow2, 1).getCellStyle(), cell.getCellStyle(), "[Style] B11 cell style");
// Blank
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Blank] C10 cell type", CellType.BLANK, cell.getCellType());
+ assertEquals(CellType.BLANK, cell.getCellType(), "[Blank] C10 cell type");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Blank] C11 cell type", CellType.BLANK, cell.getCellType());
+ assertEquals(CellType.BLANK, cell.getCellType(), "[Blank] C11 cell type");
// Error
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Error] D10 cell type", CellType.ERROR, cell.getCellType());
FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
- assertEquals("[Error] D10 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ assertEquals(CellType.ERROR, cell.getCellType(), "[Error] D10 cell type");
+ assertEquals(FormulaError.NA, error, "[Error] D10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Error] D11 cell type", CellType.ERROR, cell.getCellType());
error = FormulaError.forInt(cell.getErrorCellValue());
- assertEquals("[Error] D11 cell value", FormulaError.NAME, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here
+ assertEquals(CellType.ERROR, cell.getCellType(), "[Error] D11 cell type");
+ assertEquals(FormulaError.NAME, error, "[Error] D11 cell value");
// Date
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Date] E10 cell type", CellType.NUMERIC, cell.getCellType());
Date date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 1).getTime();
- assertEquals("[Date] E10 cell value", date, cell.getDateCellValue());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Date] E10 cell type");
+ assertEquals(date, cell.getDateCellValue(), "[Date] E10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Date] E11 cell type", CellType.NUMERIC, cell.getCellType());
date = LocaleUtil.getLocaleCalendar(2000, Calendar.JANUARY, 2).getTime();
- assertEquals("[Date] E11 cell value", date, cell.getDateCellValue());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Date] E11 cell type");
+ assertEquals(date, cell.getDateCellValue(), "[Date] E11 cell value");
// Boolean
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Boolean] F10 cell type", CellType.BOOLEAN, cell.getCellType());
- assertTrue("[Boolean] F10 cell value", cell.getBooleanCellValue());
+ assertEquals(CellType.BOOLEAN, cell.getCellType(), "[Boolean] F10 cell type");
+ assertTrue(cell.getBooleanCellValue(), "[Boolean] F10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Boolean] F11 cell type", CellType.BOOLEAN, cell.getCellType());
- assertFalse("[Boolean] F11 cell value", cell.getBooleanCellValue());
+ assertEquals(CellType.BOOLEAN, cell.getCellType(), "[Boolean] F11 cell type");
+ assertFalse(cell.getBooleanCellValue(), "[Boolean] F11 cell value");
// String
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[String] G10 cell type", CellType.STRING, cell.getCellType());
- assertEquals("[String] G10 cell value", "Hello", cell.getStringCellValue());
+ assertEquals(CellType.STRING, cell.getCellType(), "[String] G10 cell type");
+ assertEquals("Hello", cell.getStringCellValue(), "[String] G10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[String] G11 cell type", CellType.STRING, cell.getCellType());
- assertEquals("[String] G11 cell value", "World", cell.getStringCellValue());
+ assertEquals(CellType.STRING, cell.getCellType(), "[String] G11 cell type");
+ assertEquals("World", cell.getStringCellValue(), "[String] G11 cell value");
// Int
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Int] H10 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Int] H10 cell value", 15, (int) cell.getNumericCellValue());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Int] H10 cell type");
+ assertEquals(15, (int) cell.getNumericCellValue(), "[Int] H10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Int] H11 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Int] H11 cell value", 42, (int) cell.getNumericCellValue());
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Int] H11 cell type");
+ assertEquals(42, (int) cell.getNumericCellValue(), "[Int] H11 cell value");
// Float
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Float] I10 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Float] I10 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION);
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Float] I10 cell type");
+ assertEquals(12.5, cell.getNumericCellValue(), FLOAT_PRECISION, "[Float] I10 cell value");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Float] I11 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Float] I11 cell value", 5.5, cell.getNumericCellValue(), FLOAT_PRECISION);
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Float] I11 cell type");
+ assertEquals(5.5, cell.getNumericCellValue(), FLOAT_PRECISION, "[Float] I11 cell value");
// Cell Formula
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Cell Formula] J10 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula] J10 cell formula", "5+2", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula] J10 cell type");
+ assertEquals("5+2", cell.getCellFormula(), "[Cell Formula] J10 cell formula");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula] J11 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula] J11 cell formula", "6+18", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula] J11 cell type");
+ assertEquals("6+18", cell.getCellFormula(), "[Cell Formula] J11 cell formula");
// Cell Formula with Reference
col++;
// Formula row references should be adjusted by destRowNum-srcRowNum
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Cell Formula with Reference] K10 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference] K10 cell formula",
- "J10+H$2", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference] K10 cell type");
+ assertEquals("J10+H$2", cell.getCellFormula(), "[Cell Formula with Reference] K10 cell formula");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula with Reference] K11 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference] K11 cell formula", "J11+H$2", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference] K11 cell type");
+ assertEquals("J11+H$2", cell.getCellFormula(), "[Cell Formula with Reference] K11 cell formula");
// Cell Formula with Reference spanning multiple rows
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell formula",
- "G10&\" \"&G11", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference spanning multiple rows] L10 cell type");
+ assertEquals("G10&\" \"&G11", cell.getCellFormula(), "[Cell Formula with Reference spanning multiple rows] L10 cell formula");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula",
- "G11&\" \"&G12", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Reference spanning multiple rows] L11 cell type");
+ assertEquals("G11&\" \"&G12", cell.getCellFormula(), "[Cell Formula with Reference spanning multiple rows] L11 cell formula");
// Cell Formula with Area Reference
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Cell Formula with Area Reference] M10 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Area Reference] M10 cell formula",
- "SUM(H10:I11)", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Area Reference] M10 cell type");
+ assertEquals("SUM(H10:I11)", cell.getCellFormula(), "[Cell Formula with Area Reference] M10 cell formula");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Cell Formula with Area Reference] M11 cell type",
- CellType.FORMULA, cell.getCellType());
- assertEquals("[Cell Formula with Area Reference] M11 cell formula",
- "SUM($H$3:I10)", cell.getCellFormula()); //Also acceptable: SUM($H10:I$3), but this AreaReference isn't in ascending order
+ // Also acceptable: SUM($H10:I$3), but this AreaReference isn't in ascending order
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Cell Formula with Area Reference] M11 cell type");
+ assertEquals("SUM($H$3:I10)", cell.getCellFormula(), "[Cell Formula with Area Reference] M11 cell formula");
// Array Formula
col++;
@@ -1752,35 +1716,32 @@ public final class TestXSSFSheet extends
// System.out.println("Array formulas currently unsupported");
/*
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N10 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Array Formula] N10 cell formula", "{SUM(H10:J10*{1,2,3})}", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(), "[Array Formula] N10 cell type");
+ assertEquals("{SUM(H10:J10*{1,2,3})}", cell.getCellFormula(), "[Array Formula] N10 cell formula");
cell = CellUtil.getCell(destRow2, col);
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N11 cell type", CellType.FORMULA, cell.getCellType());
- assertEquals("[Array Formula] N11 cell formula", "{SUM(H11:J11*{1,2,3})}", cell.getCellFormula());
+ assertEquals(CellType.FORMULA, cell.getCellType(). "[Array Formula] N11 cell type");
+ assertEquals("{SUM(H11:J11*{1,2,3})}", cell.getCellFormula(). "[Array Formula] N11 cell formula");
*/
// Data Format
col++;
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Data Format] O10 cell type", CellType.NUMERIC, cell.getCellType());
- assertEquals("[Data Format] O10 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION);
+ assertEquals(CellType.NUMERIC, cell.getCellType(), "[Data Format] O10 cell type");
+ assertEquals(100.20, cell.getNumericCellValue(), FLOAT_PRECISION, "[Data Format] O10 cell value");
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
- assertEquals("[Data Format] O10 cell data format", moneyFormat, cell.getCellStyle().getDataFormatString());
+ assertEquals(moneyFormat, cell.getCellStyle().getDataFormatString(), "[Data Format] O10 cell data format");
// Merged
col++;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Merged] P10:Q10 cell value",
- "Merged cells", cell.getStringCellValue());
- assertTrue("[Merged] P10:Q10 merged region",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P10:Q10")));
+ assertEquals("Merged cells", cell.getStringCellValue(), "[Merged] P10:Q10 cell value");
+ assertTrue(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P10:Q10")), "[Merged] P10:Q10 merged region");
cell = CellUtil.getCell(destRow2, col);
- assertEquals("[Merged] P11:Q11 cell value", "Merged cells", cell.getStringCellValue());
- assertTrue("[Merged] P11:Q11 merged region",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P11:Q11")));
+ assertEquals("Merged cells", cell.getStringCellValue(), "[Merged] P11:Q11 cell value");
+ assertTrue(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P11:Q11")), "[Merged] P11:Q11 merged region");
// Should Q10/Q11 be checked?
@@ -1790,19 +1751,17 @@ public final class TestXSSFSheet extends
// POI's behavior should match this behavior
col += 2;
cell = CellUtil.getCell(destRow1, col);
- assertEquals("[Merged across multiple rows] R10:S11 cell value",
- "Merged cells across multiple rows", cell.getStringCellValue());
- assertTrue("[Merged across multiple rows] R10:S11 merged region",
- sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R10:S11")));
+ assertEquals("Merged cells across multiple rows", cell.getStringCellValue(), "[Merged across multiple rows] R10:S11 cell value");
+ assertTrue(sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R10:S11")), "[Merged across multiple rows] R10:S11 merged region");
// Row 3 (zero-based) was empty, so Row 11 (zero-based) should be empty too.
if (srcRow3 == null) {
- assertNull("Row 3 was empty, so Row 11 should be empty", destRow3);
+ assertNull(destRow3, "Row 3 was empty, so Row 11 should be empty");
}
// Make sure other rows are blank (off-by-one errors)
- assertNull("Off-by-one lower edge case", sheet.getRow(7)); //one row above destHeaderRow
- assertNull("Off-by-one upper edge case", sheet.getRow(12)); //one row below destRow3
+ assertNull(sheet.getRow(7), "Off-by-one lower edge case"); //one row above destHeaderRow
+ assertNull(sheet.getRow(12), "Off-by-one upper edge case"); //one row below destRow3
wb.close();
}
@@ -1956,16 +1915,16 @@ public final class TestXSSFSheet extends
for (int i = 0; i < 2; i++) {
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
- anchor.setRow1(0 + i);
+ anchor.setRow1(i);
anchor.setCol2(2);
anchor.setRow2(3 + i);
Comment comment = drawing.createCellComment(anchor);
comment.setString(helper.createRichTextString("BugTesting"));
- Row row = sheet.getRow(0 + i);
+ Row row = sheet.getRow(i);
if (row == null) {
- row = sheet.createRow(0 + i);
+ row = sheet.createRow(i);
}
Cell cell = row.getCell(0);
if (cell == null) {
@@ -1980,20 +1939,19 @@ public final class TestXSSFSheet extends
// bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
@Test
public void testRemoveRowWithCommentAndGapAbove() throws IOException {
- final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx");
- final Sheet sheet = wb.getSheetAt(0);
+ try (Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx")) {
+ final Sheet sheet = wb.getSheetAt(0);
- // comment exists
- CellAddress commentCellAddress = new CellAddress("A4");
- assertNotNull(sheet.getCellComment(commentCellAddress));
+ // comment exists
+ CellAddress commentCellAddress = new CellAddress("A4");
+ assertNotNull(sheet.getCellComment(commentCellAddress));
- assertEquals("Wrong starting # of comments", 1, sheet.getCellComments().size());
+ assertEquals(1, sheet.getCellComments().size(), "Wrong starting # of comments");
- sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
+ sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
- assertEquals("There should not be any comments left!", 0, sheet.getCellComments().size());
-
- wb.close();
+ assertEquals(0, sheet.getCellComments().size(), "There should not be any comments left!");
+ }
}
@Test
@@ -2037,7 +1995,7 @@ public final class TestXSSFSheet extends
// on sheet-level, the flag is still set
for (Sheet s : wb) {
- assertTrue("Sheet-level flag is still set to true", s.getForceFormulaRecalculation());
+ assertTrue(s.getForceFormulaRecalculation(), "Sheet-level flag is still set to true");
}
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.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 java.io.IOException;
import java.util.List;
@@ -25,7 +25,7 @@ import org.apache.poi.ss.util.CellRangeA
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;
public class TestXSSFSheetMergeRegions {
@@ -54,8 +54,8 @@ public class TestXSSFSheetMergeRegions {
// This time is typically ~800ms, versus ~7800ms to iterate getMergedRegion(int).
// when running in Gump, the VM is very slow, so we should allow much more time
- assertTrue("Should have taken <2000 ms to iterate 50k merged regions but took " + millis,
- inGump ? millis < 8000 : millis < 2000);
+ assertTrue(inGump ? millis < 8000 : millis < 2000,
+ "Should have taken <2000 ms to iterate 50k merged regions but took " + millis);
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetRowGrouping.java Thu Dec 24 18:42:29 2020
@@ -17,8 +17,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;
@@ -27,7 +27,7 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public final class TestXSSFSheetRowGrouping {
@@ -310,20 +310,20 @@ public final class TestXSSFSheetRowGroup
assertEquals(collapsed.length, hidden.length);
assertEquals(collapsed.length, outlineLevel.length);
- assertEquals("Expected " + collapsed.length + " rows with collapsed state, but had " + (sheet.getLastRowNum()-sheet.getFirstRowNum()+1) + " rows ("
- + sheet.getFirstRowNum() + "-" + sheet.getLastRowNum() + ")",
- collapsed.length, sheet.getLastRowNum()-sheet.getFirstRowNum()+1);
+ assertEquals(collapsed.length, sheet.getLastRowNum()-sheet.getFirstRowNum()+1,
+ "Expected " + collapsed.length + " rows with collapsed state, but had " + (sheet.getLastRowNum()-sheet.getFirstRowNum()+1) + " rows ("
+ + sheet.getFirstRowNum() + "-" + sheet.getLastRowNum() + ")");
for(int i = sheet.getFirstRowNum(); i < sheet.getLastRowNum();i++) {
if(collapsed[i-sheet.getFirstRowNum()] == null) {
continue;
}
XSSFRow row = (XSSFRow) sheet.getRow(i);
- assertNotNull("Could not read row " + i, row);
- assertNotNull("Could not read row " + i, row.getCTRow());
- assertEquals("Row: " + i + ": collapsed", collapsed[i - sheet.getFirstRowNum()], row.getCTRow().getCollapsed());
- assertEquals("Row: " + i + ": hidden", hidden[i-sheet.getFirstRowNum()], row.getCTRow().getHidden());
+ assertNotNull(row, "Could not read row " + i);
+ assertNotNull(row.getCTRow(), "Could not read row " + i);
+ assertEquals(collapsed[i - sheet.getFirstRowNum()], row.getCTRow().getCollapsed(), "Row: " + i + ": collapsed");
+ assertEquals(hidden[i-sheet.getFirstRowNum()], row.getCTRow().getHidden(), "Row: " + i + ": hidden");
- assertEquals("Row: " + i + ": level", outlineLevel[i-sheet.getFirstRowNum()], row.getCTRow().getOutlineLevel());
+ assertEquals(outlineLevel[i-sheet.getFirstRowNum()], row.getCTRow().getOutlineLevel(), "Row: " + i + ": level");
}
writeToFile(wb);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java Thu Dec 24 18:42:29 2020
@@ -23,11 +23,11 @@ import org.apache.poi.ss.util.CellUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
@@ -61,34 +61,34 @@ public final class TestXSSFSheetShiftRow
/** negative row shift causes corrupted data or throws exception */
@Test
public void testBug53798() throws IOException {
- // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
+ // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
Sheet testSheet = wb.getSheetAt(0);
- // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
+ // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
// when shifted by less than -1 negative amount (try -2)
testSheet.shiftRows(3, 3, -2);
-
+
// 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
- // xlsx file with unreadable data in the negative shifted row.
+ // xlsx file with unreadable data in the negative shifted row.
// NOTE it's ok to create any other row.
Row newRow = testSheet.createRow(3);
Cell newCell = newRow.createCell(0);
newCell.setCellValue("new Cell in row "+newRow.getRowNum());
-
- // 3) once a negative shift has been made any attempt to shift another group of rows
- // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
+
+ // 3) once a negative shift has been made any attempt to shift another group of rows
+ // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
// org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
- // NOTE: another negative shift on another group of rows is successful, provided no new rows in
+ // NOTE: another negative shift on another group of rows is successful, provided no new rows in
// place of previously shifted rows were attempted to be created as explained above.
// -- CHANGE the shift to positive once the behaviour of the above has been tested
- testSheet.shiftRows(6, 7, 1);
-
+ testSheet.shiftRows(6, 7, 1);
+
Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(read);
-
+
Sheet readSheet = read.getSheetAt(0);
verifyCellContent(readSheet, 0, "0.0");
verifyCellContent(readSheet, 1, "3.0");
@@ -115,7 +115,7 @@ public final class TestXSSFSheetShiftRow
assertEquals(expect, readCell.getStringCellValue());
}
}
-
+
/** negative row shift causes corrupted data or throws exception */
@Test
public void testBug53798a() throws IOException {
@@ -127,11 +127,11 @@ public final class TestXSSFSheetShiftRow
r.getRowNum();
}
testSheet.shiftRows(6, 6, 1);
-
+
Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(read);
-
+
Sheet readSheet = read.getSheetAt(0);
verifyCellContent(readSheet, 0, "0.0");
verifyCellContent(readSheet, 1, "1.0");
@@ -144,7 +144,7 @@ public final class TestXSSFSheetShiftRow
verifyCellContent(readSheet, 8, "8.0");
read.close();
}
-
+
/** Shifting rows with comment result - Unreadable content error and comment deletion */
@Test
public void testBug56017() throws IOException {
@@ -156,19 +156,19 @@ public final class TestXSSFSheetShiftRow
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
-
+
sheet.shiftRows(0, 1, 1);
// comment in row 0 is gone
comment = sheet.getCellComment(new CellAddress(0, 0));
assertNull(comment);
-
+
// comment is now in row 1
comment = sheet.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
-
+
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(wbBack);
@@ -219,14 +219,14 @@ public final class TestXSSFSheetShiftRow
@Test
public void testSetSheetOrderAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
-
+
assertEquals(5, wb.getActiveSheetIndex());
// move the sheets around in all possible combinations to check that the active sheet
// is set correctly in all cases
wb.setSheetOrder(wb.getSheetName(5), 4);
assertEquals(4, wb.getActiveSheetIndex());
-
+
wb.setSheetOrder(wb.getSheetName(5), 5);
assertEquals(4, wb.getActiveSheetIndex());
@@ -262,22 +262,22 @@ public final class TestXSSFSheetShiftRow
wb.setSheetOrder(wb.getSheetName(0), 5);
assertEquals(5, wb.getActiveSheetIndex());
-
+
wb.close();
- }
+ }
@Test
public void testRemoveSheetAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
-
+
assertEquals(5, wb.getActiveSheetIndex());
-
+
wb.removeSheetAt(0);
assertEquals(4, wb.getActiveSheetIndex());
-
+
wb.setActiveSheet(3);
assertEquals(3, wb.getActiveSheetIndex());
-
+
wb.removeSheetAt(4);
assertEquals(3, wb.getActiveSheetIndex());
@@ -292,21 +292,16 @@ public final class TestXSSFSheetShiftRow
wb.removeSheetAt(0);
assertEquals(0, wb.getActiveSheetIndex());
-
- try {
- wb.removeSheetAt(0);
- fail("Should catch exception as no more sheets are there");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> wb.removeSheetAt(0),
+ "Should catch exception as no more sheets are there");
assertEquals(0, wb.getActiveSheetIndex());
-
+
wb.createSheet();
assertEquals(0, wb.getActiveSheetIndex());
-
+
wb.removeSheetAt(0);
assertEquals(0, wb.getActiveSheetIndex());
-
+
wb.close();
}
@@ -341,32 +336,31 @@ public final class TestXSSFSheetShiftRow
/** Shifting rows with cell comments only shifts comments from first such cell. Other cell comments not shifted */
@Test
public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException {
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx");
- XSSFSheet sheet = wb.getSheetAt(0);
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx")) {
+ XSSFSheet sheet = wb.getSheetAt(0);
- Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
- assertNotNull(comment1);
+ Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
+ assertNotNull(comment1);
- Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
- assertNotNull(comment2);
+ Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
+ assertNotNull(comment2);
- Comment comment3 = sheet.getCellComment(new CellAddress(1, 1));
- assertNull("NO comment in (1,1) and it should be null", comment3);
+ Comment comment3 = sheet.getCellComment(new CellAddress(1, 1));
+ assertNull(comment3, "NO comment in (1,1) and it should be null");
- sheet.shiftRows(2, 2, -1);
+ sheet.shiftRows(2, 2, -1);
- comment3 = sheet.getCellComment(new CellAddress(1, 1));
- assertNotNull("Comment in (2,1) moved to (1,1) so its not null now.", comment3);
+ comment3 = sheet.getCellComment(new CellAddress(1, 1));
+ assertNotNull(comment3, "Comment in (2,1) moved to (1,1) so its not null now.");
- comment1 = sheet.getCellComment(new CellAddress(2, 1));
- assertNull("No comment currently in (2,1) and hence it is null", comment1);
+ comment1 = sheet.getCellComment(new CellAddress(2, 1));
+ assertNull(comment1, "No comment currently in (2,1) and hence it is null");
- comment2 = sheet.getCellComment(new CellAddress(1, 2));
- assertNotNull("Comment in (2,2) should have moved as well because of shift rows. But its not", comment2);
-
- wb.close();
+ comment2 = sheet.getCellComment(new CellAddress(1, 2));
+ assertNotNull(comment2, "Comment in (2,2) should have moved as well because of shift rows. But its not");
+ }
}
-
+
@Test
public void bug59733() throws IOException {
Workbook workbook = new XSSFWorkbook();
@@ -377,7 +371,7 @@ public final class TestXSSFSheetShiftRow
// Shift the 2nd row on top of the 0th row
sheet.shiftRows(2, 2, -2);
-
+
sheet.removeRow(sheet.getRow(0));
assertEquals(1, sheet.getRow(1).getRowNum());
@@ -443,7 +437,7 @@ public final class TestXSSFSheetShiftRow
assertEquals("SUM(E2:E4)", getCellFormula(sheet, "E6"));
wb.close();
}
-
+
// bug 60260: shift rows or rename a sheet containing a named range
// that refers to formula with a unicode (non-ASCII) sheet name formula
@Test
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRowsAndColumns.java Thu Dec 24 18:42:29 2020
@@ -17,8 +17,8 @@
package org.apache.poi.xssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -29,9 +29,9 @@ import java.util.Locale;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
-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;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
public class TestXSSFSheetShiftRowsAndColumns {
@@ -52,15 +52,14 @@ public class TestXSSFSheetShiftRowsAndCo
private String fileName = null;
public TestXSSFSheetShiftRowsAndColumns() {
- assertTrue("Failed to create directory " + resultDir,
- resultDir.exists() || resultDir.mkdirs());
+ assertTrue(resultDir.exists() || resultDir.mkdirs(), "Failed to create directory " + resultDir);
}
/**
* This creates a workbook with one worksheet. It then puts data in rows 0 to numRows-1 and colulmns
* 0 to numCols-1.
*/
- @Before
+ @BeforeEach
public void setup() throws IOException {
final String procName = "TestXSSFSheetShiftRowsAndColumns.setup";
fileName = procName+".xlsx";
@@ -88,7 +87,7 @@ public class TestXSSFSheetShiftRowsAndCo
/**
* This method writes the workbook to resultDir/fileName.
*/
- @After
+ @AfterEach
public void cleanup() throws IOException {
final String procName = "TestXSSFSheetRemoveTable.cleanup";
if (workbook == null) {
@@ -184,8 +183,8 @@ public class TestXSSFSheetShiftRowsAndCo
final Object cellAddress = cell.getAddress().formatAsString();
final Object r = ctCell.getR();
- assertEquals(String.format(Locale.US, "%s: Testing cell.getAddress",procName),address,cellAddress);
- assertEquals(String.format(Locale.US, "%s: Testing ctCell.getR",procName),address,r);
+ assertEquals(address,cellAddress,String.format(Locale.US, "%s: Testing cell.getAddress",procName));
+ assertEquals(address,r,String.format(Locale.US, "%s: Testing ctCell.getR",procName));
}
}
@@ -196,9 +195,8 @@ public class TestXSSFSheetShiftRowsAndCo
*/
private void testMergeRegion(String procName,int nRowsToShift,int nColsToShift) {
final CellRangeAddress range = sheet.getMergedRegion(0);
- assertEquals(String.format(Locale.US, "%s: Testing merge area %s", procName, range),
- new CellRangeAddress(FIRST_MERGE_ROW + nRowsToShift, LAST_MERGE_ROW + nRowsToShift,
- FIRST_MERGE_COL + nColsToShift, LAST_MERGE_COL + nColsToShift),
- range);
+ assertEquals(new CellRangeAddress(FIRST_MERGE_ROW + nRowsToShift, LAST_MERGE_ROW + nRowsToShift,
+ FIRST_MERGE_COL + nColsToShift, LAST_MERGE_COL + nColsToShift), range,
+ String.format(Locale.US, "%s: Testing merge area %s", procName, range));
}
}
\ No newline at end of file
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetUpdateArrayFormulas.java Thu Dec 24 18:42:29 2020
@@ -17,11 +17,11 @@
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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.io.IOException;
@@ -29,7 +29,7 @@ import org.apache.poi.ss.usermodel.BaseT
import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
@@ -100,7 +100,7 @@ public final class TestXSSFSheetUpdateAr
confirmArrayFormulaCell(c, cellRef, null, null);
}
private static void confirmArrayFormulaCell(XSSFCell c, String cellRef, String formulaText, String arrayRangeRef) {
- assertNotNull("Cell should not be null.", c);
+ assertNotNull(c, "Cell should not be null.");
CTCell ctCell = c.getCTCell();
assertEquals(cellRef, ctCell.getR());
if (formulaText == null) {
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java Thu Dec 24 18:42:29 2020
@@ -16,11 +16,11 @@
==================================================================== */
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.awt.Color;
import java.io.IOException;
@@ -33,7 +33,7 @@ import org.apache.poi.xddf.usermodel.tex
import org.apache.poi.xddf.usermodel.text.XDDFShapeAutoFit;
import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
import org.apache.poi.xddf.usermodel.text.XDDFTextParagraph;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestXSSFSimpleShape {
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org