]> source.dussan.org Git - poi.git/commitdiff
Bug 58829: Remove some useages of printStackTrace() and some other minor cleanups
authorDominik Stadler <centic@apache.org>
Wed, 13 Jan 2016 15:59:38 +0000 (15:59 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 13 Jan 2016 15:59:38 +0000 (15:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1724445 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
src/testcases/org/apache/poi/hpsf/basic/Util.java
src/testcases/org/apache/poi/ss/formula/eval/TestRangeEval.java

index 9ff2238578ee76e80cc6b7add9925242b5bdbd9c..24a0564d16562132c2818a751a9d2a44aaa50a8f 100644 (file)
 ==================================================================== */
 package org.apache.poi.xssf.eventusermodel;
 
-import java.util.Comparator;
 import java.util.LinkedList;
 import java.util.Queue;
 
 import org.apache.poi.ss.usermodel.BuiltinFormats;
 import org.apache.poi.ss.usermodel.DataFormatter;
 import org.apache.poi.ss.util.CellAddress;
-import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.model.CommentsTable;
index 2b1340fc7570465174bdf22442269118a4eba9e3..0b3434f9e0522a6cb945471e06154d84de421837 100644 (file)
@@ -38,16 +38,22 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun
 /**
  * Tests for XWPF Run
  */
+@SuppressWarnings("deprecation")
 public class TestXWPFRun extends TestCase {
-    public CTR ctRun;
-    public XWPFParagraph p;
+    private CTR ctRun;
+    private XWPFParagraph p;
+    private XWPFDocument doc;
 
     protected void setUp() {
-        XWPFDocument doc = new XWPFDocument();
+        doc = new XWPFDocument();
         p = doc.createParagraph();
 
         this.ctRun = CTR.Factory.newInstance();
     }
+    
+    protected void tearDown() throws Exception {
+        doc.close();
+    }
 
     public void testSetGetText() {
         ctRun.addNewT().setStringValue("TEST STRING");
@@ -410,6 +416,13 @@ public class TestXWPFRun extends TestCase {
 
         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());
     }
 
     /**
index 1b4d94ca3c0b3b30c13b677b6b746b854e6e7369..d306bfabc001b477c06a4f4cbd8f8686ac3d16bc 100644 (file)
@@ -22,6 +22,8 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.POIDataSamples;
 
+import java.io.IOException;
+
 
 public final class HWPFDocFixture
 {
@@ -37,10 +39,7 @@ public final class HWPFDocFixture
     _testFile = testFile;
   }
 
-  public void setUp()
-  {
-    try
-    {
+  public void setUp() throws IOException {
       POIFSFileSystem filesystem = new POIFSFileSystem(
               POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
 
@@ -65,11 +64,6 @@ public final class HWPFDocFixture
       filesystem.createDocumentInputStream(name).read(_tableStream);
 
       _fib.fillVariableFields(_mainStream, _tableStream);
-    }
-    catch (Throwable t)
-    {
-      t.printStackTrace();
-    }
   }
 
   public void tearDown()
index 9b6278517292c9cd07c6f86472b0420faf43fc17..27758a4474854aa34e2ea94efbfccc0e046264f8 100644 (file)
@@ -52,7 +52,7 @@ public final class TestMetaDataIPI extends TestCase{
         * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
         * SummaryInformation to reasonable values
         */
-       public void setUp() {
+       public void setUp() throws Exception {
                bout = new ByteArrayOutputStream();
                poifs = new POIFSFileSystem();
                dir = poifs.getRoot();
@@ -72,9 +72,6 @@ public final class TestMetaDataIPI extends TestCase{
                         */
                        dsi = PropertySetFactory.newDocumentSummaryInformation();
                        assertNotNull(dsi);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       fail();
                }
                assertNotNull(dsi);
                try {
@@ -92,9 +89,6 @@ public final class TestMetaDataIPI extends TestCase{
                         */
                        si = PropertySetFactory.newSummaryInformation();
                        assertNotNull(si);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       fail();
                }
                assertNotNull(dsi);
        }
@@ -111,13 +105,8 @@ public final class TestMetaDataIPI extends TestCase{
 
                si = null;
                dsi = null;
-               try {
-                       poifs.writeFilesystem(bout);
-                       bout.flush();
-               } catch (IOException e) {
-                       e.printStackTrace();
-                       fail();
-               }
+        poifs.writeFilesystem(bout);
+        bout.flush();
 
                InputStream is = new ByteArrayInputStream(bout.toByteArray());
                assertNotNull(is);
index 3ec50c5c909fd98932e9672f691e9bf47861ee25..e240f270726eefd8a7ca66b6a03402121d3ae52f 100644 (file)
@@ -327,11 +327,7 @@ public class TestWrite
                     }
                     catch (Exception ex)
                     {
-                        ex.printStackTrace();
-                        throw new RuntimeException(ex.toString());
-                        /* FIXME (2): Replace the previous line by the following
-                         * one once we no longer need JDK 1.3 compatibility. */
-                        // throw new RuntimeException(ex);
+                        throw new RuntimeException(ex);
                     }
                 }
             },
@@ -716,7 +712,7 @@ public class TestWrite
 
 
     /**
-     * <p>Performs the check described in {@link #testRecreate()} for a single
+     * <p>Performs the check described in {@link #recreate()} for a single
      * POI filesystem.</p>
      *
      * @param f the POI filesystem to check
index 097ff1aa15494185fb639a6e15fd4837de0023c0..6b33f54d1323028e1d8469a71aa98728577aae8b 100644 (file)
@@ -152,8 +152,7 @@ final class Util {
                 }
                 catch (IOException ex)
                 {
-                    ex.printStackTrace();
-                    throw new RuntimeException(ex.getMessage());
+                    throw new RuntimeException(ex);
                 }
             }
         };
@@ -224,8 +223,7 @@ final class Util {
                 }
                 catch (Exception ex)
                 {
-                    ex.printStackTrace();
-                    throw new RuntimeException(ex.getMessage());
+                    throw new RuntimeException(ex);
                 }
             }
         };
index 5057c4115034c5f58350415e6898d977ba936bb1..7493ffd087dec43995d4d90dc6908d27cb94db2f 100644 (file)
@@ -24,12 +24,12 @@ import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.AreaReference;
-import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.ss.formula.TwoDEval;
 import org.apache.poi.ss.formula.ptg.AreaI;
 import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
 import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.util.AreaReference;
+import org.apache.poi.ss.util.CellReference;
 
 /**
  * Test for unary plus operator evaluator.
@@ -54,7 +54,8 @@ public final class TestRangeEval extends TestCase {
                        createRefEval(refA),
                        createRefEval(refB),
                };
-               AreaReference ar = new AreaReference(expectedAreaRef);
+               @SuppressWarnings("deprecation")
+        AreaReference ar = new AreaReference(expectedAreaRef);
                ValueEval result = EvalInstances.Range.evaluate(args, 0, (short)0);
                assertTrue(result instanceof AreaEval);
                AreaEval ae = (AreaEval) result;