poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1849812 - in /poi/trunk/src: ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/testcases/org/apache/poi/extractor/ooxml/ ooxml/testcases/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xwpf/usermodel/ testcases/org/apache/poi/hs...
Date Thu, 27 Dec 2018 20:51:32 GMT
Author: centic
Date: Thu Dec 27 20:51:31 2018
New Revision: 1849812

URL: http://svn.apache.org/viewvc?rev=1849812&view=rev
Log:
IDE and JavaDoc fixes, close() in tests

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Thu Dec 27 20:51:31
2018
@@ -1571,7 +1571,7 @@ public abstract class OPCPackage impleme
      *
      * @param oldContentType  the content type to be replaced
      * @param newContentType  the replacement
-     * @return whether replacement was succesfull
+     * @return whether replacement was successful
      * @since POI-3.8
      */
     public boolean replaceContentType(String oldContentType, String newContentType){

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
Thu Dec 27 20:51:31 2018
@@ -470,7 +470,6 @@ public class TestExtractorFactory {
         ExtractorFactory.getEmbededDocsTextExtractors((POIXMLTextExtractor) null);
     }
 
-    @SuppressWarnings("deprecation")
     @Test(expected = IllegalStateException.class)
     public void testGetEmbeddedFromXMLExtractor() {
         // currently not implemented

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
Thu Dec 27 20:51:31 2018
@@ -112,7 +112,6 @@ public final class TestXSSFSheetShiftRow
             return;
         }
         Cell readCell = readRow.getCell(0);
-        //noinspection deprecation
         if(readCell.getCellType() == CellType.NUMERIC) {
             assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
         } else {
@@ -470,7 +469,7 @@ public final class TestXSSFSheetShiftRow
     // bug 60260: shift rows or rename a sheet containing a named range
     // that refers to formula with a unicode (non-ASCII) sheet name formula
     @Test
-    public void shiftRowsWithUnicodeNamedRange() throws IOException {
+    public void shiftRowsWithUnicodeNamedRange() {
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("unicodeSheetName.xlsx");
         XSSFSheet sheet = wb.getSheetAt(0);
         sheet.shiftRows(1, 2, 3);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java Thu Dec 27
20:51:31 2018
@@ -32,27 +32,26 @@ public final class TestXWPFSDT {
 
     /**
      * Test simple tag and title extraction from SDT
-     *
-     * @throws Exception
      */
     @Test
     public void testTagTitle() throws Exception {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
-        String tag = null;
-        String title = null;
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
-        for (XWPFAbstractSDT sdt : sdts) {
-            if (sdt.getContent().toString().equals("Rich_text")) {
-                tag = "MyTag";
-                title = "MyTitle";
-                break;
+        try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) {
+            String tag = null;
+            String title = null;
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            for (XWPFAbstractSDT sdt : sdts) {
+                if (sdt.getContent().toString().equals("Rich_text")) {
+                    tag = "MyTag";
+                    title = "MyTitle";
+                    break;
+                }
+
             }
+            assertEquals("controls size", 13, sdts.size());
 
+            assertEquals("tag", "MyTag", tag);
+            assertEquals("title", "MyTitle", title);
         }
-        assertEquals("controls size", 13, sdts.size());
-
-        assertEquals("tag", "MyTag", tag);
-        assertEquals("title", "MyTitle", title);
     }
 
     @Test
@@ -73,14 +72,15 @@ public final class TestXWPFSDT {
                 "Endnote_sdt"
 
         };
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+        try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug54849.docx")) {
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
 
-        assertEquals("number of sdts", contents.length, sdts.size());
+            assertEquals("number of sdts", contents.length, sdts.size());
 
-        for (int i = 0; i < contents.length; i++) {
-            XWPFAbstractSDT sdt = sdts.get(i);
-            assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString());
+            for (int i = 0; i < contents.length; i++) {
+                XWPFAbstractSDT sdt = sdts.get(i);
+                assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString());
+            }
         }
     }
 
@@ -91,25 +91,26 @@ public final class TestXWPFSDT {
     public void testSDTAsCell() throws Exception {
         //Bug54771a.docx and Bug54771b.docx test slightly 
         //different recursion patterns. Keep both!
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx");
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
-        String text = sdts.get(0).getContent().getText();
-        assertEquals(2, sdts.size());
-        assertContains(text, "Test");
-
-        text = sdts.get(1).getContent().getText();
-        assertContains(text, "Test Subtitle");
-        assertContains(text, "Test User");
-        assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle"));
-
-        doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx");
-        sdts = extractAllSDTs(doc);
-        assertEquals(3, sdts.size());
-        assertContains(sdts.get(0).getContent().getText(), "Test");
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"))
{
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            String text = sdts.get(0).getContent().getText();
+            assertEquals(2, sdts.size());
+            assertContains(text, "Test");
+
+            text = sdts.get(1).getContent().getText();
+            assertContains(text, "Test Subtitle");
+            assertContains(text, "Test User");
+            assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle"));
+        }
 
-        assertContains(sdts.get(1).getContent().getText(), "Test Subtitle");
-        assertContains(sdts.get(2).getContent().getText(), "Test User");
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx"))
{
+             List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            assertEquals(3, sdts.size());
+            assertContains(sdts.get(0).getContent().getText(), "Test");
 
+            assertContains(sdts.get(1).getContent().getText(), "Test Subtitle");
+            assertContains(sdts.get(2).getContent().getText(), "Test User");
+        }
     }
 
     /**
@@ -117,35 +118,37 @@ public final class TestXWPFSDT {
      */
     @Test
     public void testNewLinesBetweenRuns() throws Exception {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx");
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
-        List<String> targs = new ArrayList<>();
-        //these test newlines and tabs in paragraphs/body elements
-        targs.add("Rich-text1 abcdefghi");
-        targs.add("Rich-text2 abcd\t\tefgh");
-        targs.add("Rich-text3 abcd\nefg");
-        targs.add("Rich-text4 abcdefg");
-        targs.add("Rich-text5 abcdefg\nhijk");
-        targs.add("Plain-text1 abcdefg");
-        targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
-        //this tests consecutive runs within a cell (not a paragraph)
-        //this test case was triggered by Tika-1130
-        targs.add("sdt_incell2 abcdefg");
-
-        for (int i = 0; i < sdts.size(); i++) {
-            XWPFAbstractSDT sdt = sdts.get(i);
-            assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
+        try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug55142.docx")) {
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            List<String> targs = new ArrayList<>();
+            //these test newlines and tabs in paragraphs/body elements
+            targs.add("Rich-text1 abcdefghi");
+            targs.add("Rich-text2 abcd\t\tefgh");
+            targs.add("Rich-text3 abcd\nefg");
+            targs.add("Rich-text4 abcdefg");
+            targs.add("Rich-text5 abcdefg\nhijk");
+            targs.add("Plain-text1 abcdefg");
+            targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
+            //this tests consecutive runs within a cell (not a paragraph)
+            //this test case was triggered by Tika-1130
+            targs.add("sdt_incell2 abcdefg");
+
+            for (int i = 0; i < sdts.size(); i++) {
+                XWPFAbstractSDT sdt = sdts.get(i);
+                assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
+            }
         }
     }
 
     @Test
     public void test60341() throws IOException {
         //handle sdtbody without an sdtpr
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx");
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
-        assertEquals(1, sdts.size());
-        assertEquals("", sdts.get(0).getTag());
-        assertEquals("", sdts.get(0).getTitle());
+        try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug60341.docx")) {
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            assertEquals(1, sdts.size());
+            assertEquals("", sdts.get(0).getTag());
+            assertEquals("", sdts.get(0).getTitle());
+        }
     }
 
     @Test
@@ -154,15 +157,15 @@ public final class TestXWPFSDT {
         //it does test for a related issue, and the fix fixes both.
         //We should try to add the actual triggering document
         //to our test suite.
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug62859.docx");
-        List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
-        assertEquals(1, sdts.size());
-        assertEquals("", sdts.get(0).getTag());
-        assertEquals("", sdts.get(0).getTitle());
+        try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("Bug62859.docx")) {
+            List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
+            assertEquals(1, sdts.size());
+            assertEquals("", sdts.get(0).getTag());
+            assertEquals("", sdts.get(0).getTitle());
+        }
     }
 
     private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
-
         List<XWPFAbstractSDT> sdts = new ArrayList<>();
 
         List<XWPFHeader> headers = doc.getHeaderList();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java Thu
Dec 27 20:51:31 2018
@@ -30,10 +30,11 @@ import static org.apache.poi.POITestCase
 public final class TestXWPFSmartTag extends TestCase {
 
     public void testSmartTags() throws IOException {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx");
-        XWPFParagraph p = doc.getParagraphArray(0);
-        assertContains(p.getText(), "Carnegie Mellon University School of Computer Science");
-        p = doc.getParagraphArray(2);
-        assertContains(p.getText(), "Alice's Adventures");
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx"))
{
+            XWPFParagraph p = doc.getParagraphArray(0);
+            assertContains(p.getText(), "Carnegie Mellon University School of Computer Science");
+            p = doc.getParagraphArray(2);
+            assertContains(p.getText(), "Alice's Adventures");
+        }
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java Thu Dec
27 20:51:31 2018
@@ -18,6 +18,7 @@
 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;
@@ -39,18 +40,19 @@ import org.openxmlformats.schemas.wordpr
 public final class TestXWPFStyles {
     @Test
     public void testGetUsedStyles() throws IOException {
-        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx");
-        List<XWPFStyle> testUsedStyleList = new ArrayList<>();
-        XWPFStyles styles = sampleDoc.getStyles();
-        XWPFStyle style = styles.getStyle("berschrift1");
-        testUsedStyleList.add(style);
-        testUsedStyleList.add(styles.getStyle("Standard"));
-        testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
-        testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
-        style.hasSameName(style);
+        try (XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx"))
{
+            List<XWPFStyle> testUsedStyleList = new ArrayList<>();
+            XWPFStyles styles = sampleDoc.getStyles();
+            XWPFStyle style = styles.getStyle("berschrift1");
+            testUsedStyleList.add(style);
+            testUsedStyleList.add(styles.getStyle("Standard"));
+            testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
+            testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
+            style.hasSameName(style);
 
-        List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
-        assertEquals(usedStyleList, testUsedStyleList);
+            List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
+            assertEquals(usedStyleList, testUsedStyleList);
+        }
     }
 
     @Test
@@ -79,13 +81,14 @@ public final class TestXWPFStyles {
      */
     @Test
     public void test52449() throws Exception {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx");
-        XWPFStyles styles = doc.getStyles();
-        assertNotNull(styles);
-
-        XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
-        styles = docIn.getStyles();
-        assertNotNull(styles);
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx")) {
+            XWPFStyles styles = doc.getStyles();
+            assertNotNull(styles);
+
+            XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
+            styles = docIn.getStyles();
+            assertNotNull(styles);
+        }
     }
 
 
@@ -121,8 +124,8 @@ public final class TestXWPFStyles {
         CTLsdException ex = latentStyles.addNewLsdException();
         ex.setName("ex1");
         XWPFLatentStyles ls = new XWPFLatentStyles(latentStyles);
-        assertEquals(true, ls.isLatentStyle("ex1"));
-        assertEquals(false, ls.isLatentStyle("notex1"));
+        assertTrue(ls.isLatentStyle("ex1"));
+        assertFalse(ls.isLatentStyle("notex1"));
     }
 
     @Test
@@ -147,88 +150,89 @@ public final class TestXWPFStyles {
 
     @Test
     public void testEasyAccessToStyles() throws IOException {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
-        XWPFStyles styles = doc.getStyles();
-        assertNotNull(styles);
-
-        // Has 3 paragraphs on page one, a break, and 3 on page 2
-        assertEquals(7, doc.getParagraphs().size());
-
-        // Check the first three have no run styles, just default paragraph style
-        for (int i = 0; i < 3; i++) {
-            XWPFParagraph p = doc.getParagraphs().get(i);
-            assertEquals(null, p.getStyle());
-            assertEquals(null, p.getStyleID());
-            assertEquals(1, p.getRuns().size());
-
-            XWPFRun r = p.getRuns().get(0);
-            assertEquals(null, r.getColor());
-            assertEquals(null, r.getFontFamily());
-            assertEquals(null, r.getFontName());
-            assertEquals(-1, r.getFontSize());
-        }
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"))
{
+            XWPFStyles styles = doc.getStyles();
+            assertNotNull(styles);
+
+            // Has 3 paragraphs on page one, a break, and 3 on page 2
+            assertEquals(7, doc.getParagraphs().size());
+
+            // Check the first three have no run styles, just default paragraph style
+            for (int i = 0; i < 3; i++) {
+                XWPFParagraph p = doc.getParagraphs().get(i);
+                assertNull(p.getStyle());
+                assertNull(p.getStyleID());
+                assertEquals(1, p.getRuns().size());
+
+                XWPFRun r = p.getRuns().get(0);
+                assertNull(r.getColor());
+                assertNull(r.getFontFamily());
+                assertNull(r.getFontName());
+                assertEquals(-1, r.getFontSize());
+            }
+
+            // On page two, has explicit styles, but on runs not on
+            //  the paragraph itself
+            for (int i = 4; i < 7; i++) {
+                XWPFParagraph p = doc.getParagraphs().get(i);
+                assertNull(p.getStyle());
+                assertNull(p.getStyleID());
+                assertEquals(1, p.getRuns().size());
+
+                XWPFRun r = p.getRuns().get(0);
+                assertEquals("Arial Black", r.getFontFamily());
+                assertEquals("Arial Black", r.getFontName());
+                assertEquals(16, r.getFontSize());
+                assertEquals("548DD4", r.getColor());
+            }
+
+            // Check the document styles
+            // Should have a style defined for each type
+            assertEquals(4, styles.getNumberOfStyles());
+            assertNotNull(styles.getStyle("Normal"));
+            assertNotNull(styles.getStyle("DefaultParagraphFont"));
+            assertNotNull(styles.getStyle("TableNormal"));
+            assertNotNull(styles.getStyle("NoList"));
 
-        // On page two, has explicit styles, but on runs not on
-        //  the paragraph itself
-        for (int i = 4; i < 7; i++) {
-            XWPFParagraph p = doc.getParagraphs().get(i);
-            assertEquals(null, p.getStyle());
-            assertEquals(null, p.getStyleID());
-            assertEquals(1, p.getRuns().size());
-
-            XWPFRun r = p.getRuns().get(0);
-            assertEquals("Arial Black", r.getFontFamily());
-            assertEquals("Arial Black", r.getFontName());
-            assertEquals(16, r.getFontSize());
-            assertEquals("548DD4", r.getColor());
-        }
+            // We can't do much yet with latent styles
+            assertEquals(137, styles.getLatentStyles().getNumberOfStyles());
 
-        // Check the document styles
-        // Should have a style defined for each type
-        assertEquals(4, styles.getNumberOfStyles());
-        assertNotNull(styles.getStyle("Normal"));
-        assertNotNull(styles.getStyle("DefaultParagraphFont"));
-        assertNotNull(styles.getStyle("TableNormal"));
-        assertNotNull(styles.getStyle("NoList"));
-
-        // We can't do much yet with latent styles
-        assertEquals(137, styles.getLatentStyles().getNumberOfStyles());
-
-        // Check the default styles
-        assertNotNull(styles.getDefaultRunStyle());
-        assertNotNull(styles.getDefaultParagraphStyle());
+            // Check the default styles
+            assertNotNull(styles.getDefaultRunStyle());
+            assertNotNull(styles.getDefaultParagraphStyle());
 
-        assertEquals(11, styles.getDefaultRunStyle().getFontSize());
-        assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
+            assertEquals(11, styles.getDefaultRunStyle().getFontSize());
+            assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
+        }
     }
     
     // Bug 60329: style with missing StyleID throws NPE
     @Test
     public void testMissingStyleId() throws IOException {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60329.docx");
-        XWPFStyles styles = doc.getStyles();
-        // Styles exist in the test document in this order, EmptyCellLayoutStyle
-        // is missing a StyleId
-        try {
-            assertNotNull(styles.getStyle("NoList"));
-            assertNull(styles.getStyle("EmptyCellLayoutStyle"));
-            assertNotNull(styles.getStyle("BalloonText"));
-        } catch (NullPointerException e) {
-            fail(e.toString());
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60329.docx")) {
+            XWPFStyles styles = doc.getStyles();
+            // Styles exist in the test document in this order, EmptyCellLayoutStyle
+            // is missing a StyleId
+            try {
+                assertNotNull(styles.getStyle("NoList"));
+                assertNull(styles.getStyle("EmptyCellLayoutStyle"));
+                assertNotNull(styles.getStyle("BalloonText"));
+            } catch (NullPointerException e) {
+                fail(e.toString());
+            }
         }
-
-        doc.close();
     }
     
     @Test
     public void testGetStyleByName() throws IOException {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
-        XWPFStyles styles = doc.getStyles();
-        assertNotNull(styles);
-
-        String styleName = "Normal Table";
-        XWPFStyle style = styles.getStyleWithName(styleName);
-        assertNotNull("Expected to find style \"" + styleName + "\"", style);
-        assertEquals(styleName, style.getName());
+        try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"))
{
+            XWPFStyles styles = doc.getStyles();
+            assertNotNull(styles);
+
+            String styleName = "Normal Table";
+            XWPFStyle style = styles.getStyleWithName(styleName);
+            assertNotNull("Expected to find style \"" + styleName + "\"", style);
+            assertEquals(styleName, style.getName());
+        }
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java Thu
Dec 27 20:51:31 2018
@@ -33,7 +33,7 @@ import java.util.List;
 public class TestXWPFTableCell {
 
     @Test
-    public void testSetGetVertAlignment() throws Exception {
+    public void testSetGetVertAlignment() {
         // 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 XWPFTableCell methods.
@@ -62,7 +62,7 @@ public class TestXWPFTableCell {
     }
 
     @Test
-    public void testSetGetColor() throws Exception {
+    public void testSetGetColor() {
         // create a table
         XWPFDocument doc = new XWPFDocument();
         CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -81,7 +81,6 @@ public class TestXWPFTableCell {
     /**
      * ensure that CTHMerge and CTTcBorders go in poi-ooxml.jar
      */
-    @SuppressWarnings("unused")
     @Test
     public void test54099() {
         XWPFDocument doc = new XWPFDocument();
@@ -96,24 +95,27 @@ public class TestXWPFTableCell {
         hMerge.setVal(STMerge.RESTART);
 
         CTTcBorders tblBorders = tcPr.addNewTcBorders();
+        assertNotNull(tblBorders);
         CTVMerge vMerge = tcPr.addNewVMerge();
+        assertNotNull(vMerge);
     }
 
     @Test
     public void testCellVerticalAlign() throws Exception{
-        XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("59030.docx");
-        List<XWPFTable> tables = docx.getTables();
-        assertEquals(1, tables.size());
-
-        XWPFTable table = tables.get(0);
-
-        List<XWPFTableRow> tableRows = table.getRows();
-        assertEquals(2, tableRows.size());
-
-        assertNull(tableRows.get(0).getCell(0).getVerticalAlignment());
-        assertEquals(XWPFVertAlign.BOTTOM, tableRows.get(0).getCell(1).getVerticalAlignment());
-        assertEquals(XWPFVertAlign.CENTER, tableRows.get(1).getCell(0).getVerticalAlignment());
-        assertNull(tableRows.get(1).getCell(1).getVerticalAlignment()); // should return
null since alignment isn't set
+        try (XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("59030.docx")) {
+            List<XWPFTable> tables = docx.getTables();
+            assertEquals(1, tables.size());
+
+            XWPFTable table = tables.get(0);
+
+            List<XWPFTableRow> tableRows = table.getRows();
+            assertEquals(2, tableRows.size());
+
+            assertNull(tableRows.get(0).getCell(0).getVerticalAlignment());
+            assertEquals(XWPFVertAlign.BOTTOM, tableRows.get(0).getCell(1).getVerticalAlignment());
+            assertEquals(XWPFVertAlign.CENTER, tableRows.get(1).getCell(0).getVerticalAlignment());
+            assertNull(tableRows.get(1).getCell(1).getVerticalAlignment()); // should return
null since alignment isn't set
+        }
     }
 
     // This is not a very useful test as written. It is not worth the execution time for
a unit test

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java Thu
Dec 27 20:51:31 2018
@@ -102,20 +102,21 @@ public class TestXWPFTableRow {
     // generated in Word
     @Test
     public void testIsRepeatHeader() throws Exception {
-        XWPFDocument doc = XWPFTestDataSamples
-                .openSampleDocument("Bug60337.docx");
-        XWPFTable table = doc.getTables().get(0);
-        XWPFTableRow tr = table.getRow(0);
-        boolean isRpt = tr.isRepeatHeader();
-        assertTrue(isRpt);
-        
-        tr = table.getRow(1);
-        isRpt = tr.isRepeatHeader();
-        assertFalse(isRpt);
-        
-        tr = table.getRow(2);
-        isRpt = tr.isRepeatHeader();
-        assertFalse(isRpt);
+        try (XWPFDocument doc = XWPFTestDataSamples
+                .openSampleDocument("Bug60337.docx")) {
+            XWPFTable table = doc.getTables().get(0);
+            XWPFTableRow tr = table.getRow(0);
+            boolean isRpt = tr.isRepeatHeader();
+            assertTrue(isRpt);
+
+            tr = table.getRow(1);
+            isRpt = tr.isRepeatHeader();
+            assertFalse(isRpt);
+
+            tr = table.getRow(2);
+            isRpt = tr.isRepeatHeader();
+            assertFalse(isRpt);
+        }
     }
     
     
@@ -123,20 +124,21 @@ public class TestXWPFTableRow {
     // generated in Word
     @Test
     public void testIsCantSplit() throws Exception {
-        XWPFDocument doc = XWPFTestDataSamples
-                .openSampleDocument("Bug60337.docx");
-        XWPFTable table = doc.getTables().get(0);
-        XWPFTableRow tr = table.getRow(0);
-        boolean isCantSplit = tr.isCantSplitRow();
-        assertFalse(isCantSplit);
-        
-        tr = table.getRow(1);
-        isCantSplit = tr.isCantSplitRow();
-        assertFalse(isCantSplit);
+        try (XWPFDocument doc = XWPFTestDataSamples
+                .openSampleDocument("Bug60337.docx")) {
+            XWPFTable table = doc.getTables().get(0);
+            XWPFTableRow tr = table.getRow(0);
+            boolean isCantSplit = tr.isCantSplitRow();
+            assertFalse(isCantSplit);
+
+            tr = table.getRow(1);
+            isCantSplit = tr.isCantSplitRow();
+            assertFalse(isCantSplit);
 
-        tr = table.getRow(2);
-        isCantSplit = tr.isCantSplitRow();
-        assertTrue(isCantSplit);
+            tr = table.getRow(2);
+            isCantSplit = tr.isCantSplitRow();
+            assertTrue(isCantSplit);
+        }
     }
 
     @Test

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java?rev=1849812&r1=1849811&r2=1849812&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java Thu Dec 27
20:51:31 2018
@@ -52,7 +52,7 @@ public final class TestBoundSheetRecord
 
 		try {
 			record.setSheetname("s//*s");
-			throw new AssertionFailedError("Should have thrown IllegalArgumentException, but didnt");
+			fail("Should have thrown IllegalArgumentException, but didnt");
 		} catch (IllegalArgumentException e) {
 			// expected
 		}



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


Mime
View raw message