Fix HPBF generics warnings, and add a NPOIFS check to the HPBF tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1085495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-03-25 18:03:18 +00:00
parent 27a258e581
commit 7499f96145
2 changed files with 57 additions and 49 deletions

View File

@ -41,7 +41,7 @@ public abstract class EscherPart extends HPBFPart {
DefaultEscherRecordFactory erf =
new DefaultEscherRecordFactory();
ArrayList ec = new ArrayList();
ArrayList<EscherRecord> ec = new ArrayList<EscherRecord>();
int left = data.length;
while(left > 0) {
EscherRecord er = erf.createRecord(data, 0);
@ -51,8 +51,7 @@ public abstract class EscherPart extends HPBFPart {
ec.add(er);
}
records = (EscherRecord[])
ec.toArray(new EscherRecord[ec.size()]);
records = ec.toArray(new EscherRecord[ec.size()]);
}
public EscherRecord[] getEscherRecords() {

View File

@ -18,40 +18,18 @@
package org.apache.poi.hpbf.extractor;
import java.io.File;
import java.io.FileInputStream;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hpbf.HPBFDocument;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
public final class TestPublisherTextExtractor extends TestCase {
private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
public void testBasics() throws Exception {
HPBFDocument doc = new HPBFDocument(
_samples.openResourceAsStream("Sample.pub")
);
PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
ext.getText();
ext = new PublisherTextExtractor(
_samples.openResourceAsStream("Simple.pub")
);
ext.getText();
}
public void testContents() throws Exception {
HPBFDocument doc = new HPBFDocument(
_samples.openResourceAsStream("Sample.pub")
);
PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
String text = ext.getText();
assertEquals(
private static final String SAMPLE_TEXT =
"This is some text on the first page\n" +
"It\u2019s in times new roman, font size 10, all normal\n" +
"" +
@ -75,25 +53,56 @@ public final class TestPublisherTextExtractor extends TestCase {
"More text, more hyperlinks\n" +
"email link\n" +
"Final hyperlink\n" +
"Within doc to page 1\n"
, text
"Within doc to page 1\n";
private static final String SIMPLE_TEXT =
"0123456789\n" +
"0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef\n" +
"0123456789\n" +
"0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef0123456789abcdef\n";
public void testBasics() throws Exception {
HPBFDocument doc = new HPBFDocument(
_samples.openResourceAsStream("Sample.pub")
);
// Now a simpler one
PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
ext.getText();
ext = new PublisherTextExtractor(
_samples.openResourceAsStream("Simple.pub")
);
text = ext.getText();
assertEquals(
"0123456789\n" +
"0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef\n" +
"0123456789\n" +
"0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef\n" +
"0123456789abcdef0123456789abcdef0123456789abcdef\n"
, text
ext.getText();
}
public void testContents() throws Exception {
PublisherTextExtractor ext;
File sample = _samples.getFile("Sample.pub");
File simple = _samples.getFile("Simple.pub");
// Check this complicated file using POIFS
HPBFDocument docOPOIFS = new HPBFDocument(
new FileInputStream(sample)
);
ext = new PublisherTextExtractor(docOPOIFS);
assertEquals( SAMPLE_TEXT, ext.getText() );
// And with NPOIFS
HPBFDocument docNPOIFS = new HPBFDocument(
new NPOIFSFileSystem(sample)
);
ext = new PublisherTextExtractor(docNPOIFS);
assertEquals( SAMPLE_TEXT, ext.getText() );
// Now a simpler file
ext = new PublisherTextExtractor(
new FileInputStream(simple)
);
assertEquals( SIMPLE_TEXT, ext.getText() );
}
/**