Bug 58829: Remove some useages of printStackTrace() and some other minor cleanups

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1724445 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-01-13 15:59:38 +00:00
parent 8cf781c31b
commit 8793846bc6
7 changed files with 30 additions and 41 deletions

View File

@ -16,14 +16,12 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.eventusermodel; package org.apache.poi.xssf.eventusermodel;
import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.util.CellAddress; 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.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.CommentsTable;

View File

@ -38,17 +38,23 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun
/** /**
* Tests for XWPF Run * Tests for XWPF Run
*/ */
@SuppressWarnings("deprecation")
public class TestXWPFRun extends TestCase { public class TestXWPFRun extends TestCase {
public CTR ctRun; private CTR ctRun;
public XWPFParagraph p; private XWPFParagraph p;
private XWPFDocument doc;
protected void setUp() { protected void setUp() {
XWPFDocument doc = new XWPFDocument(); doc = new XWPFDocument();
p = doc.createParagraph(); p = doc.createParagraph();
this.ctRun = CTR.Factory.newInstance(); this.ctRun = CTR.Factory.newInstance();
} }
protected void tearDown() throws Exception {
doc.close();
}
public void testSetGetText() { public void testSetGetText() {
ctRun.addNewT().setStringValue("TEST STRING"); ctRun.addNewT().setStringValue("TEST STRING");
ctRun.addNewT().setStringValue("TEST2 STRING"); ctRun.addNewT().setStringValue("TEST2 STRING");
@ -410,6 +416,13 @@ public class TestXWPFRun extends TestCase {
assertEquals(1, doc.getAllPictures().size()); assertEquals(1, doc.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().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());
} }
/** /**

View File

@ -22,6 +22,8 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import java.io.IOException;
public final class HWPFDocFixture public final class HWPFDocFixture
{ {
@ -37,10 +39,7 @@ public final class HWPFDocFixture
_testFile = testFile; _testFile = testFile;
} }
public void setUp() public void setUp() throws IOException {
{
try
{
POIFSFileSystem filesystem = new POIFSFileSystem( POIFSFileSystem filesystem = new POIFSFileSystem(
POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile)); POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
@ -66,11 +65,6 @@ public final class HWPFDocFixture
_fib.fillVariableFields(_mainStream, _tableStream); _fib.fillVariableFields(_mainStream, _tableStream);
} }
catch (Throwable t)
{
t.printStackTrace();
}
}
public void tearDown() public void tearDown()
{ {

View File

@ -52,7 +52,7 @@ public final class TestMetaDataIPI extends TestCase{
* Setup is used to get the document ready. Gets the DocumentSummaryInformation and the * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
* SummaryInformation to reasonable values * SummaryInformation to reasonable values
*/ */
public void setUp() { public void setUp() throws Exception {
bout = new ByteArrayOutputStream(); bout = new ByteArrayOutputStream();
poifs = new POIFSFileSystem(); poifs = new POIFSFileSystem();
dir = poifs.getRoot(); dir = poifs.getRoot();
@ -72,9 +72,6 @@ public final class TestMetaDataIPI extends TestCase{
*/ */
dsi = PropertySetFactory.newDocumentSummaryInformation(); dsi = PropertySetFactory.newDocumentSummaryInformation();
assertNotNull(dsi); assertNotNull(dsi);
} catch (Exception e) {
e.printStackTrace();
fail();
} }
assertNotNull(dsi); assertNotNull(dsi);
try { try {
@ -92,9 +89,6 @@ public final class TestMetaDataIPI extends TestCase{
*/ */
si = PropertySetFactory.newSummaryInformation(); si = PropertySetFactory.newSummaryInformation();
assertNotNull(si); assertNotNull(si);
} catch (Exception e) {
e.printStackTrace();
fail();
} }
assertNotNull(dsi); assertNotNull(dsi);
} }
@ -111,13 +105,8 @@ public final class TestMetaDataIPI extends TestCase{
si = null; si = null;
dsi = null; dsi = null;
try {
poifs.writeFilesystem(bout); poifs.writeFilesystem(bout);
bout.flush(); bout.flush();
} catch (IOException e) {
e.printStackTrace();
fail();
}
InputStream is = new ByteArrayInputStream(bout.toByteArray()); InputStream is = new ByteArrayInputStream(bout.toByteArray());
assertNotNull(is); assertNotNull(is);

View File

@ -327,11 +327,7 @@ public class TestWrite
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(); throw new RuntimeException(ex);
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);
} }
} }
}, },
@ -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> * POI filesystem.</p>
* *
* @param f the POI filesystem to check * @param f the POI filesystem to check

View File

@ -152,8 +152,7 @@ final class Util {
} }
catch (IOException ex) catch (IOException ex)
{ {
ex.printStackTrace(); throw new RuntimeException(ex);
throw new RuntimeException(ex.getMessage());
} }
} }
}; };
@ -224,8 +223,7 @@ final class Util {
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(); throw new RuntimeException(ex);
throw new RuntimeException(ex.getMessage());
} }
} }
}; };

View 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.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; 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.TwoDEval;
import org.apache.poi.ss.formula.ptg.AreaI; import org.apache.poi.ss.formula.ptg.AreaI;
import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea; import org.apache.poi.ss.formula.ptg.AreaI.OffsetArea;
import org.apache.poi.ss.usermodel.CellValue; 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. * Test for unary plus operator evaluator.
@ -54,6 +54,7 @@ public final class TestRangeEval extends TestCase {
createRefEval(refA), createRefEval(refA),
createRefEval(refB), createRefEval(refB),
}; };
@SuppressWarnings("deprecation")
AreaReference ar = new AreaReference(expectedAreaRef); AreaReference ar = new AreaReference(expectedAreaRef);
ValueEval result = EvalInstances.Range.evaluate(args, 0, (short)0); ValueEval result = EvalInstances.Range.evaluate(args, 0, (short)0);
assertTrue(result instanceof AreaEval); assertTrue(result instanceof AreaEval);