]> source.dussan.org Git - poi.git/commitdiff
remove unnecessary @SuppressWarnings("deprecation") warnings (because of old xml...
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 1 Jan 2016 02:22:31 +0000 (02:22 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 1 Jan 2016 02:22:31 +0000 (02:22 +0000)
close resources

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722482 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java

index 2a21972f130998a31b24af73cc1750c70386eca7..8e13603dad031ac754cb82122c97a58a3e3ff826 100644 (file)
 ==================================================================== */
 package org.apache.poi.xslf;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
 
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.POIXMLProperties.CoreProperties;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.xslf.usermodel.XSLFRelation;
 import org.apache.poi.xslf.usermodel.XSLFSlideShow;
+import org.apache.xmlbeans.XmlException;
+import org.junit.Before;
+import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
 
-public class TestXSLFSlideShow extends TestCase {
+public class TestXSLFSlideShow {
     private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
     private OPCPackage pack;
 
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
                pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
        }
 
+    @Test
        public void testContainsMainContentType() throws Exception {
                boolean found = false;
                for(PackagePart part : pack.getParts()) {
                        if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
                                found = true;
                        }
-                       //System.out.println(part);
                }
                assertTrue(found);
        }
 
-       public void testOpen() throws Exception {
-
-               XSLFSlideShow xml;
-               
-               // With the finalised uri, should be fine
-               xml = new XSLFSlideShow(pack);
+    @Test
+       public void testOpen() throws IOException, OpenXML4JException, XmlException {
+               // With the finalized uri, should be fine
+               XSLFSlideShow xml = new XSLFSlideShow(pack);
                // Check the core
                assertNotNull(xml.getPresentation());
                
                // Check it has some slides
-               assertTrue(
-                       xml.getSlideReferences().sizeOfSldIdArray() > 0
-               );
-               assertTrue(
-                               xml.getSlideMasterReferences().sizeOfSldMasterIdArray() > 0
-                       );
+               assertNotEquals(0, xml.getSlideReferences().sizeOfSldIdArray());
+               assertNotEquals(0, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
+               
+               xml.close();
        }
        
-    @SuppressWarnings("deprecation")
-       public void testSlideBasics() throws Exception {
+    @Test
+       public void testSlideBasics() throws IOException, OpenXML4JException, XmlException {
                XSLFSlideShow xml = new XSLFSlideShow(pack);
                
                // Should have 1 master
@@ -95,19 +104,26 @@ public class TestXSLFSlideShow extends TestCase {
                assertEquals(2147483648l, masters[0].getId());
                assertEquals("rId1", masters[0].getId2());
                assertNotNull(xml.getSlideMaster(masters[0]));
+               
+               xml.close();
        }
        
-       public void testMetadataBasics() throws Exception {
+    @Test
+       public void testMetadataBasics() throws IOException, OpenXML4JException, XmlException {
                XSLFSlideShow xml = new XSLFSlideShow(pack);
                
                assertNotNull(xml.getProperties().getCoreProperties());
                assertNotNull(xml.getProperties().getExtendedProperties());
                
-               assertEquals("Microsoft Office PowerPoint", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
-               assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
-               assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
+               CTProperties props = xml.getProperties().getExtendedProperties().getUnderlyingProperties();
+               assertEquals("Microsoft Office PowerPoint", props.getApplication());
+               assertEquals(0, props.getCharacters());
+               assertEquals(0, props.getLines());
+               
+               CoreProperties cprops = xml.getProperties().getCoreProperties();
+               assertNull(cprops.getTitle());
+               assertNull(cprops.getUnderlyingProperties().getSubjectProperty().getValue());
                
-               assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
-               assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+               xml.close();
        }
 }
index 5b615ee828e376c816bb525b6359896730fc952b..b1224cbc04e9e0c82b782a9c44d95137f5a60b59 100644 (file)
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.junit.Before;
 import org.junit.Test;
-import org.openxmlformats.schemas.presentationml.x2006.main.*;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
 
 public class TestXMLSlideShow {
    private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
@@ -47,21 +54,20 @@ public class TestXMLSlideShow {
 
    @Test
    public void testOpen() throws Exception {
-      XMLSlideShow xml;
-
       // With the finalised uri, should be fine
-      xml = new XMLSlideShow(pack);
+       XMLSlideShow xml = new XMLSlideShow(pack);
       // Check the core
       assertNotNull(xml.getCTPresentation());
 
       // Check it has some slides
       assertFalse(xml.getSlides().isEmpty());
       assertFalse(xml.getSlideMasters().isEmpty());
+      
+      xml.close();
    }
 
    @Test
-   @SuppressWarnings("deprecation")
-   public void testSlideBasics() throws Exception {
+   public void testSlideBasics() throws IOException {
       XMLSlideShow xml = new XMLSlideShow(pack);
 
       // Should have 1 master
@@ -99,10 +105,12 @@ public class TestXMLSlideShow {
       assertNotNull(notesMaster);
 
       assertNotNull(xml.getNotesMaster());
+      
+      xml.close();
    }
        
    @Test
-   public void testMetadataBasics() throws Exception {
+   public void testMetadataBasics() throws IOException {
       XMLSlideShow xml = new XMLSlideShow(pack);
 
       assertNotNull(xml.getProperties().getCoreProperties());
@@ -114,6 +122,8 @@ public class TestXMLSlideShow {
 
       assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
       assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+      
+      xml.close();
    }
    
    @Test
@@ -128,8 +138,7 @@ public class TestXMLSlideShow {
       }
       
       // Try another with comments
-      OPCPackage packComments = OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx"));
-      XMLSlideShow xmlComments = new XMLSlideShow(packComments);
+      XMLSlideShow xmlComments = new XMLSlideShow(slTests.openResourceAsStream("45545_Comment.pptx"));
       
       // Has one author
       assertNotNull(xmlComments.getCommentAuthors());
@@ -155,5 +164,8 @@ public class TestXMLSlideShow {
             assertEquals(null, slide.getComments());
          }
       }
+      
+      xmlComments.close();
+      xml.close();
    }
 }
index 78b29cb104981e2557b68e36642fb90e30924d62..bb558799c33fb25542e990720b21d90b3db3e9f1 100644 (file)
@@ -2539,7 +2539,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         runTest56574(true);
     }
 
-    @SuppressWarnings("deprecation")
     private void runTest56574(boolean createRow) throws IOException {
         Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56574.xlsx");
 
index 92fc298ab518d5b1a3174aa8aa638582f312f602..1d3f97ff8fa6c7545fc226deaa18b9a562baaf0a 100644 (file)
 
 package org.apache.poi.xssf.usermodel;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
 
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.junit.Test;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
 
@@ -36,7 +40,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
  * </em>
  * 
  */
-public class TestXSSFColGrouping extends TestCase {
+public class TestXSSFColGrouping {
        
        private static final POILogger logger = POILogFactory.getLogger(TestXSSFColGrouping.class);
 
@@ -45,10 +49,10 @@ public class TestXSSFColGrouping extends TestCase {
      * Tests that POI doesn't produce "col" elements without "width" attribute. 
      * POI-52186
      */
-    @SuppressWarnings("deprecation")
-    public void testNoColsWithoutWidthWhenGrouping() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+    public void testNoColsWithoutWidthWhenGrouping() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         sheet.setColumnWidth(4, 5000);
         sheet.setColumnWidth(5, 5000);
@@ -56,24 +60,27 @@ public class TestXSSFColGrouping extends TestCase {
         sheet.groupColumn((short) 4, (short) 7);
         sheet.groupColumn((short) 9, (short) 12);
         
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testNoColsWithoutWidthWhenGrouping");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGrouping");
+        sheet = wb2.getSheet("test");
         
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
         for (CTCol col : cols.getColArray()) {
                        assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
                }
+        
+        wb2.close();
+        wb1.close();
     }
 
     /**
      * Tests that POI doesn't produce "col" elements without "width" attribute. 
      * POI-52186
      */
-    @SuppressWarnings("deprecation")
-    public void testNoColsWithoutWidthWhenGroupingAndCollapsing() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+       public void testNoColsWithoutWidthWhenGroupingAndCollapsing() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         sheet.setColumnWidth(4, 5000);
         sheet.setColumnWidth(5, 5000);
@@ -85,8 +92,8 @@ public class TestXSSFColGrouping extends TestCase {
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         logger.log(POILogger.DEBUG, "test52186_2/cols:" + cols);
 
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing");
+        sheet = wb2.getSheet("test");
         
         for (int i = 4; i <= 5; i++) {
                assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i));
@@ -95,14 +102,17 @@ public class TestXSSFColGrouping extends TestCase {
         for (CTCol col : cols.getColArray()) {
                        assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
                }
+        wb2.close();
+        wb1.close();
     }
     
     /**
      * Test the cols element is correct in case of NumericRanges.OVERLAPS_2_WRAPS
      */
-    public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+    public void testMergingOverlappingCols_OVERLAPS_2_WRAPS() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         CTCol col = cols.addNewCol();
@@ -133,20 +143,24 @@ public class TestXSSFColGrouping extends TestCase {
         
         assertEquals(3, cols.sizeOfColArray());
 
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_WRAPS");
+        sheet = wb2.getSheet("test");
         
         for (int i = 1; i <= 4; i++) {
                assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
         }
+        
+        wb2.close();
+        wb1.close();
     }
 
     /**
      * Test the cols element is correct in case of NumericRanges.OVERLAPS_1_WRAPS
      */
-    public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+    public void testMergingOverlappingCols_OVERLAPS_1_WRAPS() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         CTCol col = cols.addNewCol();
@@ -177,20 +191,24 @@ public class TestXSSFColGrouping extends TestCase {
         
         assertEquals(3, cols.sizeOfColArray());
         
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_WRAPS");
+        sheet = wb2.getSheet("test");
         
         for (int i = 2; i <= 4; i++) {
                assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
         }
+        
+        wb2.close();
+        wb1.close();
     }
 
     /**
      * Test the cols element is correct in case of NumericRanges.OVERLAPS_1_MINOR
      */
-    public void testMergingOverlappingCols_OVERLAPS_1_MINOR() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+    public void testMergingOverlappingCols_OVERLAPS_1_MINOR() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         CTCol col = cols.addNewCol();
@@ -221,21 +239,25 @@ public class TestXSSFColGrouping extends TestCase {
         
         assertEquals(3, cols.sizeOfColArray());
         
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_1_MINOR");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_1_MINOR");
+        sheet = wb2.getSheet("test");
         
         for (int i = 2; i <= 4; i++) {
                assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
         }
        assertEquals("Unexpected width of column "+ 5, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(5));
+       
+       wb2.close();
+       wb1.close();
     }
 
     /**
      * Test the cols element is correct in case of NumericRanges.OVERLAPS_2_MINOR
      */
-   public void testMergingOverlappingCols_OVERLAPS_2_MINOR() {
-               XSSFWorkbook wb = new XSSFWorkbook();
-               XSSFSheet sheet = wb.createSheet("test");
+       @Test
+    public void testMergingOverlappingCols_OVERLAPS_2_MINOR() throws IOException {
+               XSSFWorkbook wb1 = new XSSFWorkbook();
+               XSSFSheet sheet = wb1.createSheet("test");
 
         CTCols cols = sheet.getCTWorksheet().getColsArray(0);
         CTCol col = cols.addNewCol();
@@ -266,13 +288,16 @@ public class TestXSSFColGrouping extends TestCase {
         
         assertEquals(3, cols.sizeOfColArray());
         
-        wb = XSSFTestDataSamples.writeOutAndReadBack(wb, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
-        sheet = wb.getSheet("test");
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testMergingOverlappingCols_OVERLAPS_2_MINOR");
+        sheet = wb2.getSheet("test");
         
         for (int i = 2; i <= 4; i++) {
                assertEquals("Unexpected width of column "+ i, 20 * 256, sheet.getColumnWidth(i));
         }
        assertEquals("Unexpected width of column "+ 1, sheet.getDefaultColumnWidth() * 256, sheet.getColumnWidth(1));
+       
+       wb2.close();
+       wb1.close();
     }
 
 }
index 1ae86e434763bc4517c413963f01422c61a8f7c9..2fbda00441392a313bc8cb05e0b56f36c2dcb636 100644 (file)
@@ -327,7 +327,6 @@ public final class TestXSSFSheet extends BaseTestSheet {
 
 
     @Test
-    @SuppressWarnings("deprecation")
     public void groupUngroupColumn() throws IOException {
         XSSFWorkbook workbook = new XSSFWorkbook();
         XSSFSheet sheet = workbook.createSheet();
@@ -969,7 +968,6 @@ public final class TestXSSFSheet extends BaseTestSheet {
      */
     @Override
     @Test
-    @SuppressWarnings("deprecation")
     public void createRow() throws IOException {
         XSSFWorkbook workbook = new XSSFWorkbook();
         XSSFSheet sheet = workbook.createSheet();
index 62ca0196442439efcbb9e86ecf00f66123e56dd5..ba8ffd5d90188c28171f1efc42803aec91035215 100644 (file)
@@ -38,17 +38,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
 
 public final class TestXSSFTable {
 
-    public TestXSSFTable() {
-    }
-
     @Test
-    @SuppressWarnings("deprecation")
     public void bug56274() throws IOException {
         // read sample file
-        XSSFWorkbook inputWorkbook = XSSFTestDataSamples.openSampleWorkbook("56274.xlsx");
+        XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("56274.xlsx");
 
         // read the original sheet header order
-        XSSFRow row = inputWorkbook.getSheetAt(0).getRow(0);
+        XSSFRow row = wb1.getSheetAt(0).getRow(0);
         List<String> headers = new ArrayList<String>();
         for (Cell cell : row) {
             headers.add(cell.getStringCellValue());
@@ -56,12 +52,17 @@ public final class TestXSSFTable {
 
         // save the worksheet as-is using SXSSF
         File outputFile = TempFile.createTempFile("poi-56274", ".xlsx");
-        SXSSFWorkbook outputWorkbook = new org.apache.poi.xssf.streaming.SXSSFWorkbook(inputWorkbook);
-        outputWorkbook.write(new FileOutputStream(outputFile));
+        SXSSFWorkbook outputWorkbook = new SXSSFWorkbook(wb1);
+        FileOutputStream fos = new FileOutputStream(outputFile);
+        outputWorkbook.write(fos);
+        fos.close();
+        outputWorkbook.close();
 
         // re-read the saved file and make sure headers in the xml are in the original order
-        inputWorkbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(new FileInputStream(outputFile));
-        CTTable ctTable = inputWorkbook.getSheetAt(0).getTables().get(0).getCTTable();
+        FileInputStream fis = new FileInputStream(outputFile);
+        XSSFWorkbook wb2 = new XSSFWorkbook(fis);
+        fis.close();
+        CTTable ctTable = wb2.getSheetAt(0).getTables().get(0).getCTTable();
         CTTableColumn[] ctTableColumnArray = ctTable.getTableColumns().getTableColumnArray();
 
         assertEquals("number of headers in xml table should match number of header cells in worksheet",
@@ -71,10 +72,12 @@ public final class TestXSSFTable {
                     headers.get(i), ctTableColumnArray[i].getName());
         }
         assertTrue(outputFile.delete());
+        wb2.close();
+        wb1.close();
     }
 
     @Test
-    public void testCTTableStyleInfo(){
+    public void testCTTableStyleInfo() throws IOException {
         XSSFWorkbook outputWorkbook = new XSSFWorkbook();
         XSSFSheet sheet = outputWorkbook.createSheet();
 
@@ -103,6 +106,8 @@ public final class TestXSSFTable {
         assertEquals("Show row stripes",
                 outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes());
 
+        inputWorkbook.close();
+        outputWorkbook.close();
     }
 
 }
\ No newline at end of file
index f53d524b01ebaee10bf56a3b1dfb5da075d80a21..915f0716b5467b8724a46725f0324d894e837889 100644 (file)
 
 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.IOException;
 import java.math.BigInteger;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.junit.Ignore;
+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;
@@ -47,14 +53,16 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
 /**
  * Tests for XWPF Paragraphs
  */
-public final class TestXWPFParagraph extends TestCase {
+public final class TestXWPFParagraph {
 
     /**
      * Check that we get the right paragraph from the header
      *
      * @throws IOException
      */
-    public void disabled_testHeaderParagraph() throws IOException {
+    @Test
+    @Ignore
+    public void testHeaderParagraph() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
 
         XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
@@ -65,8 +73,9 @@ public final class TestXWPFParagraph extends TestCase {
         XWPFParagraph p = ps.get(0);
 
         assertEquals(5, p.getCTP().sizeOfRArray());
-        assertEquals("First header column!\tMid header\tRight header!", p
-                .getText());
+        assertEquals("First header column!\tMid header\tRight header!", p.getText());
+        
+        xml.close();
     }
 
     /**
@@ -74,7 +83,9 @@ public final class TestXWPFParagraph extends TestCase {
      *
      * @throws IOException
      */
-    public void disabled_testDocumentParagraph() throws IOException {
+    @Test
+    @Ignore
+    public void testDocumentParagraph() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
         List<XWPFParagraph> ps = xml.getParagraphs();
         assertEquals(10, ps.size());
@@ -95,9 +106,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         assertFalse(ps.get(4).isEmpty());
         assertEquals("More on page one", ps.get(4).getText());
+        
+        xml.close();
     }
 
-    public void testSetGetBorderTop() {
+    @Test
+    public void testSetGetBorderTop() throws IOException {
         //new clean instance of paragraph
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
@@ -116,9 +130,12 @@ public final class TestXWPFParagraph extends TestCase {
         assertEquals(Borders.DOUBLE, p.getBorderTop());
         p.setBorderTop(Borders.SINGLE);
         assertEquals(STBorder.SINGLE, borderTop.getVal());
+        
+        doc.close();
     }
 
-    public void testSetGetAlignment() {
+    @Test
+    public void testSetGetAlignment() throws IOException {
         //new clean instance of paragraph
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
@@ -134,10 +151,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setAlignment(ParagraphAlignment.BOTH);
         assertEquals(STJc.BOTH, ppr.getJc().getVal());
+        
+        doc.close();
     }
 
-
-    public void testSetGetSpacing() {
+    @Test
+    public void testSetGetSpacing() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -152,9 +171,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setSpacingAfter(100);
         assertEquals(100, spacing.getAfter().intValue());
+        
+        doc.close();
     }
 
-    public void testSetGetSpacingLineRule() {
+    @Test
+    public void testSetGetSpacingLineRule() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -169,9 +191,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setSpacingAfter(100);
         assertEquals(100, spacing.getAfter().intValue());
+        
+        doc.close();
     }
 
-    public void testSetGetIndentation() {
+    @Test
+    public void testSetGetIndentation() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -188,9 +213,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setIndentationLeft(100);
         assertEquals(100, ind.getLeft().intValue());
+        
+        doc.close();
     }
 
-    public void testSetGetVerticalAlignment() {
+    @Test
+    public void testSetGetVerticalAlignment() throws IOException {
         //new clean instance of paragraph
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
@@ -204,9 +232,12 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setVerticalAlignment(TextAlignment.BOTTOM);
         assertEquals(STTextAlignment.BOTTOM, ppr.getTextAlignment().getVal());
+        
+        doc.close();
     }
 
-    public void testSetGetWordWrap() {
+    @Test
+    public void testSetGetWordWrap() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -217,12 +248,14 @@ public final class TestXWPFParagraph extends TestCase {
         wordWrap.setVal(STOnOff.FALSE);
         assertEquals(false, p.isWordWrap());
 
-        p.setWordWrap(true);
+        p.setWordWrapped(true);
         assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
+        
+        doc.close();
     }
 
-
-    public void testSetGetPageBreak() {
+    @Test
+    public void testSetGetPageBreak() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -235,9 +268,10 @@ public final class TestXWPFParagraph extends TestCase {
 
         p.setPageBreak(true);
         assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
+        doc.close();
     }
 
-    @SuppressWarnings("deprecation")
+    @Test
     public void testBookmarks() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("bookmarks.docx");
         XWPFParagraph paragraph = doc.getParagraphs().get(0);
@@ -249,17 +283,21 @@ public final class TestXWPFParagraph extends TestCase {
         for (CTBookmark bookmark : paragraph.getCTP().getBookmarkStartArray()) {
             assertEquals("poi", bookmark.getName());
         }
+        doc.close();
     }
 
-    public void testGetSetNumID() {
+    @Test
+    public void testGetSetNumID() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
         p.setNumID(new BigInteger("10"));
         assertEquals("10", p.getNumID().toString());
+        doc.close();
     }
 
-    public void testAddingRuns() throws Exception {
+    @Test
+    public void testAddingRuns() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
 
         XWPFParagraph p = doc.getParagraphs().get(0);
@@ -273,9 +311,12 @@ public final class TestXWPFParagraph extends TestCase {
         assertEquals(4, p.getRuns().size());
         assertEquals(1, p.getRuns().indexOf(r2));
         assertEquals(3, p.getRuns().indexOf(r));
+        
+        doc.close();
     }
 
-    public void testPictures() throws Exception {
+    @Test
+    public void testPictures() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
         assertEquals(7, doc.getParagraphs().size());
 
@@ -346,17 +387,22 @@ public final class TestXWPFParagraph extends TestCase {
         r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
         PicDocument pd = new PicDocumentImpl(null);
         assertTrue(pd.isNil());
+        
+        doc.close();
     }
 
+    @Test
     public void testTika792() throws Exception {
         //This test forces the loading of CTMoveBookmark and
         //CTMoveBookmarkImpl into ooxml-lite.
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Tika-792.docx");
         XWPFParagraph paragraph = doc.getParagraphs().get(0);
         assertEquals("s", paragraph.getText());
+        doc.close();
     }
 
-    public void testSettersGetters() {
+    @Test
+    public void testSettersGetters() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -455,9 +501,9 @@ public final class TestXWPFParagraph extends TestCase {
         assertEquals(25, p.getIndentationFirstLine());
 
         assertFalse(p.isWordWrap());
-        p.setWordWrap(true);
+        p.setWordWrapped(true);
         assertTrue(p.isWordWrap());
-        p.setWordWrap(false);
+        p.setWordWrapped(false);
         assertFalse(p.isWordWrap());
 
         assertNull(p.getStyle());
@@ -471,16 +517,21 @@ public final class TestXWPFParagraph extends TestCase {
         assertNotNull(p.getBody());
         assertEquals(BodyElementType.PARAGRAPH, p.getElementType());
         assertEquals(BodyType.DOCUMENT, p.getPartType());
+        
+        doc.close();
     }
 
-    public void testSearchTextNotFound() {
+    @Test
+    public void testSearchTextNotFound() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
         assertNull(p.searchText("test", new PositionInParagraph()));
         assertEquals("", p.getText());
+        doc.close();
     }
 
+    @Test
     public void testSearchTextFound() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
 
@@ -495,9 +546,11 @@ public final class TestXWPFParagraph extends TestCase {
         assertEquals("sample word document", p.getText(segment));
 
         assertTrue(p.removeRun(0));
+        xml.close();
     }
     
-    public void testFieldRuns() throws Exception {
+    @Test
+    public void testFieldRuns() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx");
         List<XWPFParagraph> ps = doc.getParagraphs();
         assertEquals(1, ps.size());
@@ -513,10 +566,12 @@ public final class TestXWPFParagraph extends TestCase {
         assertEquals(" FILENAME   \\* MERGEFORMAT ", fr.getFieldInstruction());
         assertEquals("FldSimple.docx", fr.text());
         assertEquals("FldSimple.docx", p.getText());
+        doc.close();
     }
 
     @SuppressWarnings("deprecation")
-    public void testRuns() {
+    @Test
+    public void testRuns() throws IOException {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
 
@@ -527,5 +582,6 @@ public final class TestXWPFParagraph extends TestCase {
 
         assertNotNull(p.getRun(run));
         assertNull(p.getRun(null));
+        doc.close();
     }
 }