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/12 23:15:21 UTC

svn commit: r1884368 [3/3] - in /poi: site/src/documentation/content/xdocs/ trunk/ trunk/src/java/org/apache/poi/util/ trunk/src/multimodule/ooxml-lite/java9/ trunk/src/ooxml/java/org/apache/poi/ooxml/util/ trunk/src/ooxml/java/org/apache/poi/poifs/cry...

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java Sat Dec 12 23:15:20 2020
@@ -26,10 +26,12 @@ import java.util.function.Consumer;
 import java.util.function.Function;
 
 import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJcTable;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
@@ -40,7 +42,7 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJcTable;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
 
 /**
@@ -279,7 +281,7 @@ public class XWPFTable implements IBodyE
      */
     public int getWidth() {
         CTTblPr tblPr = getTblPr();
-        return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
+        return tblPr.isSetTblW() ? (int)Units.toDXA(POIXMLUnits.parseLength(tblPr.getTblW().xgetW())) : -1;
     }
 
     /**
@@ -407,8 +409,8 @@ public class XWPFTable implements IBodyE
      */
     public void setTableAlignment(TableRowAlign tra) {
         CTTblPr tPr = getTblPr(true);
-        CTJc jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
-        jc.setVal(STJc.Enum.forInt(tra.getValue()));
+        CTJcTable jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
+        jc.setVal(STJcTable.Enum.forInt(tra.getValue()));
     }
 
     /**
@@ -985,7 +987,7 @@ public class XWPFTable implements IBodyE
         if (tcm != null) {
             CTTblWidth tw = margin.apply(tcm);
             if (tw != null) {
-                return tw.getW().intValue();
+                return (int) Units.toDXA(POIXMLUnits.parseLength(tw.xgetW()));
             }
         }
         return 0;
@@ -1154,11 +1156,11 @@ public class XWPFTable implements IBodyE
         if (typeValue == STTblWidth.DXA
                 || typeValue == STTblWidth.AUTO
                 || typeValue == STTblWidth.NIL) {
-            result = 0.0 + ctWidth.getW().intValue();
+            result = 0.0 + Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW()));
         } else if (typeValue == STTblWidth.PCT) {
             // Percentage values are stored as integers that are 50 times
             // percentage.
-            result = ctWidth.getW().intValue() / 50.0;
+            result = Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW())) / 50.0;
         } else {
             // Should never get here
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java Sat Dec 12 23:15:20 2020
@@ -23,7 +23,9 @@ import java.util.HashMap;
 import java.util.List;
 
 import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
 import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
@@ -528,8 +530,8 @@ public class XWPFTableCell implements IB
      * @return Width value as a double-precision decimal.
      * @since 4.0.0
      */
