diff options
author | Josh Micich <josh@apache.org> | 2009-08-22 05:50:32 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2009-08-22 05:50:32 +0000 |
commit | e8b5f3670405426c04e3e2fb12400fceb375c8d2 (patch) | |
tree | cf89077ca9ec6fee830a93173cf2abf63a294840 | |
parent | f8a0d4bb517fb0302f8ac3823e9bd65a303ffea2 (diff) | |
download | poi-e8b5f3670405426c04e3e2fb12400fceb375c8d2.tar.gz poi-e8b5f3670405426c04e3e2fb12400fceb375c8d2.zip |
fixing compiler warnings - unused imports, declared exceptions not thrown
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@806789 13f79535-47bb-0310-9956-ffa450edef68
32 files changed, 494 insertions, 561 deletions
diff --git a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java index 480a71ad9b..47fe05ed91 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java @@ -14,19 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ -package org.apache.poi; -import java.io.IOException; +package org.apache.poi; -import org.apache.xmlbeans.XmlException; -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty; /** * A {@link POITextExtractor} for returning the textual * content of the OOXML file properties, eg author - * and title. + * and title. */ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor { /** @@ -42,17 +39,17 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor { * working on. */ public POIXMLPropertiesTextExtractor(POIXMLTextExtractor otherExtractor) { - super(otherExtractor.document); + super(otherExtractor.getDocument()); } - + /** * Returns the core document properties, eg author */ public String getCorePropertiesText() { StringBuffer text = new StringBuffer(); PackagePropertiesPart props = - document.getProperties().getCoreProperties().getUnderlyingProperties(); - + getDocument().getProperties().getCoreProperties().getUnderlyingProperties(); + text.append("Category = " + props.getCategoryProperty().getValue() + "\n"); text.append("ContentStatus = " + props.getContentStatusProperty().getValue() + "\n"); text.append("ContentType = " + props.getContentTypeProperty().getValue() + "\n"); @@ -82,7 +79,7 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor { public String getExtendedPropertiesText() { StringBuffer text = new StringBuffer(); org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties - props = document.getProperties().getExtendedProperties().getUnderlyingProperties(); + props = getDocument().getProperties().getExtendedProperties().getUnderlyingProperties(); text.append("Application = " + props.getApplication() + "\n"); text.append("AppVersion = " + props.getAppVersion() + "\n"); @@ -99,36 +96,36 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor { text.append("PresentationFormat = " + props.getPresentationFormat() + "\n"); text.append("Template = " + props.getTemplate() + "\n"); text.append("TotalTime = " + props.getTotalTime() + "\n"); - + return text.toString(); } /** - * Returns the custom document properties, if + * Returns the custom document properties, if * there are any */ public String getCustomPropertiesText() { StringBuffer text = new StringBuffer(); org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties - props = document.getProperties().getCustomProperties().getUnderlyingProperties(); - + props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties(); + CTProperty[] properties = props.getPropertyArray(); for(int i = 0; i<properties.length; i++) { // TODO - finish off String val = "(not implemented!)"; - + text.append( properties[i].getName() + " = " + val + "\n" ); } - + return text.toString(); } public String getText() { try { - return - getCorePropertiesText() + + return + getCorePropertiesText() + getExtendedPropertiesText() + getCustomPropertiesText(); } catch(Exception e) { diff --git a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java index 3f66ee5391..b3c4182d59 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java @@ -14,59 +14,58 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ -package org.apache.poi; -import java.io.IOException; +package org.apache.poi; -import org.apache.poi.POIXMLProperties.*; -import org.apache.xmlbeans.XmlException; -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; +import org.apache.poi.POIXMLProperties.CoreProperties; +import org.apache.poi.POIXMLProperties.CustomProperties; +import org.apache.poi.POIXMLProperties.ExtendedProperties; public abstract class POIXMLTextExtractor extends POITextExtractor { /** The POIXMLDocument that's open */ - protected POIXMLDocument document; + private final POIXMLDocument _document; /** * Creates a new text extractor for the given document */ public POIXMLTextExtractor(POIXMLDocument document) { super((POIDocument)null); - - this.document = document; + + _document = document; } - + /** * Returns the core document properties */ public CoreProperties getCoreProperties() { - return document.getProperties().getCoreProperties(); + return _document.getProperties().getCoreProperties(); } /** * Returns the extended document properties */ public ExtendedProperties getExtendedProperties() { - return document.getProperties().getExtendedProperties(); + return _document.getProperties().getExtendedProperties(); } /** * Returns the custom document properties */ public CustomProperties getCustomProperties() { - return document.getProperties().getCustomProperties(); + return _document.getProperties().getCustomProperties(); } /** - * Returns opened document + * Returns opened document */ - public POIXMLDocument getDocument(){ - return document; + public final POIXMLDocument getDocument(){ + return _document; } - - + + /** - * Returns an OOXML properties text extractor for the + * Returns an OOXML properties text extractor for the * document properties metadata, such as title and author. */ public POIXMLPropertiesTextExtractor getMetadataTextExtractor() { - return new POIXMLPropertiesTextExtractor(document); + return new POIXMLPropertiesTextExtractor(_document); } } diff --git a/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java b/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java index 3a3dc27d72..ba9cfe92af 100755 --- a/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java +++ b/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java @@ -15,10 +15,8 @@ limitations under the License. ==================================================================== */ - package org.apache.poi; -import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; @@ -27,8 +25,8 @@ import junit.framework.TestCase; import org.apache.poi.POIXMLProperties.CoreProperties; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.poi.xwpf.usermodel.XWPFDocument; /** * Test setting extended and custom OOXML properties @@ -37,8 +35,8 @@ public final class TestPOIXMLProperties extends TestCase { private POIXMLProperties _props; private CoreProperties _coreProperties; - public void setUp() throws Exception{ - XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx"); + public void setUp() { + XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx"); _props = sampleDoc.getProperties(); _coreProperties = _props.getCoreProperties(); assertNotNull(_props); @@ -168,7 +166,7 @@ public final class TestPOIXMLProperties extends TestCase { public void testGetSetRevision() { String revision = _coreProperties.getRevision(); - assertTrue("Revision number is 1", new Integer(revision)> 1); + assertTrue("Revision number is 1", Integer.parseInt(revision) > 1); _coreProperties.setRevision("20"); assertEquals("20", _coreProperties.getRevision()); _coreProperties.setRevision("20xx"); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java index 7e6281e757..0ace7c3f63 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java @@ -17,16 +17,15 @@ package org.apache.poi.xssf.eventusermodel; -import java.io.File; import java.io.InputStream; import java.util.Iterator; import junit.framework.TestCase; +import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.util.IOUtils; -import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xssf.usermodel.XSSFRichTextString; /** * Tests for {@link XSSFReader} diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java index 14dde090e2..6555d65938 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java @@ -21,21 +21,24 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.List; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFComment; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xssf.XSSFTestDataSamples; -import org.apache.poi.POIXMLDocumentPart; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument; public class TestCommentsTable extends TestCase { @@ -118,7 +121,7 @@ public class TestCommentsTable extends TestCase { assertEquals("Another Author", comment.getAuthor()); } - public void testDontLoostNewLines() throws Exception { + public void testDontLoostNewLines() { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx"); List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations(); CommentsTable ct = null; @@ -162,8 +165,8 @@ public class TestCommentsTable extends TestCase { assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); } - public void testExisting() throws Exception { - XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx"); + public void testExisting() { + XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx"); Sheet sheet1 = workbook.getSheetAt(0); Sheet sheet2 = workbook.getSheetAt(1); @@ -192,8 +195,8 @@ public class TestCommentsTable extends TestCase { assertEquals(2, cc7.getColumn()); } - public void testWriteRead() throws Exception { - XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx"); + public void testWriteRead() { + XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx"); XSSFSheet sheet1 = workbook.getSheetAt(0); XSSFSheet sheet2 = workbook.getSheetAt(1); @@ -239,8 +242,8 @@ public class TestCommentsTable extends TestCase { sheet1.getRow(4).getCell(2).getCellComment().getString().getString()); } - public void testReadWriteMultipleAuthors() throws Exception { - XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); + public void testReadWriteMultipleAuthors() { + XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); XSSFSheet sheet1 = workbook.getSheetAt(0); XSSFSheet sheet2 = workbook.getSheetAt(1); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java index 7adfdd0f5c..73ec1d005f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java @@ -53,7 +53,7 @@ public final class TestStylesTable extends TestCase { assertEquals(0, st._getNumberFormatSize()); } - public void testLoadExisting() throws Exception { + public void testLoadExisting() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile); assertNotNull(workbook.getStylesSource()); @@ -61,7 +61,7 @@ public final class TestStylesTable extends TestCase { doTestExisting(st); } - public void testLoadSaveLoad() throws Exception { + public void testLoadSaveLoad() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile); assertNotNull(workbook.getStylesSource()); @@ -125,7 +125,7 @@ public final class TestStylesTable extends TestCase { assertEquals(nf2, st.putNumberFormat("yyyy-mm-DD")); } - public void testPopulateExisting() throws Exception { + public void testPopulateExisting() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile); assertNotNull(workbook.getStylesSource()); @@ -138,7 +138,7 @@ public final class TestStylesTable extends TestCase { int nf2 = st.putNumberFormat("YYYY-mm-DD"); assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd")); - st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource(); + st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource(); assertEquals(11, st._getXfsSize()); assertEquals(1, st._getStyleXfsSize()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java index e6d6e97952..7c0d01b3a3 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -17,11 +17,13 @@ package org.apache.poi.xssf.usermodel; -import java.io.File; - -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.XSSFTestDataSamples; +import org.apache.poi.ss.usermodel.BaseTestHyperlink; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CreationHelper; +import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.XSSFITestDataProvider; +import org.apache.poi.xssf.XSSFTestDataSamples; public final class TestXSSFHyperlink extends BaseTestHyperlink { @Override @@ -38,7 +40,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { ); } - public void testLoadExisting() throws Exception { + public void testLoadExisting() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); assertEquals(3, workbook.getNumberOfSheets()); @@ -49,7 +51,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { doTestHyperlinkContents(sheet); } - public void testLoadSave() throws Exception { + public void testLoadSave() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); CreationHelper createHelper = workbook.getCreationHelper(); assertEquals(3, workbook.getNumberOfSheets()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index fa3d42d387..7bcf9c1cb4 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -51,7 +51,7 @@ public class TestXSSFSheet extends BaseTestSheet { baseTestGetSetMargin(new double[]{0.7, 0.7, 0.75, 0.75, 0.3, 0.3}); } - public void testExistingHeaderFooter() throws Exception { + public void testExistingHeaderFooter() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("45540_classic_Header.xlsx"); XSSFOddHeader hdr; XSSFOddFooter ftr; diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 3014bcf904..9db76c04f9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -168,8 +168,6 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { short i = workbook.getNumCellStyles(); //get default cellStyles assertEquals(1, i); - //get wrong value - assertNotSame(2, i); } public void testLoadSave() { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java index f55e7f5081..d25d22a483 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java @@ -17,11 +17,8 @@ package org.apache.poi.xwpf; -import java.io.File; - import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLProperties; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; @@ -32,7 +29,7 @@ public final class TestXWPFDocument extends TestCase { public void testContainsMainContentType() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); - OPCPackage pack = doc.getPackage(); + OPCPackage pack = doc.getPackage(); boolean found = false; for(PackagePart part : pack.getParts()) { @@ -55,14 +52,14 @@ public final class TestXWPFDocument extends TestCase { assertNotNull(xml.getStyle()); // Complex file - xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx"); + xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx"); assertNotNull(xml.getDocument()); assertNotNull(xml.getDocument().getBody()); assertNotNull(xml.getStyle()); } - public void testMetadataBasics() throws Exception { - XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx"); + public void testMetadataBasics() { + XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx"); assertNotNull(xml.getProperties().getCoreProperties()); assertNotNull(xml.getProperties().getExtendedProperties()); @@ -74,7 +71,7 @@ public final class TestXWPFDocument extends TestCase { assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); } - public void testMetadataComplex() throws Exception { + public void testMetadataComplex() { XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx"); assertNotNull(xml.getProperties().getCoreProperties()); assertNotNull(xml.getProperties().getExtendedProperties()); @@ -93,5 +90,4 @@ public final class TestXWPFDocument extends TestCase { assertNotNull(props); assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication()); } - } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java index cffdaec9ab..29b2a1643b 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java @@ -14,16 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.xwpf.extractor; -import java.io.File; -import java.io.IOException; +import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; -import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.XWPFTestDataSamples; - -import junit.framework.TestCase; +import org.apache.poi.xwpf.usermodel.XWPFDocument; /** * Tests for HXFWordExtractor @@ -33,7 +30,7 @@ public class TestXWPFWordExtractor extends TestCase { /** * Get text out of the simple file */ - public void testGetSimpleText() throws Exception { + public void testGetSimpleText() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -62,7 +59,7 @@ public class TestXWPFWordExtractor extends TestCase { /** * Tests getting the text out of a complex file */ - public void testGetComplexText() throws Exception { + public void testGetComplexText() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -94,7 +91,7 @@ public class TestXWPFWordExtractor extends TestCase { assertEquals(103, ps); } - public void testGetWithHyperlinks() throws Exception { + public void testGetWithHyperlinks() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -119,7 +116,7 @@ public class TestXWPFWordExtractor extends TestCase { ); } - public void testHeadersFooters() throws Exception { + public void testHeadersFooters() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ThreeColHeadFoot.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -162,7 +159,7 @@ public class TestXWPFWordExtractor extends TestCase { ); } - public void testFootnotes() throws Exception { + public void testFootnotes() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -170,14 +167,14 @@ public class TestXWPFWordExtractor extends TestCase { } - public void testTableFootnotes() throws Exception { + public void testTableFootnotes() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table_footnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); assertTrue(extractor.getText().contains("snoska")); } - public void testFormFootnotes() throws Exception { + public void testFormFootnotes() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("form_footnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); @@ -186,14 +183,14 @@ public class TestXWPFWordExtractor extends TestCase { assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase")); } - public void testEndnotes() throws Exception { + public void testEndnotes() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); assertTrue(extractor.getText().contains("XXX")); } - public void testInsertedDeletedText() throws Exception { + public void testInsertedDeletedText() { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("delins.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java index 13c04b0193..d30503b0a8 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java @@ -14,15 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.xwpf.model; -import java.io.File; +import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; -import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.XWPFTestDataSamples; - -import junit.framework.TestCase; +import org.apache.poi.xwpf.usermodel.XWPFDocument; /** * Tests for XWPF Header Footer Stuff @@ -35,15 +33,14 @@ public class TestXWPFHeaderFooterPolicy extends TestCase { private XWPFDocument oddEven; private XWPFDocument diffFirst; - protected void setUp() throws Exception { - super.setUp(); + protected void setUp() { noHeader = XWPFTestDataSamples.openSampleDocument("NoHeadFoot.docx"); - header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx"); - headerFooter = XWPFTestDataSamples.openSampleDocument("SimpleHeadThreeColFoot.docx"); - footer = XWPFTestDataSamples.openSampleDocument("FancyFoot.docx"); - oddEven = XWPFTestDataSamples.openSampleDocument("PageSpecificHeadFoot.docx"); - diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx"); + header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx"); + headerFooter = XWPFTestDataSamples.openSampleDocument("SimpleHeadThreeColFoot.docx"); + footer = XWPFTestDataSamples.openSampleDocument("FancyFoot.docx"); + oddEven = XWPFTestDataSamples.openSampleDocument("PageSpecificHeadFoot.docx"); + diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx"); } public void testPolicy() { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java index 478f622b2d..edd72ce295 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java @@ -14,42 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.xwpf.usermodel; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; -import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr; +import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; -public class TestXWPFHeader extends TestCase { - - public void testSimpleHeader() throws IOException { +public final class TestXWPFHeader extends TestCase { + + public void testSimpleHeader() { XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx"); XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); - - + + XWPFHeader header = policy.getDefaultHeader(); XWPFFooter footer = policy.getDefaultFooter(); assertNotNull(header); assertNotNull(footer); - + // TODO verify if the following is correct assertNull(header.toString()); - + } - + public void testSetHeader() throws IOException { XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); // no header is set (yet) @@ -57,17 +52,17 @@ public class TestXWPFHeader extends TestCase { assertNull(policy.getDefaultHeader()); assertNull(policy.getFirstPageHeader()); assertNull(policy.getDefaultFooter()); - + CTP ctP1 = CTP.Factory.newInstance(); CTR ctR1 = ctP1.addNewR(); CTText t = ctR1.addNewT(); - t.set("Paragraph in header"); - + t.setStringValue("Paragraph in header"); + CTP ctP2 = CTP.Factory.newInstance(); CTR ctR2 = ctP2.addNewR(); CTText t2 = ctR2.addNewT(); - t2.set("Second paragraph.. for footer"); - + t2.setStringValue("Second paragraph.. for footer"); + XWPFParagraph p1 = new XWPFParagraph(ctP1); XWPFParagraph[] pars = new XWPFParagraph[1]; pars[0] = p1; @@ -75,30 +70,29 @@ public class TestXWPFHeader extends TestCase { XWPFParagraph p2 = new XWPFParagraph(ctP2); XWPFParagraph[] pars2 = new XWPFParagraph[1]; pars2[0] = p2; - + // set a default header and test it is not null policy.createHeader(policy.DEFAULT, pars); policy.createHeader(policy.FIRST); policy.createFooter(policy.DEFAULT, pars2); - + assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getFirstPageHeader()); assertNotNull(policy.getDefaultFooter()); } - - public void testSetWatermark() throws IOException { + + public void testSetWatermark() { XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); // no header is set (yet) XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); assertNull(policy.getDefaultHeader()); assertNull(policy.getFirstPageHeader()); assertNull(policy.getDefaultFooter()); - + policy.createWatermark("DRAFT"); - + assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getFirstPageHeader()); assertNotNull(policy.getEvenPageHeader()); } - } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index 12405fb4a7..3c826ba255 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -14,14 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.xwpf.usermodel; -import java.io.File; import java.math.BigInteger; import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd; diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java index 73c3a03e70..f5cbb40011 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java @@ -45,7 +45,7 @@ public final class TestBlankFileRead extends TestCase { /** * Check if we can read the body of the blank message, we expect "". */ - public void testReadBody() throws Exception { + public void testReadBody() { try { mapiMessage.getTextBody(); } catch(ChunkNotFoundException exp) { @@ -102,8 +102,6 @@ public final class TestBlankFileRead extends TestCase { /** * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception */ public void testReadSubject() throws Exception { String obtained = mapiMessage.getSubject(); @@ -113,8 +111,6 @@ public final class TestBlankFileRead extends TestCase { /** * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception */ public void testReadConversationTopic() { try { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java index 2eb46a4291..61f72d5af7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java @@ -17,13 +17,9 @@ package org.apache.poi.hwpf; -import java.io.FileInputStream; - -import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.hwpf.model.FileInformationBlock; import org.apache.poi.poifs.filesystem.DocumentEntry; - -import org.apache.poi.hwpf.model.*; -import java.io.File; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; public final class HWPFDocFixture diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java index b750e52af8..0f71e22ad7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java @@ -23,38 +23,39 @@ import java.io.IOException; import junit.framework.TestCase; - -public abstract class HWPFTestCase - extends TestCase -{ - protected HWPFDocFixture _hWPFDocFixture; - - public HWPFTestCase() - { - } - - protected void setUp() throws Exception { - super.setUp(); - /**@todo verify the constructors*/ - _hWPFDocFixture = new HWPFDocFixture(this); - - _hWPFDocFixture.setUp(); - } - - protected void tearDown() throws Exception { - if(_hWPFDocFixture != null) { - _hWPFDocFixture.tearDown(); - } - - _hWPFDocFixture = null; - super.tearDown(); - } - - public HWPFDocument writeOutAndRead(HWPFDocument doc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - doc.write(baos); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - HWPFDocument newDoc = new HWPFDocument(bais); - return newDoc; - } +public abstract class HWPFTestCase extends TestCase { + protected HWPFDocFixture _hWPFDocFixture; + + protected HWPFTestCase() { + } + + protected void setUp() throws Exception { + super.setUp(); + /** @todo verify the constructors */ + _hWPFDocFixture = new HWPFDocFixture(this); + + _hWPFDocFixture.setUp(); + } + + protected void tearDown() throws Exception { + if (_hWPFDocFixture != null) { + _hWPFDocFixture.tearDown(); + } + + _hWPFDocFixture = null; + super.tearDown(); + } + + public HWPFDocument writeOutAndRead(HWPFDocument doc) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + HWPFDocument newDoc; + try { + doc.write(baos); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + newDoc = new HWPFDocument(bais); + } catch (IOException e) { + throw new RuntimeException(e); + } + return newDoc; + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java index 4cb88ae30b..ccc14ba76a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java @@ -55,7 +55,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test just opening the files */ - public void testOpen() throws Exception { + public void testOpen() { HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile); HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); } @@ -63,7 +63,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test that we have the right numbers of images in each file */ - public void testImageCount() throws Exception { + public void testImageCount() { HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile); HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); @@ -83,7 +83,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test that we have the right images in at least one file */ - public void testImageData() throws Exception { + public void testImageData() { HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); PicturesTable picB = docB.getPicturesTable(); List picturesB = picB.getAllPictures(); @@ -110,7 +110,7 @@ public final class TestHWPFPictures extends TestCase { /** * Test that compressed image data is correctly returned. */ - public void testCompressedImageData() throws Exception { + public void testCompressedImageData() { HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile); PicturesTable picC = docC.getPicturesTable(); List picturesC = picC.getAllPictures(); @@ -131,7 +131,7 @@ public final class TestHWPFPictures extends TestCase { * Pending the missing files being uploaded to * bug #44937 */ - public void BROKENtestEscherDrawing() throws Exception { + public void BROKENtestEscherDrawing() { HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile); List allPictures = docD.getPicturesTable().getAllPictures(); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java index 6aee79605b..43eb9b4870 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java @@ -93,7 +93,7 @@ public final class TestHWPFRangeParts extends TestCase { */ private HWPFDocument docUnicode; - public void setUp() throws Exception { + public void setUp() { docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc"); docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc"); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java index 559d95aacf..bda0866bb0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java @@ -52,50 +52,50 @@ public final class TestDifferentRoutes extends TestCase { private HWPFDocument doc; - protected void setUp() throws Exception { + protected void setUp() { doc = HWPFTestDataSamples.openSampleFile("test2.doc"); - } - - /** - * Test model based extraction - */ - public void testExtractFromModel() { - Range r = doc.getRange(); - - String[] text = new String[r.numParagraphs()]; - for(int i=0; i < r.numParagraphs(); i++) { - Paragraph p = r.getParagraph(i); - text[i] = p.text(); - } - - assertEquals(p_text.length, text.length); - for(int i=0; i<p_text.length; i++) { - assertEquals(p_text[i], text[i]); - } - } - - /** - * Test textPieces based extraction - */ - public void testExtractFromTextPieces() throws Exception { - StringBuffer textBuf = new StringBuffer(); - - Iterator textPieces = doc.getTextTable().getTextPieces().iterator(); - while (textPieces.hasNext()) { - TextPiece piece = (TextPiece) textPieces.next(); - - String encoding = "Cp1252"; - if (piece.isUnicode()) { - encoding = "UTF-16LE"; - } - String text = new String(piece.getRawBytes(), encoding); - textBuf.append(text); - } - - StringBuffer exp = new StringBuffer(); - for(int i=0; i<p_text.length; i++) { - exp.append(p_text[i]); - } - assertEquals(exp.toString(), textBuf.toString()); - } + } + + /** + * Test model based extraction + */ + public void testExtractFromModel() { + Range r = doc.getRange(); + + String[] text = new String[r.numParagraphs()]; + for (int i = 0; i < r.numParagraphs(); i++) { + Paragraph p = r.getParagraph(i); + text[i] = p.text(); + } + + assertEquals(p_text.length, text.length); + for (int i = 0; i < p_text.length; i++) { + assertEquals(p_text[i], text[i]); + } + } + + /** + * Test textPieces based extraction + */ + public void testExtractFromTextPieces() throws Exception { + StringBuffer textBuf = new StringBuffer(); + + Iterator textPieces = doc.getTextTable().getTextPieces().iterator(); + while (textPieces.hasNext()) { + TextPiece piece = (TextPiece) textPieces.next(); + + String encoding = "Cp1252"; + if (piece.isUnicode()) { + encoding = "UTF-16LE"; + } + String text = new String(piece.getRawBytes(), encoding); + textBuf.append(text); + } + + StringBuffer exp = new StringBuffer(); + for (int i = 0; i < p_text.length; i++) { + exp.append(p_text[i]); + } + assertEquals(exp.toString(), textBuf.toString()); + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java index 9d32badaf2..4f9c08634f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java @@ -61,10 +61,10 @@ public final class TestWordExtractor extends TestCase { private String filename4; // With unicode header and footer private String filename5; - // With footnote - private String filename6; + // With footnote + private String filename6; - protected void setUp() throws Exception { + protected void setUp() throws Exception { String pdirname = System.getProperty("POIFS.testdata.path"); String filename = "test2.doc"; @@ -72,7 +72,7 @@ public final class TestWordExtractor extends TestCase { filename3 = pdirname + "/excel_with_embeded.xls"; filename4 = "ThreeColHeadFoot.doc"; filename5 = "HeaderFooterUnicode.doc"; - filename6 = "footnote.doc"; + filename6 = "footnote.doc"; extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename)); extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2)); @@ -81,184 +81,160 @@ public final class TestWordExtractor extends TestCase { for(int i=0; i<p_text1.length; i++) { p_text1_block += p_text1[i]; } - } - - /** - * Test paragraph based extraction - */ - public void testExtractFromParagraphs() { - String[] text = extractor.getParagraphText(); - - assertEquals(p_text1.length, text.length); - for(int i=0; i<p_text1.length; i++) { - assertEquals(p_text1[i], text[i]); - } - - // On second one, should fall back - assertEquals(1, extractor2.getParagraphText().length); - } - - /** - * Test the paragraph -> flat extraction - */ - public void testGetText() { - assertEquals(p_text1_block, extractor.getText()); - - // On second one, should fall back to text piece - assertEquals(extractor2.getTextFromPieces(), extractor2.getText()); - } - - /** - * Test textPieces based extraction - */ - public void testExtractFromTextPieces() { - String text = extractor.getTextFromPieces(); - assertEquals(p_text1_block, text); - } - - - /** - * Test that we can get data from two different - * embeded word documents - * @throws Exception - */ - public void testExtractFromEmbeded() throws Exception { - POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(filename3)); - HWPFDocument doc; - WordExtractor extractor3; - - DirectoryNode dirA = (DirectoryNode) - fs.getRoot().getEntry("MBD0000A3B7"); - DirectoryNode dirB = (DirectoryNode) - fs.getRoot().getEntry("MBD0000A3B2"); - - // Should have WordDocument and 1Table - assertNotNull(dirA.getEntry("1Table")); - assertNotNull(dirA.getEntry("WordDocument")); - - assertNotNull(dirB.getEntry("1Table")); - assertNotNull(dirB.getEntry("WordDocument")); - - // Check each in turn - doc = new HWPFDocument(dirA, fs); - extractor3 = new WordExtractor(doc); - - assertNotNull(extractor3.getText()); - assertTrue(extractor3.getText().length() > 20); - assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", - extractor3.getText()); - assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle()); - assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject()); - - - doc = new HWPFDocument(dirB, fs); - extractor3 = new WordExtractor(doc); - - assertNotNull(extractor3.getText()); - assertTrue(extractor3.getText().length() > 20); - assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", - extractor3.getText()); - assertEquals("Sample Doc 2", extractor3.getSummaryInformation().getTitle()); - assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject()); - } - - public void testWithHeader() throws Exception { - // Non-unicode - HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4); - extractor = new WordExtractor(doc); - - assertEquals( - "First header column!\tMid header Right header!\n", - extractor.getHeaderText() - ); - - String text = extractor.getText(); - assertTrue( - text.indexOf("First header column!") > -1 - ); - - - // Unicode - doc = HWPFTestDataSamples.openSampleFile(filename5); - extractor = new WordExtractor(doc); - - assertEquals( - "This is a simple header, with a \u20ac euro symbol in it.\n\n", - extractor.getHeaderText() - ); - text = extractor.getText(); - assertTrue( - text.indexOf("This is a simple header") > -1 - ); - } - - public void testWithFooter() throws Exception { - // Non-unicode - HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4); - extractor = new WordExtractor(doc); - - assertEquals( - "Footer Left\tFooter Middle Footer Right\n", - extractor.getFooterText() - ); - - String text = extractor.getText(); - assertTrue( - text.indexOf("Footer Left") > -1 - ); - - - // Unicode - doc = HWPFTestDataSamples.openSampleFile(filename5); - extractor = new WordExtractor(doc); - - assertEquals( - "The footer, with Moli\u00e8re, has Unicode in it.\n", - extractor.getFooterText() - ); - text = extractor.getText(); - assertTrue( - text.indexOf("The footer, with") > -1 - ); - } - - public void testFootnote() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); - extractor = new WordExtractor(doc); - - String[] text = extractor.getFootnoteText(); - StringBuffer b = new StringBuffer(); - for (int i=0; i<text.length; i++) { - b.append(text[i]); - } - - assertTrue(b.toString().contains("TestFootnote")); - } - - public void testEndnote() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); - extractor = new WordExtractor(doc); - - String[] text = extractor.getEndnoteText(); - StringBuffer b = new StringBuffer(); - for (int i=0; i<text.length; i++) { - b.append(text[i]); - } - - assertTrue(b.toString().contains("TestEndnote")); - } - - public void testComments() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); - extractor = new WordExtractor(doc); - - String[] text = extractor.getCommentsText(); - StringBuffer b = new StringBuffer(); - for (int i=0; i<text.length; i++) { - b.append(text[i]); - } - - assertTrue(b.toString().contains("TestComment")); - } + } + + /** + * Test paragraph based extraction + */ + public void testExtractFromParagraphs() { + String[] text = extractor.getParagraphText(); + + assertEquals(p_text1.length, text.length); + for (int i = 0; i < p_text1.length; i++) { + assertEquals(p_text1[i], text[i]); + } + + // On second one, should fall back + assertEquals(1, extractor2.getParagraphText().length); + } + + /** + * Test the paragraph -> flat extraction + */ + public void testGetText() { + assertEquals(p_text1_block, extractor.getText()); + + // On second one, should fall back to text piece + assertEquals(extractor2.getTextFromPieces(), extractor2.getText()); + } + + /** + * Test textPieces based extraction + */ + public void testExtractFromTextPieces() { + String text = extractor.getTextFromPieces(); + assertEquals(p_text1_block, text); + } + + + /** + * Test that we can get data from two different + * embeded word documents + * @throws Exception + */ + public void testExtractFromEmbeded() throws Exception { + POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3)); + HWPFDocument doc; + WordExtractor extractor3; + + DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7"); + DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2"); + + // Should have WordDocument and 1Table + assertNotNull(dirA.getEntry("1Table")); + assertNotNull(dirA.getEntry("WordDocument")); + + assertNotNull(dirB.getEntry("1Table")); + assertNotNull(dirB.getEntry("WordDocument")); + + // Check each in turn + doc = new HWPFDocument(dirA, fs); + extractor3 = new WordExtractor(doc); + + assertNotNull(extractor3.getText()); + assertTrue(extractor3.getText().length() > 20); + assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractor3 + .getText()); + assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle()); + assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject()); + + doc = new HWPFDocument(dirB, fs); + extractor3 = new WordExtractor(doc); + + assertNotNull(extractor3.getText()); + assertTrue(extractor3.getText().length() > 20); + assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", + extractor3.getText()); + assertEquals("Sample Doc 2", extractor3.getSummaryInformation().getTitle()); + assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject()); + } + + public void testWithHeader() { + // Non-unicode + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4); + extractor = new WordExtractor(doc); + + assertEquals("First header column!\tMid header Right header!\n", extractor.getHeaderText()); + + String text = extractor.getText(); + assertTrue(text.indexOf("First header column!") > -1); + + // Unicode + doc = HWPFTestDataSamples.openSampleFile(filename5); + extractor = new WordExtractor(doc); + + assertEquals("This is a simple header, with a \u20ac euro symbol in it.\n\n", extractor + .getHeaderText()); + text = extractor.getText(); + assertTrue(text.indexOf("This is a simple header") > -1); + } + + public void testWithFooter() { + // Non-unicode + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4); + extractor = new WordExtractor(doc); + + assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor.getFooterText()); + + String text = extractor.getText(); + assertTrue(text.indexOf("Footer Left") > -1); + + // Unicode + doc = HWPFTestDataSamples.openSampleFile(filename5); + extractor = new WordExtractor(doc); + + assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\n", extractor + .getFooterText()); + text = extractor.getText(); + assertTrue(text.indexOf("The footer, with") > -1); + } + + public void testFootnote() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); + extractor = new WordExtractor(doc); + + String[] text = extractor.getFootnoteText(); + StringBuffer b = new StringBuffer(); + for (int i = 0; i < text.length; i++) { + b.append(text[i]); + } + + assertTrue(b.toString().contains("TestFootnote")); + } + + public void testEndnote() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); + extractor = new WordExtractor(doc); + + String[] text = extractor.getEndnoteText(); + StringBuffer b = new StringBuffer(); + for (int i = 0; i < text.length; i++) { + b.append(text[i]); + } + + assertTrue(b.toString().contains("TestEndnote")); + } + + public void testComments() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6); + extractor = new WordExtractor(doc); + + String[] text = extractor.getCommentsText(); + StringBuffer b = new StringBuffer(); + for (int i = 0; i < text.length; i++) { + b.append(text[i]); + } + + assertTrue(b.toString().contains("TestComment")); + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java index f657dc4858..860552cef2 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java @@ -17,9 +17,8 @@ package org.apache.poi.hwpf.extractor; -import java.io.FileInputStream; - import junit.framework.TestCase; + import org.apache.poi.hwpf.HWPFTestDataSamples; /** diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java index e4c09463ab..be231dad21 100755 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java @@ -25,42 +25,35 @@ import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; -public class TestBug46610 extends TestCase { - - public void testUtf() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_1.doc"); - - runExtract(doc); - } - - public void testUtf2() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_2.doc"); - - runExtract(doc); - } - - public void testExtraction() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_3.doc"); - - String text = runExtract(doc); - - assertTrue(text.contains("\u0421\u0412\u041e\u042e")); - } - - private String runExtract(HWPFDocument doc) { - StringBuffer out = new StringBuffer(); - - Range globalRange = doc.getRange(); - for (int i = 0; i < globalRange.numParagraphs(); i++) { - Paragraph p = globalRange.getParagraph(i); - out.append(p.text()); - out.append("\n"); - for (int j = 0; j < p.numCharacterRuns(); j++) { - CharacterRun characterRun = p.getCharacterRun(j); - characterRun.text(); - } - } - - return out.toString(); - } +public final class TestBug46610 extends TestCase { + + public void testUtf() { + runExtract("Bug46610_1.doc"); + } + + public void testUtf2() { + runExtract("Bug46610_2.doc"); + } + + public void testExtraction() { + String text = runExtract("Bug46610_3.doc"); + assertTrue(text.contains("\u0421\u0412\u041e\u042e")); + } + + private static String runExtract(String sampleName) { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName); + StringBuffer out = new StringBuffer(); + + Range globalRange = doc.getRange(); + for (int i = 0; i < globalRange.numParagraphs(); i++) { + Paragraph p = globalRange.getParagraph(i); + out.append(p.text()); + out.append("\n"); + for (int j = 0; j < p.numCharacterRuns(); j++) { + CharacterRun characterRun = p.getCharacterRun(j); + characterRun.text(); + } + } + return out.toString(); + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java index b4d9a7d620..ec9e2f9440 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java @@ -35,7 +35,7 @@ public final class TestHeaderStories extends TestCase { private HWPFDocument unicode; private HWPFDocument withFields; - protected void setUp() throws Exception { + protected void setUp() { none = HWPFTestDataSamples.openSampleFile("NoHeadFoot.doc"); header = HWPFTestDataSamples.openSampleFile("ThreeColHead.doc"); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java index 85580786db..4a0341619f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -35,7 +35,7 @@ public final class TestPictures extends TestCase { /** * two jpegs */ - public void testTwoImages() throws Exception { + public void testTwoImages() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc"); List pics = doc.getPicturesTable().getAllPictures(); @@ -59,7 +59,7 @@ public final class TestPictures extends TestCase { /** * pngs and jpegs */ - public void testDifferentImages() throws Exception { + public void testDifferentImages() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc"); List pics = doc.getPicturesTable().getAllPictures(); @@ -85,7 +85,7 @@ public final class TestPictures extends TestCase { /** * emf image, nice and simple */ - public void testEmfImage() throws Exception { + public void testEmfImage() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc"); List pics = doc.getPicturesTable().getAllPictures(); @@ -109,7 +109,7 @@ public final class TestPictures extends TestCase { /** * emf image, with a crazy offset */ - public void disabled_testEmfComplexImage() throws Exception { + public void disabled_testEmfComplexImage() { // Commenting out this test case temporarily. The file emf_2003_image does not contain any // pictures. Instead it has an office drawing object. Need to rewrite this test after @@ -136,11 +136,10 @@ public final class TestPictures extends TestCase { assertEquals(0x80000000l, LittleEndian.getUInt(pic.getRawContent())); } - public void testPicturesWithTable() throws Exception { + public void testPicturesWithTable() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc"); List pics = doc.getPicturesTable().getAllPictures(); assertEquals(pics.size(), 2); } - } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java index 41dd238f55..dbb02d4a0d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java @@ -30,46 +30,46 @@ import org.apache.poi.hwpf.model.StyleSheet; */ public final class TestProblems extends HWPFTestCase { - /** - * ListEntry passed no ListTable - */ - public void testListEntryNoListTable() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ListEntryNoListTable.doc"); - - Range r = doc.getRange(); - StyleSheet styleSheet = doc.getStyleSheet(); - for (int x = 0; x < r.numSections(); x++) { - Section s = r.getSection(x); - for (int y = 0; y < s.numParagraphs(); y++) { - Paragraph paragraph = s.getParagraph(y); - //System.out.println(paragraph.getCharacterRun(0).text()); - } - } - } + /** + * ListEntry passed no ListTable + */ + public void testListEntryNoListTable() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ListEntryNoListTable.doc"); + + Range r = doc.getRange(); + StyleSheet styleSheet = doc.getStyleSheet(); + for (int x = 0; x < r.numSections(); x++) { + Section s = r.getSection(x); + for (int y = 0; y < s.numParagraphs(); y++) { + Paragraph paragraph = s.getParagraph(y); + // System.out.println(paragraph.getCharacterRun(0).text()); + } + } + } /** * AIOOB for TableSprmUncompressor.unCompressTAPOperation */ - public void testSprmAIOOB() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc"); - - Range r = doc.getRange(); - StyleSheet styleSheet = doc.getStyleSheet(); - for (int x = 0; x < r.numSections(); x++) { - Section s = r.getSection(x); - for (int y = 0; y < s.numParagraphs(); y++) { - Paragraph paragraph = s.getParagraph(y); - //System.out.println(paragraph.getCharacterRun(0).text()); - } - } + public void testSprmAIOOB() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc"); + + Range r = doc.getRange(); + StyleSheet styleSheet = doc.getStyleSheet(); + for (int x = 0; x < r.numSections(); x++) { + Section s = r.getSection(x); + for (int y = 0; y < s.numParagraphs(); y++) { + Paragraph paragraph = s.getParagraph(y); + // System.out.println(paragraph.getCharacterRun(0).text()); + } + } } /** - * Test for TableCell not skipping the last paragraph. - * Bugs #45062 and #44292 + * Test for TableCell not skipping the last paragraph. Bugs #45062 and + * #44292 */ - public void testTableCellLastParagraph() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44292.doc"); + public void testTableCellLastParagraph() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44292.doc"); Range r = doc.getRange(); assertEquals(6, r.numParagraphs()); assertEquals(0, r.getStartOffset()); @@ -83,34 +83,34 @@ public final class TestProblems extends HWPFTestCase { // Get the table Table t = r.getTable(p); - //get the only row + // get the only row assertEquals(1, t.numRows()); TableRow row = t.getRow(0); - //get the first cell + // get the first cell TableCell cell = row.getCell(0); // First cell should have one paragraph assertEquals(1, cell.numParagraphs()); assertEquals("One paragraph is ok\7", cell.getParagraph(0).text()); - //get the second + // get the second cell = row.getCell(1); // Second cell should be detected as having two paragraphs assertEquals(2, cell.numParagraphs()); assertEquals("First para is ok\r", cell.getParagraph(0).text()); assertEquals("Second paragraph is skipped\7", cell.getParagraph(1).text()); - //get the last cell + // get the last cell cell = row.getCell(2); // Last cell should have one paragraph assertEquals(1, cell.numParagraphs()); assertEquals("One paragraph is ok\7", cell.getParagraph(0).text()); } - public void testRangeDelete() throws Exception { - HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug28627.doc"); + public void testRangeDelete() { + HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug28627.doc"); - Range range = doc.getRange(); + Range range = doc.getRange(); int numParagraphs = range.numParagraphs(); int totalLength = 0, deletedLength = 0; @@ -128,7 +128,7 @@ public final class TestProblems extends HWPFTestCase { // check the text length after deletion int newLength = 0; - range = doc.getRange(); + range = doc.getRange(); numParagraphs = range.numParagraphs(); for (int i = 0; i < numParagraphs; i++) { @@ -142,24 +142,23 @@ public final class TestProblems extends HWPFTestCase { } /** - * With an encrypted file, we should give a suitable - * exception, and not OOM + * With an encrypted file, we should give a suitable exception, and not OOM */ - public void testEncryptedFile() throws Exception { + public void testEncryptedFile() { try { HWPFTestDataSamples.openSampleFile("PasswordProtected.doc"); fail(); - } catch(EncryptedDocumentException e) { + } catch (EncryptedDocumentException e) { // Good } } - public void testWriteProperties() throws Exception { + public void testWriteProperties() { HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc"); assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor()); // Write and read HWPFDocument doc2 = writeOutAndRead(doc); - assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor()); + assertEquals("Nick Burch", doc2.getSummaryInformation().getAuthor()); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java index 289f2b80fa..f123a2018c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java @@ -53,15 +53,15 @@ public final class TestRangeDelete extends TestCase { /** * Test just opening the files */ - public void testOpen() throws Exception { + public void testOpen() { - HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + HWPFTestDataSamples.openSampleFile(illustrativeDocFile); } /** * Test (more "confirm" than test) that we have the general structure that we expect to have. */ - public void testDocStructure() throws Exception { + public void testDocStructure() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); Range range; @@ -126,7 +126,7 @@ public final class TestRangeDelete extends TestCase { /** * Test that we can delete text (one instance) from our Range with Unicode text. */ - public void testRangeDeleteOne() throws Exception { + public void testRangeDeleteOne() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); @@ -172,7 +172,7 @@ public final class TestRangeDelete extends TestCase { /** * Test that we can delete text (all instances of) from our Range with Unicode text. */ - public void testRangeDeleteAll() throws Exception { + public void testRangeDeleteAll() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java index 5b024daeff..f2e2ea3329 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java @@ -45,15 +45,15 @@ public final class TestRangeInsertion extends TestCase { /** * Test just opening the files */ - public void testOpen() throws Exception { + public void testOpen() { - HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + HWPFTestDataSamples.openSampleFile(illustrativeDocFile); } /** * Test (more "confirm" than test) that we have the general structure that we expect to have. */ - public void testDocStructure() throws Exception { + public void testDocStructure() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); @@ -81,11 +81,11 @@ public final class TestRangeInsertion extends TestCase { /** * Test that we can insert text in our CharacterRun with Unicode text. */ - public void testRangeInsertion() throws Exception { + public void testRangeInsertion() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); - /* + if (false) { // TODO - delete or resurrect this code Range range = daDoc.getRange(); Section section = range.getSection(0); Paragraph para = section.getParagraph(2); @@ -93,7 +93,7 @@ public final class TestRangeInsertion extends TestCase { para.getCharacterRun(2).text(); System.out.println(text); - */ + } Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc); range.insertBefore(textToInsert); @@ -118,6 +118,5 @@ public final class TestRangeInsertion extends TestCase { // System.out.println(text); assertEquals((textToInsert + originalText), text); - } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java index 315c033d06..df17b74ce3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java @@ -40,12 +40,12 @@ public final class TestRangeProperties extends TestCase { "The trick with this one is that it contains some Unicode based strings in it.\r" + "Firstly, some currency symbols:\r" + "\tGBP - \u00a3\r" + - "\tEUR - \u20ac\r" + - "Now, we\u2019ll have some French text, in bold and big:\r" + - "\tMoli\u00e8re\r" + - "And some normal French text:\r" + - "\tL'Avare ou l'\u00c9cole du mensonge\r" + - "That\u2019s it for page one\r" + "\tEUR - \u20ac\r" + + "Now, we\u2019ll have some French text, in bold and big:\r" + + "\tMoli\u00e8re\r" + + "And some normal French text:\r" + + "\tL'Avare ou l'\u00c9cole du mensonge\r" + + "That\u2019s it for page one\r" ; private static final String u_page_2 = "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r" @@ -65,7 +65,7 @@ public final class TestRangeProperties extends TestCase { private HWPFDocument u; private HWPFDocument a; - protected void setUp() throws Exception { + protected void setUp() { u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc"); a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc"); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java index 23ca51cda5..8303224bd9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java @@ -44,15 +44,15 @@ public final class TestRangeReplacement extends TestCase { /** * Test just opening the files */ - public void testOpen() throws Exception { + public void testOpen() { - HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); + HWPFTestDataSamples.openSampleFile(illustrativeDocFile); } /** * Test (more "confirm" than test) that we have the general structure that we expect to have. */ - public void testDocStructure() throws Exception { + public void testDocStructure() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); @@ -81,7 +81,7 @@ public final class TestRangeReplacement extends TestCase { /** * Test that we can replace text in our Range with Unicode text. */ - public void testRangeReplacementOne() throws Exception { + public void testRangeReplacementOne() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); @@ -114,7 +114,7 @@ public final class TestRangeReplacement extends TestCase { /** * Test that we can replace text in our Range with Unicode text. */ - public void testRangeReplacementAll() throws Exception { + public void testRangeReplacementAll() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); diff --git a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java index 2bdc3c08d2..3120f3cc0d 100644 --- a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java +++ b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java @@ -119,12 +119,12 @@ public final class TestHPSFPropertiesExtractor extends TestCase { assertTrue(fsText.indexOf("TITLE = Titel: \u00c4h") > -1); } - public void test42726() throws Exception { - HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls")); - String txt = ex.getText(); - assertTrue(txt.indexOf("PID_AUTHOR") != -1); - assertTrue(txt.indexOf("PID_EDITTIME") != -1); - assertTrue(txt.indexOf("PID_REVNUMBER") != -1); - assertTrue(txt.indexOf("PID_THUMBNAIL") != -1); - } + public void test42726() { + HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls")); + String txt = ex.getText(); + assertTrue(txt.indexOf("PID_AUTHOR") != -1); + assertTrue(txt.indexOf("PID_EDITTIME") != -1); + assertTrue(txt.indexOf("PID_REVNUMBER") != -1); + assertTrue(txt.indexOf("PID_THUMBNAIL") != -1); + } } diff --git a/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java b/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java index 4d0f3a72c5..cbe4e61cd9 100644 --- a/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java +++ b/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java @@ -19,14 +19,11 @@ package org.apache.poi.hssf; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.POIDataSamples; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder. @@ -37,22 +34,22 @@ public final class HSSFTestDataSamples extends POIDataSamples { private static final HSSFTestDataSamples _inst = new HSSFTestDataSamples("HSSF.testdata.path", "SampleSS.xls"); - private HSSFTestDataSamples(String dir, String classPathTestFile){ - super(dir, classPathTestFile); - } + private HSSFTestDataSamples(String dir, String classPathTestFile){ + super(dir, classPathTestFile); + } - public static POIDataSamples getInstance(){ - return _inst; - } + public static POIDataSamples getInstance(){ + return _inst; + } - public static InputStream openSampleFileStream(String sampleFileName) { - return _inst.openResourceAsStream(sampleFileName); - } - public static byte[] getTestDataFileContent(String fileName) { - return _inst.readFile(fileName); - } + public static InputStream openSampleFileStream(String sampleFileName) { + return _inst.openResourceAsStream(sampleFileName); + } + public static byte[] getTestDataFileContent(String fileName) { + return _inst.readFile(fileName); + } - public static HSSFWorkbook openSampleWorkbook(String sampleFileName) { + public static HSSFWorkbook openSampleWorkbook(String sampleFileName) { try { return new HSSFWorkbook(_inst.openResourceAsStream(sampleFileName)); } catch (IOException e) { @@ -75,5 +72,4 @@ public final class HSSFTestDataSamples extends POIDataSamples { throw new RuntimeException(e); } } - } |