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
This commit is contained in:
Josh Micich 2009-08-22 05:50:32 +00:00
parent 32ea85bbfd
commit 9ca061617c
32 changed files with 443 additions and 510 deletions

View File

@ -14,12 +14,9 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi;
import java.io.IOException;
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;
@ -42,7 +39,7 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
* working on.
*/
public POIXMLPropertiesTextExtractor(POIXMLTextExtractor otherExtractor) {
super(otherExtractor.document);
super(otherExtractor.getDocument());
}
/**
@ -51,7 +48,7 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
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");
@ -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");
@ -109,7 +106,7 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
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++) {

View File

@ -14,17 +14,16 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi;
import java.io.IOException;
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
@ -32,33 +31,33 @@ public abstract class POIXMLTextExtractor extends POITextExtractor {
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
*/
public POIXMLDocument getDocument(){
return document;
public final POIXMLDocument getDocument(){
return _document;
}
@ -67,6 +66,6 @@ public abstract class POIXMLTextExtractor extends POITextExtractor {
* document properties metadata, such as title and author.
*/
public POIXMLPropertiesTextExtractor getMetadataTextExtractor() {
return new POIXMLPropertiesTextExtractor(document);
return new POIXMLPropertiesTextExtractor(_document);
}
}

View File

@ -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");

View File

@ -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.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.util.IOUtils;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
/**
* Tests for {@link XSSFReader}

View 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);

View 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());

View File

@ -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());

View 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;

View 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() {

View File

@ -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());
}
}

View File

@ -14,17 +14,14 @@
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 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.XWPFTestDataSamples;
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);

View File

@ -14,16 +14,14 @@
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 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.XWPFTestDataSamples;
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() {

View File

@ -14,27 +14,22 @@
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 final class TestXWPFHeader extends TestCase {
public void testSimpleHeader() throws IOException {
public void testSimpleHeader() {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
@ -61,12 +56,12 @@ public class TestXWPFHeader extends TestCase {
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];
@ -86,7 +81,7 @@ public class TestXWPFHeader extends TestCase {
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();
@ -100,5 +95,4 @@ public class TestXWPFHeader extends TestCase {
assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getEvenPageHeader());
}
}

View File

@ -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;

View 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 {

View File

@ -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

View File

@ -23,38 +23,39 @@ import java.io.IOException;
import junit.framework.TestCase;
public abstract class HWPFTestCase extends TestCase {
protected HWPFDocFixture _hWPFDocFixture;
public abstract class HWPFTestCase
extends TestCase
{
protected HWPFDocFixture _hWPFDocFixture;
protected HWPFTestCase() {
}
public HWPFTestCase()
{
}
protected void setUp() throws Exception {
super.setUp();
/** @todo verify the constructors */
_hWPFDocFixture = new HWPFDocFixture(this);
protected void setUp() throws Exception {
super.setUp();
/**@todo verify the constructors*/
_hWPFDocFixture = new HWPFDocFixture(this);
_hWPFDocFixture.setUp();
}
_hWPFDocFixture.setUp();
}
protected void tearDown() throws Exception {
if (_hWPFDocFixture != null) {
_hWPFDocFixture.tearDown();
}
protected void tearDown() throws Exception {
if(_hWPFDocFixture != null) {
_hWPFDocFixture.tearDown();
}
_hWPFDocFixture = null;
super.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 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;
}
}

View 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();

View 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");
}

View 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();
/**
* 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();
}
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]);
}
}
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();
/**
* 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();
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);
}
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());
}
StringBuffer exp = new StringBuffer();
for (int i = 0; i < p_text.length; i++) {
exp.append(p_text[i]);
}
assertEquals(exp.toString(), textBuf.toString());
}
}

View 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();
/**
* 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]);
}
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);
}
// 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());
/**
* 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());
}
// 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 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;
/**
* 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");
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"));
// Should have WordDocument and 1Table
assertNotNull(dirA.getEntry("1Table"));
assertNotNull(dirA.getEntry("WordDocument"));
assertNotNull(dirB.getEntry("1Table"));
assertNotNull(dirB.getEntry("WordDocument"));
assertNotNull(dirB.getEntry("1Table"));
assertNotNull(dirB.getEntry("WordDocument"));
// Check each in turn
doc = new HWPFDocument(dirA, fs);
extractor3 = new WordExtractor(doc);
// 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());
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);
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());
}
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);
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());
assertEquals(
"First header column!\tMid header Right header!\n",
extractor.getHeaderText()
);
String text = extractor.getText();
assertTrue(text.indexOf("First header column!") > -1);
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);
}
// Unicode
doc = HWPFTestDataSamples.openSampleFile(filename5);
extractor = new WordExtractor(doc);
public void testWithFooter() {
// Non-unicode
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
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
);
}
assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor.getFooterText());
public void testWithFooter() throws Exception {
// Non-unicode
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
extractor = new WordExtractor(doc);
String text = extractor.getText();
assertTrue(text.indexOf("Footer Left") > -1);
assertEquals(
"Footer Left\tFooter Middle Footer Right\n",
extractor.getFooterText()
);
// Unicode
doc = HWPFTestDataSamples.openSampleFile(filename5);
extractor = new WordExtractor(doc);
String text = extractor.getText();
assertTrue(
text.indexOf("Footer Left") > -1
);
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);
// Unicode
doc = HWPFTestDataSamples.openSampleFile(filename5);
extractor = new WordExtractor(doc);
String[] text = extractor.getFootnoteText();
StringBuffer b = new StringBuffer();
for (int i = 0; i < text.length; i++) {
b.append(text[i]);
}
assertEquals(
"The footer, with Moli\u00e8re, has Unicode in it.\n",
extractor.getFooterText()
);
text = extractor.getText();
assertTrue(
text.indexOf("The footer, with") > -1
);
}
assertTrue(b.toString().contains("TestFootnote"));
}
public void testFootnote() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
extractor = new WordExtractor(doc);
public void testEndnote() {
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]);
}
String[] text = extractor.getEndnoteText();
StringBuffer b = new StringBuffer();
for (int i = 0; i < text.length; i++) {
b.append(text[i]);
}
assertTrue(b.toString().contains("TestFootnote"));
}
assertTrue(b.toString().contains("TestEndnote"));
}
public void testEndnote() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
extractor = new WordExtractor(doc);
public void testComments() {
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]);
}
String[] text = extractor.getCommentsText();
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"));
}
assertTrue(b.toString().contains("TestComment"));
}
}

View 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;
/**

View File

@ -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 final class TestBug46610 extends TestCase {
public void testUtf() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_1.doc");
public void testUtf() {
runExtract("Bug46610_1.doc");
}
runExtract(doc);
}
public void testUtf2() {
runExtract("Bug46610_2.doc");
}
public void testUtf2() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_2.doc");
public void testExtraction() {
String text = runExtract("Bug46610_3.doc");
assertTrue(text.contains("\u0421\u0412\u041e\u042e"));
}
runExtract(doc);
}
private static String runExtract(String sampleName) {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
StringBuffer out = new StringBuffer();
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();
}
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();
}
}

View 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");

View 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);
}
}

View 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");
/**
* 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());
}
}
}
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");
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());
}
}
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());
}
}

View 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);

View 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);
}
}

View 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");
}

View 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);

View 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);
}
}

View 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);
}
}
}