// assert the table is empty
List<XWPFTableRow> rows = table.getRows();
assertEquals(noRows, rows.size(), "Table has less rows than requested.");
+ int row = 0;
for (XWPFTableRow xwpfRow : rows) {
assertNotNull(xwpfRow);
+ assertEquals(noCols, xwpfRow.getTableCells().size(),
+ "Row has less columns than requested.");
for (int i = 0; i < 7; i++) {
XWPFTableCell xwpfCell = xwpfRow.getCell(i);
assertNotNull(xwpfCell);
- assertEquals(1, xwpfCell.getParagraphs().size(), "Empty cells should not have one paragraph.");
+ assertEquals(row != 0 || i != 0 ? 0 : 1, xwpfCell.getParagraphs().size(),
+ "Empty cells should not have one paragraph: " + i);
+
xwpfCell = xwpfRow.getCell(i);
- assertEquals(1, xwpfCell.getParagraphs().size(), "Calling 'getCell' must not modify cells content.");
+ assertEquals(row != 0 || i != 0 ? 0 : 1, xwpfCell.getParagraphs().size(),
+ "Calling 'getCell' must not modify cells content: " + i);
}
+
+ row++;
}
doc.getPackage().revert();
}
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
XWPFTableRow tr = table.createRow();
XWPFTableCell cell = tr.addNewTableCell();
- // cell have at least one paragraph by default
+ // now paragraph or body element initially
+ assertEquals(0, cell.getParagraphs().size());
+ assertEquals(0, cell.getBodyElements().size());
+
+ XWPFParagraph p = cell.addParagraph();
assertEquals(1, cell.getParagraphs().size());
assertEquals(1, cell.getBodyElements().size());
+ assertSame(p, cell.getParagraphArray(0));
assertEquals(cell.getParagraphArray(0), cell.getBodyElements().get(0));
- XWPFParagraph p = cell.addParagraph();
- assertEquals(2, cell.getParagraphs().size());
- assertEquals(2, cell.getBodyElements().size());
- assertEquals(p, cell.getParagraphArray(1));
- assertEquals(cell.getParagraphArray(1), cell.getBodyElements().get(1));
-
doc.close();
}
XWPFTableRow tr = table.createRow();
XWPFTableCell cell = tr.addNewTableCell();
- // cell have at least one paragraph by default
- XWPFParagraph p0 = cell.getParagraphArray(0);
+ // cell have no paragraph by default
+ assertNull(cell.getParagraphArray(0));
+
+ XWPFParagraph p0 = cell.addParagraph();
XWPFParagraph p1 = cell.addParagraph();
cell.addParagraph();
XWPFTableRow tr = table.createRow();
XWPFTableCell cell = tr.addNewTableCell();
- // cell have at least one paragraph by default
+ // cell should not have any elements by default
+ assertTrue(cell.getParagraphs().isEmpty());
+
+ XWPFParagraph p = cell.addParagraph();
+ assertNotNull(p);
+
XWPFParagraph p0 = cell.getParagraphArray(0);
XmlCursor newCursor = p0.getCTP().newCursor();
cell.insertNewTbl(newCursor);