aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases/org/apache
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2020-12-25 09:50:50 +0000
committerPJ Fanning <fanningpj@apache.org>2020-12-25 09:50:50 +0000
commit353293f244546ab5f514b4900bade037545d3bb6 (patch)
tree8bea19ba63fbe9cf02236322a4d9f4535409a328 /src/ooxml/testcases/org/apache
parenta2d728cbe6d9547f6327392ce8796d6826a3374e (diff)
downloadpoi-353293f244546ab5f514b4900bade037545d3bb6.tar.gz
poi-353293f244546ab5f514b4900bade037545d3bb6.zip
[bug-65023] add col bugfix. Thanks to Paula Muldoon, This closes #212
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884794 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestColumn.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestColumn.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestColumn.java
new file mode 100644
index 0000000000..9354afd7d0
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestColumn.java
@@ -0,0 +1,82 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xwpf.usermodel;
+
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.junit.jupiter.api.Test;
+import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestColumn {
+ @Test
+ public void testAddNewColWithCorrectAmountOfColumns() throws IOException {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFTable table = doc.createTable(2, 4);
+ table.addNewCol();
+
+ int expectedNumberOfColumns = 5;
+ for (int i = 0; i < table.tableRows.size(); i++) {
+ assertEquals(expectedNumberOfColumns, table.tableRows.get(i).getTableCells().size());
+ }
+ doc.close();
+ }
+
+ @Test
+ public void testAddNewColWithEmptyTable() throws IOException {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFTable table = doc.createTable(0, 0);
+ table.removeRow(0);
+ table.addNewCol();
+
+ int expectedNumberOfColumnsInRow1 = 1;
+ int actualNumberOfColumnsInRow1 = table.tableRows.get(0).getTableCells().size();
+ assertEquals(expectedNumberOfColumnsInRow1, actualNumberOfColumnsInRow1);
+ doc.close();
+ }
+
+ @Test
+ public void testAddNewColWithDocx() throws Exception {
+ try (XWPFDocument doc = XWPFTestDataSamples
+ .openSampleDocument("TestTableColumns.docx")) {
+ XWPFTable table = doc.getTables().get(0);
+ table.addNewCol();
+
+ int expectedNumberOfColumns = 5;
+ for (int i = 0; i < table.tableRows.size(); i++) {
+ assertEquals(expectedNumberOfColumns, table.tableRows.get(i).getTableCells().size());
+ }
+ }
+ }
+
+ @Test
+ public void testAddNewColWhenRowsHaveDifferentNumbersOfColumnsWithDocx() throws Exception {
+ try (XWPFDocument doc = XWPFTestDataSamples
+ .openSampleDocument("TestTableColumns.docx")) {
+ XWPFTable table = doc.getTables().get(1);
+ table.addNewCol();
+
+ int expectedNumberOfColumnsInRow1 = 5;
+ int actualNumberOfColumnsInRow1 = table.tableRows.get(0).getTableCells().size();
+ assertEquals(expectedNumberOfColumnsInRow1, actualNumberOfColumnsInRow1);
+
+ int expectedNumberOfColumnsInRow2 = 4;
+ int actualNumberOfColumnsInRow2 = table.tableRows.get(1).getTableCells().size();
+ assertEquals(expectedNumberOfColumnsInRow2, actualNumberOfColumnsInRow2);
+ }
+ }
+}