-    public double getWidthDecimal() {                
-        return XWPFTable.getWidthDecimal(getTcWidth());    
+    public double getWidthDecimal() {
+        return XWPFTable.getWidthDecimal(getTcWidth());
     }
 
     /**
@@ -541,7 +543,7 @@ public class XWPFTableCell implements IB
      * @since 4.0.0
      */
     public TableWidthType getWidthType() {
-        return XWPFTable.getWidthType(getTcWidth());    
+        return XWPFTable.getWidthType(getTcWidth());
     }
 
     /**
@@ -551,7 +553,7 @@ public class XWPFTableCell implements IB
      * @since 4.0.0
      */
     public void setWidth(String widthValue) {
-        XWPFTable.setWidthValue(widthValue, getTcWidth());    
+        XWPFTable.setWidthValue(widthValue, getTcWidth());
     }
 
     private CTTblWidth getTcWidth() {
@@ -582,6 +584,6 @@ public class XWPFTableCell implements IB
     }
 
     public int getWidth() {
-        return getTcWidth().getW().intValue();
+        return (int) Units.toDXA(POIXMLUnits.parseLength(getTcWidth().xgetW()));
     }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java Sat Dec 12 23:15:20 2020
@@ -20,10 +20,12 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.poi.ooxml.util.POIXMLUnits;
 import org.apache.poi.util.Internal;
-import org.apache.poi.xwpf.model.WMLHelper;
+import org.apache.poi.util.Units;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
@@ -101,7 +103,7 @@ public class XWPFTableRow {
      */
     public int getHeight() {
         CTTrPr properties = getTrPr();
-        return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
+        return properties.sizeOfTrHeightArray() == 0 ? 0 : (int) Units.toDXA(POIXMLUnits.parseLength(properties.getTrHeightArray(0).xgetVal()));
     }
 
     /**
@@ -229,7 +231,7 @@ public class XWPFTableRow {
             CTTrPr trpr = getTrPr();
             if (trpr.sizeOfCantSplitArray() > 0) {
                 CTOnOff onoff = trpr.getCantSplitArray(0);
-                isCant = (onoff.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(onoff.getVal()) : true);
+                isCant = !onoff.isSetVal() || POIXMLUnits.parseOnOff(onoff.xgetVal());
             }
         }
         return isCant;
@@ -246,7 +248,7 @@ public class XWPFTableRow {
     public void setCantSplitRow(boolean split) {
         CTTrPr trpr = getTrPr();
         CTOnOff onoff = (trpr.sizeOfCantSplitArray() > 0 ? trpr.getCantSplitArray(0) : trpr.addNewCantSplit());
-        onoff.setVal(WMLHelper.convertBooleanToSTOnOff(split));
+        onoff.setVal(split ? STOnOff1.ON : STOnOff1.OFF);
     }
 
     /**
@@ -254,7 +256,7 @@ public class XWPFTableRow {
      * table split across pages. NOTE - Word will not repeat a table row unless
      * all preceding rows of the table are also repeated. This function returns
      * false if the row will not be repeated even if the repeat tag is present
-     * for this row. 
+     * for this row.
      *
      * @return true if table's header row should be repeated at the top of each
      * page of table, false otherwise.
@@ -269,14 +271,14 @@ public class XWPFTableRow {
         }
         return repeat;
     }
-    
+
     private boolean getRepeat() {
         boolean repeat = false;
         if (ctRow.isSetTrPr()) {
             CTTrPr trpr = getTrPr();
             if (trpr.sizeOfTblHeaderArray() > 0) {
                 CTOnOff rpt = trpr.getTblHeaderArray(0);
-                repeat = (rpt.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(rpt.getVal()) : true);
+                repeat = !rpt.isSetVal() || POIXMLUnits.parseOnOff(rpt.xgetVal());
             }
         }
         return repeat;
@@ -293,6 +295,6 @@ public class XWPFTableRow {
     public void setRepeatHeader(boolean repeat) {
         CTTrPr trpr = getTrPr();
         CTOnOff onoff = (trpr.sizeOfTblHeaderArray() > 0 ? trpr.getTblHeaderArray(0) : trpr.addNewTblHeader());
-        onoff.setVal(WMLHelper.convertBooleanToSTOnOff(repeat));
+        onoff.setVal(repeat ? STOnOff1.ON : STOnOff1.OFF);
     }
 }

Copied: poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip (from r1884367, poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip?p2=poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip&p1=poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip&r1=1884367&r2=1884368&rev=1884368&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java Sat Dec 12 23:15:20 2020
@@ -21,6 +21,11 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
@@ -47,10 +52,6 @@ import org.junit.Test;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
 public final class TestContentTypeManager {
 
     /**
@@ -176,10 +177,10 @@ public final class TestContentTypeManage
                         anchor = (XSSFClientAnchor) helper.createClientAnchor();
                         CTMarker markerFrom = oldAnchor.getFrom();
                         CTMarker markerTo = oldAnchor.getTo();
-                        anchor.setDx1((int) markerFrom.getColOff());
-                        anchor.setDx2((int) markerTo.getColOff());
-                        anchor.setDy1((int) markerFrom.getRowOff());
-                        anchor.setDy2((int) markerTo.getRowOff());
+                        anchor.setDx1((int) POIXMLUnits.parseLength(markerFrom.xgetColOff()));
+                        anchor.setDx2((int) POIXMLUnits.parseLength(markerTo.xgetColOff()));
+                        anchor.setDy1((int) POIXMLUnits.parseLength(markerFrom.xgetRowOff()));
+                        anchor.setDy2((int) POIXMLUnits.parseLength(markerTo.xgetRowOff()));
                         anchor.setCol1(markerFrom.getCol());
                         anchor.setCol2(markerTo.getCol());
                         anchor.setRow1(markerFrom.getRow());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java Sat Dec 12 23:15:20 2020
@@ -124,5 +124,8 @@ public class TestXDDFColor {
         built = (XDDFColorRgbPercent) XDDFColor.from(654321, 654321, 654321);
         assertEquals(expected, built.getXmlObject().toString());
         assertEquals("FFFFFF", built.toRGBHex());
+
+        built = (XDDFColorRgbPercent) XDDFColor.from(75000, 50000, 25000);
+        assertEquals("BF7F3F", built.toRGBHex());
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java Sat Dec 12 23:15:20 2020
@@ -17,6 +17,8 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 
 import org.apache.poi.common.usermodel.fonts.FontCharset;
@@ -33,9 +35,11 @@ import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
@@ -44,9 +48,6 @@ import org.openxmlformats.schemas.spread
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
-
-import static org.junit.Assert.*;
 
 public final class TestXSSFFont extends BaseTestFont{
 
@@ -330,7 +331,7 @@ public final class TestXSSFFont extends
 	@Test
 	public void testFamily() {
 		CTFont ctFont=CTFont.Factory.newInstance();
-		CTIntProperty family=ctFont.addNewFamily();
+		CTFontFamily family=ctFont.addNewFamily();
 		family.setVal(FontFamily.MODERN.getValue());
 		ctFont.setFamilyArray(0,family);
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java Sat Dec 12 23:15:20 2020
@@ -34,10 +34,10 @@ import org.apache.poi.ss.usermodel.Sheet
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.StylesTable;
 import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
 
 /**
  * Tests functionality of the XSSFRichTextRun object

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java Sat Dec 12 23:15:20 2020
@@ -35,7 +35,6 @@ import java.util.regex.Pattern;
 
 import com.microsoft.schemas.office.excel.CTClientData;
 import com.microsoft.schemas.office.excel.STObjectType;
-import com.microsoft.schemas.office.excel.STTrueFalseBlank;
 import com.microsoft.schemas.office.office.CTShapeLayout;
 import com.microsoft.schemas.office.office.STConnectType;
 import com.microsoft.schemas.office.office.STInsetMode;
@@ -43,12 +42,13 @@ import com.microsoft.schemas.vml.CTShado
 import com.microsoft.schemas.vml.CTShape;
 import com.microsoft.schemas.vml.CTShapetype;
 import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
 import org.apache.poi.POIDataSamples;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
 import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank;
 
 public class TestXSSFVMLDrawing {
 

Copied: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java (from r1884337, poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java?p2=poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java&p1=poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java&r1=1884337&r2=1884368&rev=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java Sat Dec 12 23:15:20 2020
@@ -18,18 +18,23 @@ package org.apache.poi.xssf.usermodel.ch
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
 
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.SheetBuilder;
 import org.apache.poi.xddf.usermodel.chart.AxisPosition;
 import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.XDDFArea3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFBar3DChartData;
 import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
 import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
 import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
 import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFLine3DChartData;
 import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
 import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
 import org.apache.poi.xssf.usermodel.XSSFChart;
@@ -40,9 +45,9 @@ import org.apache.poi.xssf.usermodel.XSS
 import org.junit.Test;
 
 /**
- * Tests for XSSF Line Charts
+ * Tests for XSSF Area3d Charts
  */
-public class TestXSSFLineChartData {
+public class TestXSSF3DChartData {
 
     private static final Object[][] plotData = {
             {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"},
@@ -50,27 +55,58 @@ public class TestXSSFLineChartData {
     };
 
     @Test
-    public void testOneSeriePlot() throws IOException {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
-        XSSFDrawing drawing = sheet.createDrawingPatriarch();
-        XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
-        XSSFChart chart = drawing.createChart(anchor);
-
-        XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
-        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
-
-        XDDFDataSource<String> xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
-        XDDFNumericalDataSource<Double> ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
-
-        XDDFChartData lineChartData = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
-        XDDFChartData.Series series = lineChartData.addSeries(xs, ys);
-
-        assertNotNull(series);
-        assertEquals(1, lineChartData.getSeries().size());
-        assertTrue(lineChartData.getSeries().contains(series));
+    public void testArea3D() throws IOException {
+        // This test currently doesn't produce a valid area 3d chart and is only used to test accessors
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
+            XSSFDrawing drawing = sheet.createDrawingPatriarch();
+            XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+
+            Map<ChartTypes, Consumer<XDDFChartData>> map = new HashMap<>();
+            map.put(ChartTypes.AREA3D, this::handleArea3D);
+            map.put(ChartTypes.BAR3D, this::handleBar3D);
+            map.put(ChartTypes.LINE3D, this::handleLine3D);
+
+            for (Map.Entry<ChartTypes, Consumer<XDDFChartData>> me : map.entrySet()) {
+
+                XSSFChart chart = drawing.createChart(anchor);
+
+                XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+                XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+
+                XDDFDataSource<String> xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
+                XDDFNumericalDataSource<Double> ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
+
+                XDDFChartData data = chart.createData(me.getKey(), bottomAxis, leftAxis);
+                XDDFChartData.Series series = data.addSeries(xs, ys);
+
+                assertNotNull(series);
+                assertEquals(1, data.getSeriesCount());
+                assertEquals(series, data.getSeries(0));
+                chart.plot(data);
+
+                me.getValue().accept(data);
+            }
+        }
+    }
+
+    private void handleArea3D(XDDFChartData data) {
+        XDDFArea3DChartData xArea3d = (XDDFArea3DChartData)data;
+        xArea3d.setGapDepth(10);
+        assertEquals(10, (int)xArea3d.getGapDepth());
+    }
+
+    private void handleBar3D(XDDFChartData data) {
+        XDDFBar3DChartData xBar3d = (XDDFBar3DChartData) data;
+        xBar3d.setGapDepth(10);
+        assertEquals(10, (int)xBar3d.getGapDepth());
+        xBar3d.setGapWidth(10);
+        assertEquals(10, (int)xBar3d.getGapWidth());
+    }
 
-        chart.plot(lineChartData);
-        wb.close();
+    private void handleLine3D(XDDFChartData data) {
+        XDDFLine3DChartData xLine3d = (XDDFLine3DChartData) data;
+        xLine3d.setGapDepth(10);
+        assertEquals(10, (int)xLine3d.getGapDepth());
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java Sat Dec 12 23:15:20 2020
@@ -32,6 +32,7 @@ import org.junit.Test;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
 import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
 import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
@@ -46,7 +47,6 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
 
 /**
@@ -163,9 +163,9 @@ public final class TestXWPFParagraph {
             assertEquals(10, p.getSpacingBefore());
 
             p.setSpacingAfter(100);
-            assertEquals(100, spacing.getAfter().intValue());
+            assertEquals("100", spacing.xgetAfter().getStringValue());
             p.setSpacingBefore(100);
-            assertEquals(100, spacing.getBefore().intValue());
+            assertEquals("100", spacing.xgetBefore().getStringValue());
 
             p.setSpacingBetween(.25, LineSpacingRule.EXACT);
             assertEquals(.25, p.getSpacingBetween(), 0.01);
@@ -197,7 +197,7 @@ public final class TestXWPFParagraph {
             assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
 
             p.setSpacingAfter(100);
-            assertEquals(100, spacing.getAfter().intValue());
+            assertEquals("100", spacing.xgetAfter().getStringValue());
         }
     }
 
@@ -234,7 +234,7 @@ public final class TestXWPFParagraph {
             assertEquals(10, p.getIndentationLeft());
 
             p.setIndentationLeft(100);
-            assertEquals(100, ind.getLeft().intValue());
+            assertEquals("100", ind.xgetLeft().getStringValue());
         }
     }
     @Test
@@ -264,11 +264,11 @@ public final class TestXWPFParagraph {
             CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
             CTOnOff wordWrap = ppr.addNewWordWrap();
-            wordWrap.setVal(STOnOff.FALSE);
+            wordWrap.setVal(STOnOff1.OFF);
             assertFalse(p.isWordWrap());
 
             p.setWordWrapped(true);
-            assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
+            assertEquals("on", ppr.getWordWrap().getVal());
         }
     }
 
@@ -281,11 +281,11 @@ public final class TestXWPFParagraph {
             CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
             CTOnOff pageBreak = ppr.addNewPageBreakBefore();
-            pageBreak.setVal(STOnOff.FALSE);
+            pageBreak.setVal(STOnOff1.OFF);
             assertFalse(p.isPageBreak());
 
             p.setPageBreak(true);
-            assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
+            assertEquals("on", ppr.getPageBreakBefore().getVal());
         }
     }
 
@@ -713,7 +713,7 @@ public final class TestXWPFParagraph {
             assertTrue(p.removeRun(0));
         }
     }
-    
+
     @Test
     public void testFieldRuns() throws IOException {
         try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx")) {
@@ -777,7 +777,7 @@ public final class TestXWPFParagraph {
 
     /**
      * Tests for numbered lists
-     * 
+     *
      * See also https://github.com/jimklo/apache-poi-sample/blob/master/src/main/java/com/sri/jklo/StyledDocument.java
      * for someone else trying a similar thing
      */

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Sat Dec 12 23:15:20 2020
@@ -16,6 +16,19 @@
 ==================================================================== */
 package org.apache.poi.xwpf.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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.Units;
@@ -28,16 +41,19 @@ import org.junit.Test;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STEm;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
 
 /**
  * Tests for XWPF Run
@@ -88,34 +104,34 @@ public class TestXWPFRun {
     @Test
     public void testCTOnOff() {
         CTRPr rpr = ctRun.addNewRPr();
-        CTOnOff bold = rpr.addNewB();        
+        CTOnOff bold = rpr.addNewB();
         XWPFRun run = new XWPFRun(ctRun, irb);
 
         // True values: "true", "1", "on"
-        bold.setVal(STOnOff.TRUE);
+        bold.setVal(STOnOff1.ON);
         assertTrue(run.isBold());
 
-        bold.setVal(STOnOff.X_1);
+        bold.setVal(STOnOff1.ON);
         assertTrue(run.isBold());
 
-        bold.setVal(STOnOff.ON);
+        bold.setVal(STOnOff1.ON);
         assertTrue(run.isBold());
 
         // False values: "false", "0", "off"
-        bold.setVal(STOnOff.FALSE);
+        bold.setVal(STOnOff1.OFF);
         assertFalse(run.isBold());
 
-        bold.setVal(STOnOff.X_0);
+        bold.setVal(STOnOff1.OFF);
         assertFalse(run.isBold());
 
-        bold.setVal(STOnOff.OFF);
+        bold.setVal(STOnOff1.OFF);
         assertFalse(run.isBold());
     }
 
     @Test
     public void testSetGetBold() {
         CTRPr rpr = ctRun.addNewRPr();
-        rpr.addNewB().setVal(STOnOff.TRUE);
+        rpr.addNewB().setVal(STOnOff1.ON);
 
         XWPFRun run = new XWPFRun(ctRun, irb);
         assertTrue(run.isBold());
@@ -123,31 +139,31 @@ public class TestXWPFRun {
         run.setBold(false);
         // Implementation detail: POI natively prefers <w:b w:val="false"/>,
         // but should correctly read val="0" and val="off"
-        assertEquals(STOnOff.FALSE, rpr.getB().getVal());
+        assertEquals("off", rpr.getB().getVal());
     }
 
     @Test
     public void testSetGetItalic() {
         CTRPr rpr = ctRun.addNewRPr();
-        rpr.addNewI().setVal(STOnOff.TRUE);
+        rpr.addNewI().setVal(STOnOff1.ON);
 
         XWPFRun run = new XWPFRun(ctRun, irb);
         assertTrue(run.isItalic());
 
         run.setItalic(false);
-        assertEquals(STOnOff.FALSE, rpr.getI().getVal());
+        assertEquals("off", rpr.getI().getVal());
     }
 
     @Test
     public void testSetGetStrike() {
         CTRPr rpr = ctRun.addNewRPr();
-        rpr.addNewStrike().setVal(STOnOff.TRUE);
+        rpr.addNewStrike().setVal(STOnOff1.ON);
 
         XWPFRun run = new XWPFRun(ctRun, irb);
         assertTrue(run.isStrikeThrough());
 
         run.setStrikeThrough(false);
-        assertEquals(STOnOff.FALSE, rpr.getStrike().getVal());
+        assertEquals("off", rpr.getStrike().getVal());
     }
 
     @Test
@@ -186,10 +202,10 @@ public class TestXWPFRun {
         assertEquals(7.0, run.getFontSizeAsDouble(), 0.01);
 
         run.setFontSize(24);
-        assertEquals(48, rpr.getSz().getVal().longValue());
+        assertEquals("48", rpr.getSz().getVal().toString());
 
         run.setFontSize(24.5f);
-        assertEquals(49, rpr.getSz().getVal().longValue());
+        assertEquals("49", rpr.getSz().getVal().toString());
         assertEquals(25, run.getFontSize());
         assertEquals(24.5, run.getFontSizeAsDouble(), 0.01);
     }
@@ -203,7 +219,7 @@ public class TestXWPFRun {
         assertEquals(4000, run.getTextPosition());
 
         run.setTextPosition(2400);
-        assertEquals(2400, rpr.getPosition().getVal().longValue());
+        assertEquals("2400", rpr.getPosition().getVal().toString());
     }
 
     @Test
@@ -408,7 +424,7 @@ public class TestXWPFRun {
         assertFalse(run.isItalic());
         assertFalse(run.isStrikeThrough());
         assertNull(run.getCTR().getRPr());
-        
+
         doc.close();
     }
 
@@ -481,17 +497,17 @@ public class TestXWPFRun {
 
         assertEquals(1, doc.getAllPictures().size());
         assertEquals(1, r.getEmbeddedPictures().size());
-        
+
         XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
         XWPFParagraph pBack = docBack.getParagraphArray(2);
         XWPFRun rBack = pBack.getRuns().get(0);
-        
+
         assertEquals(1, docBack.getAllPictures().size());
         assertEquals(1, rBack.getEmbeddedPictures().size());
         docBack.close();
         doc.close();
     }
-    
+
     /**
      * Bugzilla #58237 - Unable to add image to word document header
      */
@@ -501,7 +517,7 @@ public class TestXWPFRun {
         XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
         XWPFParagraph p = hdr.createParagraph();
         XWPFRun r = p.createRun();
-        
+
         assertEquals(0, hdr.getAllPictures().size());
         assertEquals(0, r.getEmbeddedPictures().size());
 
@@ -509,23 +525,23 @@ public class TestXWPFRun {
 
         assertEquals(1, hdr.getAllPictures().size());
         assertEquals(1, r.getEmbeddedPictures().size());
-        
+
         XWPFPicture pic = r.getEmbeddedPictures().get(0);
         CTPicture ctPic = pic.getCTPicture();
         CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
 
         assertNotNull(ctBlipFill);
-        
+
         CTBlip ctBlip = ctBlipFill.getBlip();
-        
+
         assertNotNull(ctBlip);
         assertEquals("rId1", ctBlip.getEmbed());
-        
+
         XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
         XWPFHeader hdrBack = docBack.getHeaderArray(0);
         XWPFParagraph pBack = hdrBack.getParagraphArray(0);
         XWPFRun rBack = pBack.getRuns().get(0);
-        
+
         assertEquals(1, hdrBack.getAllPictures().size());
         assertEquals(1, rBack.getEmbeddedPictures().size());
         docBack.close();
@@ -633,7 +649,7 @@ public class TestXWPFRun {
 
         run.setTextPosition(-1);
         assertEquals(-1, run.getTextPosition());
-        
+
         document.close();
     }
 
@@ -658,7 +674,7 @@ public class TestXWPFRun {
         run.setImprinted(true);
         run.setItalic(true);
     }
-    
+
     @Test
     public void testSetGetTextScale() throws IOException {
         XWPFDocument document = new XWPFDocument();
@@ -668,7 +684,7 @@ public class TestXWPFRun {
         assertEquals(200, run.getTextScale());
         document.close();
     }
-    
+
     @Test
     public void testSetGetTextHighlightColor() throws IOException {
         XWPFDocument document = new XWPFDocument();
@@ -680,7 +696,7 @@ public class TestXWPFRun {
         assertTrue(run.isHighlighted());
         run.setTextHighlightColor("none");
         assertFalse(run.isHighlighted());
-        
+
         document.close();
     }
 
@@ -695,7 +711,7 @@ public class TestXWPFRun {
         assertFalse(run.isVanish());
         document.close();
     }
-    
+
     @Test
     public void testSetGetVerticalAlignment() throws IOException {
         XWPFDocument document = new XWPFDocument();
@@ -732,7 +748,7 @@ public class TestXWPFRun {
         assertEquals(STEm.DOT, run.getEmphasisMark());
         document.close();
     }
-    
+
     @Test
     public void testSetGetUnderlineColor() throws IOException {
         XWPFDocument document = new XWPFDocument();
@@ -747,7 +763,7 @@ public class TestXWPFRun {
         assertEquals("auto", run.getUnderlineColor());
         document.close();
     }
-    
+
     @Test
     public void testSetGetUnderlineThemeColor() throws IOException {
         XWPFDocument document = new XWPFDocument();
@@ -762,13 +778,13 @@ public class TestXWPFRun {
         assertEquals(STThemeColor.NONE, run.getUnderlineThemeColor());
         document.close();
     }
-    
+
 
     @Test
     public void testSetStyleId() throws IOException {
         XWPFDocument document = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
         final XWPFRun run = document.createParagraph().createRun();
-        
+
         String styleId = "bolditalic";
         run.setStyle(styleId);
         String candStyleId = run.getCTR().getRPr().getRStyle().getVal();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java?rev=1884368&r1=1884367&r2=1884368&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java Sat Dec 12 23:15:20 2020
@@ -19,7 +19,6 @@ package org.apache.poi.xwpf.usermodel;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.math.BigInteger;
@@ -35,6 +34,7 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblCellMar;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
@@ -46,218 +46,190 @@ import org.openxmlformats.schemas.wordpr
 public class TestXWPFTable {
 
     @Test
-    public void testConstructor() {
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable xtab = new XWPFTable(ctTable, doc);
-        assertNotNull(xtab);
-        assertEquals(1, ctTable.sizeOfTrArray());
-        assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
-        assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-
-        ctTable = CTTbl.Factory.newInstance();
-        xtab = new XWPFTable(ctTable, doc, 3, 2);
-        assertNotNull(xtab);
-        assertEquals(3, ctTable.sizeOfTrArray());
-        assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
-        assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testTblGrid() {
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        CTTblGrid cttblgrid = ctTable.addNewTblGrid();
-        cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
-        cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
-
-        XWPFTable xtab = new XWPFTable(ctTable, doc);
-        assertEquals(123, xtab.getCTTbl().getTblGrid().getGridColArray(0).getW().intValue());
-        assertEquals(321, xtab.getCTTbl().getTblGrid().getGridColArray(1).getW().intValue());
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testGetText() {
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl table = CTTbl.Factory.newInstance();
-        CTRow row = table.addNewTr();
-        CTTc cell = row.addNewTc();
-        CTP paragraph = cell.addNewP();
-        CTR run = paragraph.addNewR();
-        CTText text = run.addNewT();
-        text.setStringValue("finally I can write!");
-
-        XWPFTable xtab = new XWPFTable(table, doc);
-        assertEquals("finally I can write!\n", xtab.getText());
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testCreateRow() {
-        XWPFDocument doc = new XWPFDocument();
-
-        CTTbl table = CTTbl.Factory.newInstance();
-        CTRow r1 = table.addNewTr();
-        r1.addNewTc().addNewP();
-        r1.addNewTc().addNewP();
-        CTRow r2 = table.addNewTr();
-        r2.addNewTc().addNewP();
-        r2.addNewTc().addNewP();
-        CTRow r3 = table.addNewTr();
-        r3.addNewTc().addNewP();
-        r3.addNewTc().addNewP();
-
-        XWPFTable xtab = new XWPFTable(table, doc);
-        assertEquals(3, xtab.getNumberOfRows());
-        assertNotNull(xtab.getRow(2));
-
-        //add a new row
-        xtab.createRow();
-        assertEquals(4, xtab.getNumberOfRows());
-
-        //check number of cols
-        assertEquals(2, table.getTrArray(0).sizeOfTcArray());
-
-        //check creation of first row
-        xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
-        assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testSetGetWidth() {
-        XWPFDocument doc = new XWPFDocument();
-
-        XWPFTable xtab = doc.createTable();
-
-        assertEquals(0, xtab.getWidth());
-        assertEquals(TableWidthType.AUTO, xtab.getWidthType());
-        
-        xtab.setWidth(1000);
-        assertEquals(TableWidthType.DXA, xtab.getWidthType());
-        assertEquals(1000, xtab.getWidth());
-        
-        xtab.setWidth("auto");
-        assertEquals(TableWidthType.AUTO, xtab.getWidthType());
-        assertEquals(0, xtab.getWidth());
-        assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
-        
-        xtab.setWidth("999");
-        assertEquals(TableWidthType.DXA, xtab.getWidthType());                
-        assertEquals(999, xtab.getWidth());
-        
-        xtab.setWidth("50.5%");
-        assertEquals(TableWidthType.PCT, xtab.getWidthType());        
-        assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
-        
-        // Test effect of setting width type to a new value
-        
-        // From PCT to NIL:
-        xtab.setWidthType(TableWidthType.NIL);
-        assertEquals(TableWidthType.NIL, xtab.getWidthType());   
-        assertEquals(0, xtab.getWidth());
-
-        xtab.setWidth("999"); // Sets type to DXA 
-        assertEquals(TableWidthType.DXA, xtab.getWidthType());
-        
-        // From DXA to AUTO:
-        xtab.setWidthType(TableWidthType.AUTO);
-        assertEquals(TableWidthType.AUTO, xtab.getWidthType());   
-        assertEquals(0, xtab.getWidth());
-        
-        xtab.setWidthType(TableWidthType.PCT);
-        assertEquals(TableWidthType.PCT, xtab.getWidthType());   
-        
-        // From PCT to DXA:
-        xtab.setWidth("33.3%");
-        xtab.setWidthType(TableWidthType.DXA);
-        assertEquals(TableWidthType.DXA, xtab.getWidthType());   
-        assertEquals(0, xtab.getWidth());
-
-        // From DXA to DXA: (value should be unchanged)
-        xtab.setWidth("999");
-        xtab.setWidthType(TableWidthType.DXA);
-        assertEquals(TableWidthType.DXA, xtab.getWidthType());   
-        assertEquals(999, xtab.getWidth());
-
-        // From DXA to PCT:
-        xtab.setWidthType(TableWidthType.PCT);
-        assertEquals(TableWidthType.PCT, xtab.getWidthType());   
-        assertEquals(100.0, xtab.getWidthDecimal(), 0.0);        
-
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testSetGetHeight() {
-        XWPFDocument doc = new XWPFDocument();
-
-        CTTbl table = CTTbl.Factory.newInstance();
-
-        XWPFTable xtab = new XWPFTable(table, doc);
-        XWPFTableRow row = xtab.createRow();
-        row.setHeight(20);
-        assertEquals(20, row.getHeight());
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+    public void testConstructor() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable xtab = new XWPFTable(ctTable, doc);
+            assertNotNull(xtab);
+            assertEquals(1, ctTable.sizeOfTrArray());
+            assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
+            assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+
+            ctTable = CTTbl.Factory.newInstance();
+            xtab = new XWPFTable(ctTable, doc, 3, 2);
+            assertNotNull(xtab);
+            assertEquals(3, ctTable.sizeOfTrArray());
+            assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
+            assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+        }
+    }
+
+    @Test
+    public void testTblGrid() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            CTTblGrid cttblgrid = ctTable.addNewTblGrid();
+            cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
+            cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
+
+            XWPFTable xtab = new XWPFTable(ctTable, doc);
+            CTTblGridCol[] ca = xtab.getCTTbl().getTblGrid().getGridColArray();
+            assertEquals("123", ca[0].getW().toString());
+            assertEquals("321", ca[1].getW().toString());
+        }
+    }
+
+    @Test
+    public void testGetText() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl table = CTTbl.Factory.newInstance();
+            CTRow row = table.addNewTr();
+            CTTc cell = row.addNewTc();
+            CTP paragraph = cell.addNewP();
+            CTR run = paragraph.addNewR();
+            CTText text = run.addNewT();
+            text.setStringValue("finally I can write!");
+
+            XWPFTable xtab = new XWPFTable(table, doc);
+            assertEquals("finally I can write!\n", xtab.getText());
+        }
+    }
+
+    @Test
+    public void testCreateRow() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+
+            CTTbl table = CTTbl.Factory.newInstance();
+            CTRow r1 = table.addNewTr();
+            r1.addNewTc().addNewP();
+            r1.addNewTc().addNewP();
+            CTRow r2 = table.addNewTr();
+            r2.addNewTc().addNewP();
+            r2.addNewTc().addNewP();
+            CTRow r3 = table.addNewTr();
+            r3.addNewTc().addNewP();
+            r3.addNewTc().addNewP();
+
+            XWPFTable xtab = new XWPFTable(table, doc);
+            assertEquals(3, xtab.getNumberOfRows());
+            assertNotNull(xtab.getRow(2));
+
+            //add a new row
+            xtab.createRow();
+            assertEquals(4, xtab.getNumberOfRows());
+
+            //check number of cols
+            assertEquals(2, table.getTrArray(0).sizeOfTcArray());
+
+            //check creation of first row
+            xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
+            assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
         }
     }
 
     @Test
-    public void testSetGetMargins() {
+    public void testSetGetWidth() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+
+            XWPFTable xtab = doc.createTable();
+
+            assertEquals(0, xtab.getWidth());
+            assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+
+            xtab.setWidth(1000);
+            assertEquals(TableWidthType.DXA, xtab.getWidthType());
+            assertEquals(1000, xtab.getWidth());
+
+            xtab.setWidth("auto");
+            assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+            assertEquals(0, xtab.getWidth());
+            assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
+
+            xtab.setWidth("999");
+            assertEquals(TableWidthType.DXA, xtab.getWidthType());
+            assertEquals(999, xtab.getWidth());
+
+            xtab.setWidth("50.5%");
+            assertEquals(TableWidthType.PCT, xtab.getWidthType());
+            assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
+
+            // Test effect of setting width type to a new value
+
+            // From PCT to NIL:
+            xtab.setWidthType(TableWidthType.NIL);
+            assertEquals(TableWidthType.NIL, xtab.getWidthType());
+            assertEquals(0, xtab.getWidth());
+
+            xtab.setWidth("999"); // Sets type to DXA
+            assertEquals(TableWidthType.DXA, xtab.getWidthType());
+
+            // From DXA to AUTO:
+            xtab.setWidthType(TableWidthType.AUTO);
+            assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+            assertEquals(0, xtab.getWidth());
+
+            xtab.setWidthType(TableWidthType.PCT);
+            assertEquals(TableWidthType.PCT, xtab.getWidthType());
+
+            // From PCT to DXA:
+            xtab.setWidth("33.3%");
+            xtab.setWidthType(TableWidthType.DXA);
+            assertEquals(TableWidthType.DXA, xtab.getWidthType());
+            assertEquals(0, xtab.getWidth());
+
+            // From DXA to DXA: (value should be unchanged)
+            xtab.setWidth("999");
+            xtab.setWidthType(TableWidthType.DXA);
+            assertEquals(TableWidthType.DXA, xtab.getWidthType());
+            assertEquals(999, xtab.getWidth());
+
+            // From DXA to PCT:
+            xtab.setWidthType(TableWidthType.PCT);
+            assertEquals(TableWidthType.PCT, xtab.getWidthType());
+            assertEquals(100.0, xtab.getWidthDecimal(), 0.0);
+        }
+    }
+
+    @Test
+    public void testSetGetHeight() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+
+            CTTbl table = CTTbl.Factory.newInstance();
+
+            XWPFTable xtab = new XWPFTable(table, doc);
+            XWPFTableRow row = xtab.createRow();
+            row.setHeight(20);
+            assertEquals(20, row.getHeight());
+        }
+    }
+
+    @Test
+    public void testSetGetMargins() throws IOException {
         // instantiate the following class so it'll get picked up by
         // the XmlBean process and added to the jar file. it's required
         // for the following XWPFTable methods.
         CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
         assertNotNull(ctm);
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // set margins
-        table.setCellMargins(50, 50, 250, 450);
-        // get margin components
-        int t = table.getCellMarginTop();
-        assertEquals(50, t);
-        int l = table.getCellMarginLeft();
-        assertEquals(50, l);
-        int b = table.getCellMarginBottom();
-        assertEquals(250, b);
-        int r = table.getCellMarginRight();
-        assertEquals(450, r);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // set margins
+            table.setCellMargins(50, 50, 250, 450);
+            // get margin components
+            int t = table.getCellMarginTop();
+            assertEquals(50, t);
+            int l = table.getCellMarginLeft();
+            assertEquals(50, l);
+            int b = table.getCellMarginBottom();
+            assertEquals(250, b);
+            int r = table.getCellMarginRight();
+            assertEquals(450, r);
         }
     }
 
     @Test
-    public void testSetGetHBorders() {
+    public void testSetGetHBorders() throws IOException {
         // instantiate the following classes so they'll get picked up by
         // the XmlBean process and added to the jar file. they are required
         // for the following XWPFTable methods.
@@ -266,388 +238,348 @@ public class TestXWPFTable {
         STBorder stb = STBorder.Factory.newInstance();
         assertNotNull(stb);
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getInsideHBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getInsideHBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getInsideHBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getInsideHBorderColor();
-        assertNull(clr);
-        // set inside horizontal border
-        table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
-        // get inside horizontal border components
-        bt = table.getInsideHBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        sz = table.getInsideHBorderSize();
-        assertEquals(4, sz);
-        sp = table.getInsideHBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getInsideHBorderColor();
-        assertEquals("FF0000", clr);
-        // remove the border and verify state
-        table.removeInsideHBorder();
-        bt = table.getInsideHBorderType();
-        assertNull(bt);
-        sz = table.getInsideHBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getInsideHBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getInsideHBorderColor();
-        assertNull(clr);
-        // check other borders
-        bt = table.getInsideVBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getTopBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getBottomBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getLeftBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getRightBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        // remove the rest all at once and test
-        table.removeBorders();
-        bt = table.getInsideVBorderType();
-        assertNull(bt);
-        bt = table.getTopBorderType();
-        assertNull(bt);
-        bt = table.getBottomBorderType();
-        assertNull(bt);
-        bt = table.getLeftBorderType();
-        assertNull(bt);
-        bt = table.getRightBorderType();
-        assertNull(bt);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getInsideHBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getInsideHBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getInsideHBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getInsideHBorderColor();
+            assertNull(clr);
+            // set inside horizontal border
+            table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
+            // get inside horizontal border components
+            bt = table.getInsideHBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            sz = table.getInsideHBorderSize();
+            assertEquals(4, sz);
+            sp = table.getInsideHBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getInsideHBorderColor();
+            assertEquals("FF0000", clr);
+            // remove the border and verify state
+            table.removeInsideHBorder();
+            bt = table.getInsideHBorderType();
+            assertNull(bt);
+            sz = table.getInsideHBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getInsideHBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getInsideHBorderColor();
+            assertNull(clr);
+            // check other borders
+            bt = table.getInsideVBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getTopBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getBottomBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getLeftBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getRightBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            // remove the rest all at once and test
+            table.removeBorders();
+            bt = table.getInsideVBorderType();
+            assertNull(bt);
+            bt = table.getTopBorderType();
+            assertNull(bt);
+            bt = table.getBottomBorderType();
+            assertNull(bt);
+            bt = table.getLeftBorderType();
+            assertNull(bt);
+            bt = table.getRightBorderType();
+            assertNull(bt);
         }
     }
 
     @Test
-    public void testSetGetVBorders() {
+    public void testSetGetVBorders() throws IOException {
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getInsideVBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getInsideVBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getInsideVBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getInsideVBorderColor();
-        assertNull(clr);
-        // set inside vertical border
-        table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
-        // get inside vertical border components
-        bt = table.getInsideVBorderType();
-        assertEquals(XWPFBorderType.DOUBLE, bt);
-        sz = table.getInsideVBorderSize();
-        assertEquals(4, sz);
-        sp = table.getInsideVBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getInsideVBorderColor();
-        assertEquals("00FF00", clr);
-        // remove the border and verify state
-        table.removeInsideVBorder();
-        bt = table.getInsideVBorderType();
-        assertNull(bt);
-        sz = table.getInsideVBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getInsideVBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getInsideVBorderColor();
-        assertNull(clr);
-        // check the rest
-        bt = table.getInsideHBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getTopBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getBottomBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getLeftBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        bt = table.getRightBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        // remove the rest one at a time and test
-        table.removeInsideHBorder();
-        table.removeTopBorder();
-        table.removeBottomBorder();
-        table.removeLeftBorder();
-        table.removeRightBorder();
-        bt = table.getInsideHBorderType();
-        assertNull(bt);
-        bt = table.getTopBorderType();
-        assertNull(bt);
-        bt = table.getBottomBorderType();
-        assertNull(bt);
-        bt = table.getLeftBorderType();
-        assertNull(bt);
-        bt = table.getRightBorderType();
-        assertNull(bt);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getInsideVBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getInsideVBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getInsideVBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getInsideVBorderColor();
+            assertNull(clr);
+            // set inside vertical border
+            table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
+            // get inside vertical border components
+            bt = table.getInsideVBorderType();
+            assertEquals(XWPFBorderType.DOUBLE, bt);
+            sz = table.getInsideVBorderSize();
+            assertEquals(4, sz);
+            sp = table.getInsideVBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getInsideVBorderColor();
+            assertEquals("00FF00", clr);
+            // remove the border and verify state
+            table.removeInsideVBorder();
+            bt = table.getInsideVBorderType();
+            assertNull(bt);
+            sz = table.getInsideVBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getInsideVBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getInsideVBorderColor();
+            assertNull(clr);
+            // check the rest
+            bt = table.getInsideHBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getTopBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getBottomBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getLeftBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            bt = table.getRightBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            // remove the rest one at a time and test
+            table.removeInsideHBorder();
+            table.removeTopBorder();
+            table.removeBottomBorder();
+            table.removeLeftBorder();
+            table.removeRightBorder();
+            bt = table.getInsideHBorderType();
+            assertNull(bt);
+            bt = table.getTopBorderType();
+            assertNull(bt);
+            bt = table.getBottomBorderType();
+            assertNull(bt);
+            bt = table.getLeftBorderType();
+            assertNull(bt);
+            bt = table.getRightBorderType();
+            assertNull(bt);
         }
     }
 
     @Test
-    public void testSetGetTopBorders() {
+    public void testSetGetTopBorders() throws IOException {
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getTopBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getTopBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getTopBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getTopBorderColor();
-        assertNull(clr);
-        // set top border
-        table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
-        // get inside vertical border components
-        bt = table.getTopBorderType();
-        assertEquals(XWPFBorderType.THICK, bt);
-        sz = table.getTopBorderSize();
-        assertEquals(4, sz);
-        sp = table.getTopBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getTopBorderColor();
-        assertEquals("00FF00", clr);
-        // remove the border and verify state
-        table.removeTopBorder();
-        bt = table.getTopBorderType();
-        assertNull(bt);
-        sz = table.getTopBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getTopBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getTopBorderColor();
-        assertNull(clr);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getTopBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getTopBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getTopBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getTopBorderColor();
+            assertNull(clr);
+            // set top border
+            table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
+            // get inside vertical border components
+            bt = table.getTopBorderType();
+            assertEquals(XWPFBorderType.THICK, bt);
+            sz = table.getTopBorderSize();
+            assertEquals(4, sz);
+            sp = table.getTopBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getTopBorderColor();
+            assertEquals("00FF00", clr);
+            // remove the border and verify state
+            table.removeTopBorder();
+            bt = table.getTopBorderType();
+            assertNull(bt);
+            sz = table.getTopBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getTopBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getTopBorderColor();
+            assertNull(clr);
         }
     }
 
     @Test
-    public void testSetGetBottomBorders() {
+    public void testSetGetBottomBorders() throws IOException {
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getBottomBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getBottomBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getBottomBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getBottomBorderColor();
-        assertNull(clr);
-        // set inside vertical border
-        table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
-        // get inside vertical border components
-        bt = table.getBottomBorderType();
-        assertEquals(XWPFBorderType.DOTTED, bt);
-        sz = table.getBottomBorderSize();
-        assertEquals(4, sz);
-        sp = table.getBottomBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getBottomBorderColor();
-        assertEquals("00FF00", clr);
-        // remove the border and verify state
-        table.removeBottomBorder();
-        bt = table.getBottomBorderType();
-        assertNull(bt);
-        sz = table.getBottomBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getBottomBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getBottomBorderColor();
-        assertNull(clr);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getBottomBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getBottomBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getBottomBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getBottomBorderColor();
+            assertNull(clr);
+            // set inside vertical border
+            table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
+            // get inside vertical border components
+            bt = table.getBottomBorderType();
+            assertEquals(XWPFBorderType.DOTTED, bt);
+            sz = table.getBottomBorderSize();
+            assertEquals(4, sz);
+            sp = table.getBottomBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getBottomBorderColor();
+            assertEquals("00FF00", clr);
+            // remove the border and verify state
+            table.removeBottomBorder();
+            bt = table.getBottomBorderType();
+            assertNull(bt);
+            sz = table.getBottomBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getBottomBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getBottomBorderColor();
+            assertNull(clr);
         }
     }
 
     @Test
-    public void testSetGetLeftBorders() {
+    public void testSetGetLeftBorders() throws IOException {
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getLeftBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getLeftBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getLeftBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getLeftBorderColor();
-        assertNull(clr);
-        // set inside vertical border
-        table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
-        // get inside vertical border components
-        bt = table.getLeftBorderType();
-        assertEquals(XWPFBorderType.DASHED, bt);
-        sz = table.getLeftBorderSize();
-        assertEquals(4, sz);
-        sp = table.getLeftBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getLeftBorderColor();
-        assertEquals("00FF00", clr);
-        // remove the border and verify state
-        table.removeLeftBorder();
-        bt = table.getLeftBorderType();
-        assertNull(bt);
-        sz = table.getLeftBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getLeftBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getLeftBorderColor();
-        assertNull(clr);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getLeftBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getLeftBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getLeftBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getLeftBorderColor();
+            assertNull(clr);
+            // set inside vertical border
+            table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
+            // get inside vertical border components
+            bt = table.getLeftBorderType();
+            assertEquals(XWPFBorderType.DASHED, bt);
+            sz = table.getLeftBorderSize();
+            assertEquals(4, sz);
+            sp = table.getLeftBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getLeftBorderColor();
+            assertEquals("00FF00", clr);
+            // remove the border and verify state
+            table.removeLeftBorder();
+            bt = table.getLeftBorderType();
+            assertNull(bt);
+            sz = table.getLeftBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getLeftBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getLeftBorderColor();
+            assertNull(clr);
         }
     }
 
     @Test
-    public void testSetGetRightBorders() {
+    public void testSetGetRightBorders() throws IOException {
         // create a table
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        // check initial state
-        XWPFBorderType bt = table.getRightBorderType();
-        assertEquals(XWPFBorderType.SINGLE, bt);
-        int sz = table.getRightBorderSize();
-        assertEquals(-1, sz);
-        int sp = table.getRightBorderSpace();
-        assertEquals(-1, sp);
-        String clr = table.getRightBorderColor();
-        assertNull(clr);
-        // set inside vertical border
-        table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
-        // get inside vertical border components
-        bt = table.getRightBorderType();
-        assertEquals(XWPFBorderType.DOT_DASH, bt);
-        sz = table.getRightBorderSize();
-        assertEquals(4, sz);
-        sp = table.getRightBorderSpace();
-        assertEquals(0, sp);
-        clr = table.getRightBorderColor();
-        assertEquals("00FF00", clr);
-        // remove the border and verify state
-        table.removeRightBorder();
-        bt = table.getRightBorderType();
-        assertNull(bt);
-        sz = table.getRightBorderSize();
-        assertEquals(-1, sz);
-        sp = table.getRightBorderSpace();
-        assertEquals(-1, sp);
-        clr = table.getRightBorderColor();
-        assertNull(clr);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testSetGetRowBandSize() {
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        table.setRowBandSize(12);
-        int sz = table.getRowBandSize();
-        assertEquals(12, sz);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-
-    @Test
-    public void testSetGetColBandSize() {
-        XWPFDocument doc = new XWPFDocument();
-        CTTbl ctTable = CTTbl.Factory.newInstance();
-        XWPFTable table = new XWPFTable(ctTable, doc);
-        table.setColBandSize(16);
-        int sz = table.getColBandSize();
-        assertEquals(16, sz);
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // check initial state
+            XWPFBorderType bt = table.getRightBorderType();
+            assertEquals(XWPFBorderType.SINGLE, bt);
+            int sz = table.getRightBorderSize();
+            assertEquals(-1, sz);
+            int sp = table.getRightBorderSpace();
+            assertEquals(-1, sp);
+            String clr = table.getRightBorderColor();
+            assertNull(clr);
+            // set inside vertical border
+            table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
+            // get inside vertical border components
+            bt = table.getRightBorderType();
+            assertEquals(XWPFBorderType.DOT_DASH, bt);
+            sz = table.getRightBorderSize();
+            assertEquals(4, sz);
+            sp = table.getRightBorderSpace();
+            assertEquals(0, sp);
+            clr = table.getRightBorderColor();
+            assertEquals("00FF00", clr);
+            // remove the border and verify state
+            table.removeRightBorder();
+            bt = table.getRightBorderType();
+            assertNull(bt);
+            sz = table.getRightBorderSize();
+            assertEquals(-1, sz);
+            sp = table.getRightBorderSpace();
+            assertEquals(-1, sp);
+            clr = table.getRightBorderColor();
+            assertNull(clr);
+        }
+    }
+
+    @Test
+    public void testSetGetRowBandSize() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            table.setRowBandSize(12);
+            int sz = table.getRowBandSize();
+            assertEquals(12, sz);
+        }
+    }
+
+    @Test
+    public void testSetGetColBandSize() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            table.setColBandSize(16);
+            int sz = table.getColBandSize();
+            assertEquals(16, sz);
         }
     }
 
     @Test
     public void testCreateTable() throws Exception {
         // open an empty document
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
 
-        // create a table with 5 rows and 7 columns
-        int noRows = 5;
-        int noCols = 7;
-        XWPFTable table = doc.createTable(noRows, noCols);
-
-        // assert the table is empty
-        List<XWPFTableRow> rows = table.getRows();
-        assertEquals("Table has less rows than requested.", noRows, rows.size());
-        for (XWPFTableRow xwpfRow : rows) {
-            assertNotNull(xwpfRow);
-            for (int i = 0; i < 7; i++) {
-                XWPFTableCell xwpfCell = xwpfRow.getCell(i);
-                assertNotNull(xwpfCell);
-                assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
-                xwpfCell = xwpfRow.getCell(i);
-                assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+            // create a table with 5 rows and 7 columns
+            int noRows = 5;
+            int noCols = 7;
+            XWPFTable table = doc.createTable(noRows, noCols);
+
+            // assert the table is empty
+            List<XWPFTableRow> rows = table.getRows();
+            assertEquals("Table has less rows than requested.", noRows, rows.size());
+            for (XWPFTableRow xwpfRow : rows) {
+                assertNotNull(xwpfRow);
+                for (int i = 0; i < 7; i++) {
+                    XWPFTableCell xwpfCell = xwpfRow.getCell(i);
+                    assertNotNull(xwpfCell);
+                    assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
+                    xwpfCell = xwpfRow.getCell(i);
+                    assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+                }
             }
+            doc.getPackage().revert();
         }
-        doc.getPackage().revert();
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
-        }
-    }
-    
-    @Test
-    public void testSetGetTableAlignment() {
-        XWPFDocument doc = new XWPFDocument();
-        XWPFTable tbl = doc.createTable(1, 1);
-        tbl.setTableAlignment(TableRowAlign.LEFT);
-        assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
-        tbl.setTableAlignment(TableRowAlign.CENTER);
-        assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
-        tbl.setTableAlignment(TableRowAlign.RIGHT);
-        assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
-        tbl.removeTableAlignment();
-        assertNull(tbl.getTableAlignment());
-        try {
-            doc.close();
-        } catch (IOException e) {
-            fail("Unable to close doc");
+    }
+
+    @Test
+    public void testSetGetTableAlignment() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            XWPFTable tbl = doc.createTable(1, 1);
+            tbl.setTableAlignment(TableRowAlign.LEFT);
+            assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
+            tbl.setTableAlignment(TableRowAlign.CENTER);
+            assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
+            tbl.setTableAlignment(TableRowAlign.RIGHT);
+            assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
+            tbl.removeTableAlignment();
+            assertNull(tbl.getTableAlignment());
         }
     }
 }
\ No newline at end of file



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