]> source.dussan.org Git - poi.git/commitdiff
fixing compiler warnings - unused imports, declared exceptions not thrown
authorJosh Micich <josh@apache.org>
Sat, 22 Aug 2009 05:50:32 +0000 (05:50 +0000)
committerJosh Micich <josh@apache.org>
Sat, 22 Aug 2009 05:50:32 +0000 (05:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@806789 13f79535-47bb-0310-9956-ffa450edef68

32 files changed:
src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java
src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java
src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java
src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java
src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java
src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java

index 480a71ad9b34a42f501f7c5a7c8e708cedfd06e8..47fe05ed91b05b88319dcbee255942d0b340e81a 100644 (file)
    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) {
index 3f66ee5391629cb77f0497000a5574284971b390..b3c4182d5997ab927150de5dd375f93cf0256209 100644 (file)
    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);
        }
 }
index 3a3dc27d72491f57bb8d5041d4c6c2cfbfaad947..ba9cfe92afda8c450b33f6ab4a538133ecf9041b 100755 (executable)
   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");
index 7e6281e757894533398a23181277695249bd3dc1..0ace7c3f63e9eca9054bcaad54cc2469ce47cffa 100644 (file)
 
 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}
index 14dde090e2e903be7b5077afaf76f33a0eb9f767..6555d65938e65b87b483042b831cffc939254d2a 100644 (file)
@@ -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);
 
index 7adfdd0f5cf8e36f5aca961fee3cfcad637a9896..73ec1d005ffb7900991b0714f27a41d70967909e 100644 (file)
@@ -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());
index e6d6e979523965666a73fb4cd08777a7b14801c5..7c0d01b3a35ae94d50eb170005422cd5cccd307e 100644 (file)
 
 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());
index fa3d42d3873ff5385dfe2d7f751a1c732cd77b74..7bcf9c1cb4bb7f3a7329e1bf6c0dc633d9792f6a 100644 (file)
@@ -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;
index 3014bcf9047f810579f5f76bc7176e3c0766ce43..9db76c04f908f07e7e1b710c52f9f1515a151e9c 100644 (file)
@@ -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() {
index f55e7f5081542d683ddff24eba04db8d526482fa..d25d22a48390709c372f4d9be0e503e480009112 100644 (file)
 
 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());
        }
-
 }
index cffdaec9ab5b3ed5b41ccce0267ef137e42c1dc5..29b2a1643b0e97d7e0221a66dcfaab5b195e2e84 100644 (file)
    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);
 
index 13c04b0193a619a9305922be199c9759d3cba01e..d30503b0a865b1366d99d1f20f0fd3eca4879812 100644 (file)
    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() {
index 478f622b2d4251b02a295f57dc1990335e8d3ad7..edd72ce2958ac928d6b9a4a37ebabe4c70e40d62 100644 (file)
    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());
        }
-
 }
index 12405fb4a7ad76b1dd25f1a139b4d36a02cc9dd0..3c826ba255d95bf1495c5546247c18095ac3329a 100644 (file)
    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;
index 73c3a03e70a1a21cbc7cdc6eda10495a1bcc589b..f5cbb40011eb0c7b7d5a981c8ad2ea0929a7b1a5 100644 (file)
@@ -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 {
index 2eb46a4291bc47efbf19cc3da42408b6828eb80c..61f72d5af7619a31d06643e93c6e08551d78f713 100644 (file)
 
 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
index b750e52af81db1b927a93d995edee099f2937183..0f71e22ad74623c9ec9a820391c4efba74946009 100644 (file)
@@ -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;
+       }
 }
index 4cb88ae30b8bb32b3d4e236ae6e4276ec2d7b3ee..ccc14ba76ad2dcef0cd2c1cc36764c5362198097 100644 (file)
@@ -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();
 
index 6aee79605b8a1d13a6c7de79acf5a528f189d8b5..43eb9b4870a4655ed0b276addb37c49601a09266 100644 (file)
@@ -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");
        }
index 559d95aacf1628b1fac09f7df04041d19fb3a8a7..bda0866bb0846007a6255e43ec453b6c9f9ff18d 100644 (file)
@@ -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());
+       }
 }
index 9d32badaf2c60ebe0768ecd5b7e2fab48748fe21..4f9c08634f5cf8fce3130b1068d9ecbe08ce31ca 100644 (file)
@@ -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"));
+       }
 }
index f657dc48583afba8a48f8bb60325aa3c8a352cca..860552cef22400e0c24317fc765fba34a632be73 100644 (file)
@@ -17,9 +17,8 @@
 
 package org.apache.poi.hwpf.extractor;
 
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
+
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
index e4c09463ab4f0a2db31076cc0c9fcbc4ebb74256..be231dad219bc7ebf739a1b66394c4b081502b51 100755 (executable)
@@ -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();
+       }
 }
index b4d9a7d62000b7474aa695f8ee22eb8a278d19e0..ec9e2f9440899feb9d9aad6e41915d619e811dda 100644 (file)
@@ -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");
index 85580786db67cc4e404f2579bc3fd24e8ac2a1a9..4a0341619fbbebdd73cd9291429363b7ef6a4336 100644 (file)
@@ -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);
        }
-
 }
index 41dd238f5516e41a728892d6a1df9c649b6f173b..dbb02d4a0d6d38520220e55cfdb9be34986fc76d 100644 (file)
@@ -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());
        }
 }
index 289f2b80faa264fbb07ff444f367cb553c50d032..f123a2018c907cf8dbf3d51c0881ed4db8946366 100644 (file)
@@ -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);
 
index 5b024daeff48a7120bc59d2696cfbc06c8d7fe82..f2e2ea3329299f301b11333073199d5d5d34c166 100644 (file)
@@ -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);
-
        }
 }
index 315c033d06e265005f9d1cbbb66c1c17a3bf51c6..df17b74ce39c7abece22f427da8290b423aa19da 100644 (file)
@@ -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");
        }
index 23ca51cda52442319d867690d61cc03a35f2b4b8..8303224bd921c5c754f47621f9763684b4e6a4b1 100644 (file)
@@ -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);
 
index 2bdc3c08d2207a21b61f2fda43ddb14520c5ada4..3120f3cc0d9eda6b41baf650c19acc956b686228 100644 (file)
@@ -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);
+       }
 }
index 4d0f3a72c52144da4e184cbc3b777e1c9fc439f6..cbe4e61cd9751b60159d78ca2b3ddd97fcf654c2 100644 (file)
@@ -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);
                }
        }
-
 }