diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java index 332642f69a..b07c8c51bc 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java @@ -32,18 +32,14 @@ import org.apache.poi.openxml4j.opc.TargetMode; /** * Test Open Packaging Convention package model compliance. - * + * * M1.11 : A package implementer shall neither create nor recognize a part with * a part name derived from another part name by appending segments to it. - * + * * @author Julien Chable */ public class TestOPCCompliancePackageModel extends TestCase { - public TestOPCCompliancePackageModel(String name) { - super(name); - } - /** * A package implementer shall neither create nor recognize a part with a * part name derived from another part name by appending segments to it. @@ -135,7 +131,7 @@ public class TestOPCCompliancePackageModel extends TestCase { /** * Try to add a relationship to a relationship part. - * + * * Check rule M1.25: The Relationships part shall not have relationships to * any other part. Package implementers shall enforce this requirement upon * the attempt to create such a relationship and shall treat any such diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java index 4548080bab..c7db283942 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java @@ -79,10 +79,6 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; */ public final class TestOPCCompliancePartName extends TestCase { - public TestOPCCompliancePartName(String name) { - super(name); - } - /** * Test some common invalid names. * diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java index 567cd014ea..f02cfb4e47 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java @@ -28,111 +28,110 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.openxml4j.opc.OPCPackage; /** - * Tests for XSSFReader + * Tests for {@link XSSFReader} */ -public class TestXSSFReader extends TestCase { +public final class TestXSSFReader extends TestCase { private String dirName; - - public TestXSSFReader(String name) { - super(name); - + + @Override + protected void setUp() { + dirName = System.getProperty("HSSF.testdata.path"); assertNotNull(dirName); assertTrue( (new File(dirName)).exists() ); - + // Use system out logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.SystemOutLogger" - ); + System.setProperty( + "org.apache.poi.util.POILogger", + "org.apache.poi.util.SystemOutLogger" + ); } - - public void testGetBits() throws Exception { - File f = new File(dirName, "SampleSS.xlsx"); - OPCPackage pkg = OPCPackage.open(f.toString()); - - XSSFReader r = new XSSFReader(pkg); - - assertNotNull(r.getWorkbookData()); - assertNotNull(r.getSharedStringsData()); - assertNotNull(r.getStylesData()); - - assertNotNull(r.getSharedStringsTable()); - assertNotNull(r.getStylesTable()); - } - - public void testStyles() throws Exception { - File f = new File(dirName, "SampleSS.xlsx"); - OPCPackage pkg = OPCPackage.open(f.toString()); - - XSSFReader r = new XSSFReader(pkg); - - assertEquals(3, r.getStylesTable().getFonts().size()); - assertEquals(0, r.getStylesTable()._getNumberFormatSize()); - } - - public void testStrings() throws Exception { - File f = new File(dirName, "SampleSS.xlsx"); - OPCPackage pkg = OPCPackage.open(f.toString()); - - XSSFReader r = new XSSFReader(pkg); - - assertEquals(11, r.getSharedStringsTable().getItems().size()); - assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString()); - } - - public void testSheets() throws Exception { - File f = new File(dirName, "SampleSS.xlsx"); - OPCPackage pkg = OPCPackage.open(f.toString()); - - XSSFReader r = new XSSFReader(pkg); - byte[] data = new byte[4096]; - - // By r:id - assertNotNull(r.getSheet("rId2")); - int read = IOUtils.readFully(r.getSheet("rId2"), data); - assertEquals(974, read); - - // All - Iterator it = r.getSheetsData(); - - int count = 0; - while(it.hasNext()) { - count++; - InputStream inp = it.next(); - assertNotNull(inp); - read = IOUtils.readFully(inp, data); - inp.close(); - - assertTrue(read > 400); - assertTrue(read < 1500); - } - assertEquals(3, count); - } - /** - * Check that the sheet iterator returns sheets in the logical order - * (as they are defined in the workbook.xml) - */ - public void testOrderOfSheets() throws Exception { - File f = new File(dirName, "reordered_sheets.xlsx"); - OPCPackage pkg = OPCPackage.open(f.toString()); + public void testGetBits() throws Exception { + File f = new File(dirName, "SampleSS.xlsx"); + OPCPackage pkg = OPCPackage.open(f.toString()); - XSSFReader r = new XSSFReader(pkg); + XSSFReader r = new XSSFReader(pkg); - String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"}; - XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData(); + assertNotNull(r.getWorkbookData()); + assertNotNull(r.getSharedStringsData()); + assertNotNull(r.getStylesData()); - int count = 0; - while(it.hasNext()) { - InputStream inp = it.next(); - assertNotNull(inp); - inp.close(); + assertNotNull(r.getSharedStringsTable()); + assertNotNull(r.getStylesTable()); + } - assertEquals(sheetNames[count], it.getSheetName()); - count++; - } - assertEquals(4, count); + public void testStyles() throws Exception { + File f = new File(dirName, "SampleSS.xlsx"); + OPCPackage pkg = OPCPackage.open(f.toString()); - } + XSSFReader r = new XSSFReader(pkg); + + assertEquals(3, r.getStylesTable().getFonts().size()); + assertEquals(0, r.getStylesTable()._getNumberFormatSize()); + } + + public void testStrings() throws Exception { + File f = new File(dirName, "SampleSS.xlsx"); + OPCPackage pkg = OPCPackage.open(f.toString()); + + XSSFReader r = new XSSFReader(pkg); + + assertEquals(11, r.getSharedStringsTable().getItems().size()); + assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString()); + } + + public void testSheets() throws Exception { + File f = new File(dirName, "SampleSS.xlsx"); + OPCPackage pkg = OPCPackage.open(f.toString()); + + XSSFReader r = new XSSFReader(pkg); + byte[] data = new byte[4096]; + + // By r:id + assertNotNull(r.getSheet("rId2")); + int read = IOUtils.readFully(r.getSheet("rId2"), data); + assertEquals(974, read); + + // All + Iterator it = r.getSheetsData(); + + int count = 0; + while(it.hasNext()) { + count++; + InputStream inp = it.next(); + assertNotNull(inp); + read = IOUtils.readFully(inp, data); + inp.close(); + + assertTrue(read > 400); + assertTrue(read < 1500); + } + assertEquals(3, count); + } + + /** + * Check that the sheet iterator returns sheets in the logical order + * (as they are defined in the workbook.xml) + */ + public void testOrderOfSheets() throws Exception { + File f = new File(dirName, "reordered_sheets.xlsx"); + OPCPackage pkg = OPCPackage.open(f.toString()); + + XSSFReader r = new XSSFReader(pkg); + + String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"}; + XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData(); + + int count = 0; + while(it.hasNext()) { + InputStream inp = it.next(); + assertNotNull(inp); + inp.close(); + + assertEquals(sheetNames[count], it.getSheetName()); + count++; + } + assertEquals(4, count); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java index f1ebf5f65d..19aeabbec5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java @@ -23,9 +23,8 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.XSSFTestDataSamples; public final class TestXSSFFormulaEvaluation extends TestCase { - public TestXSSFFormulaEvaluation(String name) { - super(name); - + @Override + protected void setUp() { // Use system out logger System.setProperty( "org.apache.poi.util.POILogger", diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java index a256b192ee..28ee4fd689 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -27,31 +27,26 @@ import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.XSSFTestDataSamples; -public class TestXSSFHyperlink extends TestCase { - public TestXSSFHyperlink(String name) { - super(name); - +public final class TestXSSFHyperlink extends TestCase { + @Override + protected void setUp() { // Use system out logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.SystemOutLogger" - ); + System.setProperty( + "org.apache.poi.util.POILogger", + "org.apache.poi.util.SystemOutLogger" + ); } - - public void testAddNew() throws Exception { - - } - public void testLoadExisting() throws Exception { + public void testLoadExisting() throws Exception { File xml = new File( System.getProperty("HSSF.testdata.path") + File.separator + "WithMoreVariousData.xlsx" ); assertTrue(xml.exists()); - + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); assertEquals(3, workbook.getNumberOfSheets()); - + XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0); // Check the hyperlinks @@ -59,13 +54,13 @@ public class TestXSSFHyperlink extends TestCase { doTestHyperlinkContents(sheet); } - public void testLoadSave() throws Exception { + public void testLoadSave() throws Exception { File xml = new File( System.getProperty("HSSF.testdata.path") + File.separator + "WithMoreVariousData.xlsx" ); assertTrue(xml.exists()); - + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); CreationHelper createHelper = workbook.getCreationHelper(); assertEquals(3, workbook.getNumberOfSheets()); @@ -74,8 +69,8 @@ public class TestXSSFHyperlink extends TestCase { // Check hyperlinks assertEquals(4, sheet.getNumHyperlinks()); doTestHyperlinkContents(sheet); - - + + // Write out, and check // Load up again, check all links still there @@ -84,95 +79,95 @@ public class TestXSSFHyperlink extends TestCase { assertNotNull(wb2.getSheetAt(0)); assertNotNull(wb2.getSheetAt(1)); assertNotNull(wb2.getSheetAt(2)); - + sheet = (XSSFSheet)wb2.getSheetAt(0); - + // Check hyperlinks again assertEquals(4, sheet.getNumHyperlinks()); doTestHyperlinkContents(sheet); - - + + // Add one more, and re-check Row r17 = sheet.createRow(17); Cell r17c = r17.createCell(2); - + Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL); hyperlink.setAddress("http://poi.apache.org/spreadsheet/"); hyperlink.setLabel("POI SS Link"); r17c.setHyperlink(hyperlink); - + assertEquals(5, sheet.getNumHyperlinks()); doTestHyperlinkContents(sheet); - - assertEquals(Hyperlink.LINK_URL, + + assertEquals(Hyperlink.LINK_URL, sheet.getRow(17).getCell(2).getHyperlink().getType()); - assertEquals("POI SS Link", + assertEquals("POI SS Link", sheet.getRow(17).getCell(2).getHyperlink().getLabel()); - assertEquals("http://poi.apache.org/spreadsheet/", + assertEquals("http://poi.apache.org/spreadsheet/", sheet.getRow(17).getCell(2).getHyperlink().getAddress()); - - + + // Save and re-load once more - XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2); + XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2); assertEquals(3, wb3.getNumberOfSheets()); assertNotNull(wb3.getSheetAt(0)); assertNotNull(wb3.getSheetAt(1)); assertNotNull(wb3.getSheetAt(2)); - + sheet = wb3.getSheetAt(0); - + assertEquals(5, sheet.getNumHyperlinks()); doTestHyperlinkContents(sheet); - - assertEquals(Hyperlink.LINK_URL, - sheet.getRow(17).getCell(2).getHyperlink().getType()); - assertEquals("POI SS Link", - sheet.getRow(17).getCell(2).getHyperlink().getLabel()); - assertEquals("http://poi.apache.org/spreadsheet/", - sheet.getRow(17).getCell(2).getHyperlink().getAddress()); - } - /** - * Only for WithMoreVariousData.xlsx ! - */ - private void doTestHyperlinkContents(XSSFSheet sheet) { + assertEquals(Hyperlink.LINK_URL, + sheet.getRow(17).getCell(2).getHyperlink().getType()); + assertEquals("POI SS Link", + sheet.getRow(17).getCell(2).getHyperlink().getLabel()); + assertEquals("http://poi.apache.org/spreadsheet/", + sheet.getRow(17).getCell(2).getHyperlink().getAddress()); + } + + /** + * Only for WithMoreVariousData.xlsx ! + */ + private void doTestHyperlinkContents(XSSFSheet sheet) { assertNotNull(sheet.getRow(3).getCell(2).getHyperlink()); assertNotNull(sheet.getRow(14).getCell(2).getHyperlink()); assertNotNull(sheet.getRow(15).getCell(2).getHyperlink()); assertNotNull(sheet.getRow(16).getCell(2).getHyperlink()); - + // First is a link to poi - assertEquals(Hyperlink.LINK_URL, + assertEquals(Hyperlink.LINK_URL, sheet.getRow(3).getCell(2).getHyperlink().getType()); - assertEquals(null, + assertEquals(null, sheet.getRow(3).getCell(2).getHyperlink().getLabel()); - assertEquals("http://poi.apache.org/", + assertEquals("http://poi.apache.org/", sheet.getRow(3).getCell(2).getHyperlink().getAddress()); - + // Next is an internal doc link - assertEquals(Hyperlink.LINK_DOCUMENT, + assertEquals(Hyperlink.LINK_DOCUMENT, sheet.getRow(14).getCell(2).getHyperlink().getType()); - assertEquals("Internal hyperlink to A2", + assertEquals("Internal hyperlink to A2", sheet.getRow(14).getCell(2).getHyperlink().getLabel()); - assertEquals("Sheet1!A2", + assertEquals("Sheet1!A2", sheet.getRow(14).getCell(2).getHyperlink().getAddress()); - + // Next is a file - assertEquals(Hyperlink.LINK_FILE, + assertEquals(Hyperlink.LINK_FILE, sheet.getRow(15).getCell(2).getHyperlink().getType()); - assertEquals(null, + assertEquals(null, sheet.getRow(15).getCell(2).getHyperlink().getLabel()); - assertEquals("WithVariousData.xlsx", + assertEquals("WithVariousData.xlsx", sheet.getRow(15).getCell(2).getHyperlink().getAddress()); - + // Last is a mailto - assertEquals(Hyperlink.LINK_EMAIL, + assertEquals(Hyperlink.LINK_EMAIL, sheet.getRow(16).getCell(2).getHyperlink().getType()); - assertEquals(null, + assertEquals(null, sheet.getRow(16).getCell(2).getHyperlink().getLabel()); - assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks", + assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks", sheet.getRow(16).getCell(2).getHyperlink().getAddress()); - } + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java index 84ff605096..4f4b4707b8 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java @@ -17,130 +17,74 @@ package org.apache.poi.hdf.model; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import junit.framework.TestCase; -import java.io.FileInputStream; -import java.io.IOException; - - /** - * Class to test HDFDocument functionality + * Class to test {@link HDFDocument} functionality * * @author Bob Otterberg */ -public final class TestHDFDocument - extends TestCase -{ - - public TestHDFDocument( String name ) - { - super( name ); +public final class TestHDFDocument extends TestCase { + public void testStopJUnitComplainintAboutNoTests() { + // TODO - fix these junits } - public void testStopJUnitComplainintAboutNoTests() - throws Exception - { - + private static InputStream openSample(String sampleFileName) { + String fullPathName = System.getProperty("HDF.testdata.path") + "/" + sampleFileName; + try { + return new FileInputStream(System.getProperty("HDF.testdata.path")); + } catch (FileNotFoundException e) { + throw new RuntimeException("Sample HDF file '" + fullPathName + "' was not found."); + } } /** - * TEST NAME: Test Read Empty

* OBJECTIVE: Test that HDF can read an empty document (empty.doc).

* SUCCESS: HDF reads the document. Matches values in their particular positions.

* FAILURE: HDF does not read the document or excepts. HDF cannot identify values * in the document in their known positions.

- * */ - public void fixme_testEmpty() - throws IOException - { - - String filename = System.getProperty( "HDF.testdata.path" ); - - - filename = filename + "/empty.doc"; - - FileInputStream stream = new FileInputStream( filename ); - - HDFDocument empty = new HDFDocument( stream ); - - stream.close(); - + public void fixme_testEmpty() throws IOException { + InputStream stream = openSample("empty.doc"); + new HDFDocument(stream); } - /** - * TEST NAME: Test Simple

* OBJECTIVE: Test that HDF can read an _very_ simple document (simple.doc).

* SUCCESS: HDF reads the document. Matches values in their particular positions.

* FAILURE: HDF does not read the document or excepts. HDF cannot identify values * in the document in their known positions.

- * */ - public void fixme_testSimple() - throws IOException - { - String filename = System.getProperty( "HDF.testdata.path" ); - filename = filename + "/simple.doc"; - FileInputStream stream = new FileInputStream( filename ); - HDFDocument empty = new HDFDocument( stream ); - stream.close(); + public void fixme_testSimple() throws IOException { + InputStream stream = openSample("simple.doc"); + new HDFDocument(stream); } /** - * TEST NAME: Test Read Simple List

* OBJECTIVE: Test that HDF can read a document containing a simple list (simple-list.doc).

* SUCCESS: HDF reads the document. Matches values in their particular positions.

* FAILURE: HDF does not read the document or excepts. HDF cannot identify values * in the document in their known positions.

* */ - public void fixme_testSimpleList() - throws IOException - { - String filename = System.getProperty( "HDF.testdata.path" ); - - filename = filename + "/simple-list.doc"; - FileInputStream stream = new FileInputStream( filename ); - HDFDocument empty = new HDFDocument( stream ); - stream.close(); + public void fixme_testSimpleList() throws IOException { + InputStream stream = openSample("simple-list.doc"); + new HDFDocument(stream); } /** - * TEST NAME: Test Read Simple Table

* OBJECTIVE: Test that HDF can read a document containing a simple table (simple-table.doc).

* SUCCESS: HDF reads the document. Matches values in their particular positions.

* FAILURE: HDF does not read the document or excepts. HDF cannot identify values * in the document in their known positions.

- * */ - public void fixme_testSimpleTable() - throws IOException - { - String filename = System.getProperty( "HDF.testdata.path" ); - - filename = filename + "/simple-table.doc"; - FileInputStream stream = new FileInputStream( filename ); - HDFDocument empty = new HDFDocument( stream ); - stream.close(); - } - - public static void main( String[] ignored_args ) - { - String path = System.getProperty( "HDF.testdata.path" ); - - // assume this is relative to basedir - if ( path == null ) - { - System.setProperty( - "HDF.testdata.path", - "src/scratchpad/testcases/org/apache/poi/hdf/data" ); - } - System.out.println( "Testing org.apache.poi.hdf.model.HDFDocument" ); - - junit.textui.TestRunner.run( TestHDFDocument.class ); + public void fixme_testSimpleTable() throws IOException { + InputStream stream = openSample("simple-table.doc"); + new HDFDocument(stream); } } - - diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java index d121666ae1..4ad028aac4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java @@ -33,11 +33,6 @@ public final class TestCHPBinTable private TextPieceTable fakeTPT = new TextPieceTable(); - public TestCHPBinTable(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java index c897944e5c..e0473faba5 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java @@ -29,12 +29,6 @@ public final class TestDocumentProperties private DocumentProperties _documentProperties = null; private HWPFDocFixture _hWPFDocFixture; - public TestDocumentProperties(String name) - { - super(name); - } - - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java index 5c848ff87a..75a8c64859 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java @@ -28,11 +28,6 @@ public final class TestFileInformationBlock private FileInformationBlock _fileInformationBlock = null; private HWPFDocFixture _hWPFDocFixture; - public TestFileInformationBlock(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java index 73b4298431..cdb425e607 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java @@ -27,11 +27,6 @@ public final class TestFontTable private FontTable _fontTable = null; private HWPFDocFixture _hWPFDocFixture; - public TestFontTable(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java index 008058b5cf..7cc013d941 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java @@ -32,11 +32,6 @@ public final class TestPAPBinTable private TextPieceTable fakeTPT = new TextPieceTable(); - public TestPAPBinTable(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java index de585efba1..7107db9613 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java @@ -28,13 +28,7 @@ public final class TestPlexOfCps private PlexOfCps _plexOfCps = null; private HWPFDocFixture _hWPFDocFixture; - public TestPlexOfCps(String name) - { - super(name); - } - public void testWriteRead() - throws Exception - { + public void testWriteRead() { _plexOfCps = new PlexOfCps(4); int last = 0; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java index da0eb00b8e..64830e6ec5 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java @@ -30,11 +30,6 @@ public final class TestSectionTable { private HWPFDocFixture _hWPFDocFixture; - public TestSectionTable(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java index e9d70370df..d092441e0d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java @@ -28,12 +28,6 @@ public final class TestStyleSheet private StyleSheet _styleSheet = null; private HWPFDocFixture _hWPFDocFixture; - - public TestStyleSheet(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java index e69f0dec04..c1d77be2a7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java @@ -33,11 +33,6 @@ public final class TestTextPieceTable extends TestCase { private HWPFDocFixture _hWPFDocFixture; private String dirname; - public TestTextPieceTable(String name) - { - super(name); - } - public void testReadWrite() throws Exception { diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java index bb28bc7c9e..0eeef4bbdf 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java @@ -43,11 +43,10 @@ import org.apache.poi.hpsf.wellknown.SectionIDMap; * * @author Rainer Klute (klute@rainer-klute.de) */ -public class TestBasic extends TestCase -{ +public final class TestBasic extends TestCase { - static final String POI_FS = "TestGermanWord90.doc"; - static final String[] POI_FILES = new String[] + private static final String POI_FS = "TestGermanWord90.doc"; + private static final String[] POI_FILES = new String[] { "\005SummaryInformation", "\005DocumentSummaryInformation", @@ -55,42 +54,29 @@ public class TestBasic extends TestCase "\001CompObj", "1Table" }; - static final int BYTE_ORDER = 0xfffe; - static final int FORMAT = 0x0000; - static final int OS_VERSION = 0x00020A04; - static final byte[] CLASS_ID = + private static final int BYTE_ORDER = 0xfffe; + private static final int FORMAT = 0x0000; + private static final int OS_VERSION = 0x00020A04; + private static final byte[] CLASS_ID = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; - static final int[] SECTION_COUNT = + private static final int[] SECTION_COUNT = {1, 2}; - static final boolean[] IS_SUMMARY_INFORMATION = + private static final boolean[] IS_SUMMARY_INFORMATION = {true, false}; - static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION = - {false, true}; - - POIFile[] poiFiles; - - - - /** - *

Test case constructor.

- * - * @param name The test case's name. - */ - public TestBasic(final String name) - { - super(name); - } + private static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION = + {false, true}; + private POIFile[] poiFiles; /** *

Read a the test file from the "data" directory.

- * + * * @exception FileNotFoundException if the file to be read does not exist. * @exception IOException if any other I/O exception occurs. */ @@ -102,8 +88,6 @@ public class TestBasic extends TestCase poiFiles = Util.readPOIFiles(data); } - - /** *

Checks the names of the files in the POI filesystem. They * are expected to be in a certain order.

@@ -115,8 +99,6 @@ public class TestBasic extends TestCase Assert.assertEquals(poiFiles[i].getName(), expected[i]); } - - /** *

Tests whether property sets can be created from the POI * files in the POI file system. This test case expects the first @@ -125,9 +107,9 @@ public class TestBasic extends TestCase * property sets. In the latter cases a {@link * NoPropertySetStreamException} will be thrown when trying to * create a {@link PropertySet}.

- * + * * @exception IOException if an I/O exception occurs. - * + * * @exception UnsupportedEncodingException if a character encoding is not * supported. */ @@ -163,13 +145,11 @@ public class TestBasic extends TestCase } } - - /** *

Tests the {@link PropertySet} methods. The test file has two * property sets: the first one is a {@link SummaryInformation}, * the second one is a {@link DocumentSummaryInformation}.

- * + * * @exception IOException if an I/O exception occurs * @exception HPSFException if any HPSF exception occurs */ @@ -194,13 +174,11 @@ public class TestBasic extends TestCase } } - - /** *

Tests the {@link Section} methods. The test file has two * property sets: the first one is a {@link SummaryInformation}, * the second one is a {@link DocumentSummaryInformation}.

- * + * * @exception IOException if an I/O exception occurs * @exception HPSFException if any HPSF exception occurs */ @@ -218,21 +196,4 @@ public class TestBasic extends TestCase Assert.assertEquals("Titel", s.getProperty(2)); Assert.assertEquals(1748, s.getSize()); } - - - - /** - *

Runs the test cases stand-alone.

- * - * @param args Command-line arguments (ignored) - * - * @exception Throwable if any sort of exception or error occurs - */ - public static void main(final String[] args) throws Throwable - { - System.setProperty("HPSF.testdata.path", - "./src/testcases/org/apache/poi/hpsf/data"); - junit.textui.TestRunner.run(TestBasic.class); - } - } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java b/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java index ec68dcea5b..b908c933a2 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hpsf.basic; @@ -31,17 +30,7 @@ import org.apache.poi.hpsf.SummaryInformation; * * @author Michael Zalewski (zalewski@optonline.net) */ -public class TestClassID extends TestCase -{ - /** - *

Constructor

- * - * @param name the test case's name - */ - public TestClassID(final String name) - { - super(name); - } +public final class TestClassID extends TestCase { /** * Various tests of overridden .equals() @@ -130,19 +119,4 @@ public class TestClassID extends TestCase "{04030201-0605-0807-090A-0B0C0D0E0F10}" ); } - - - - /** - *

Runs the test cases stand-alone.

- * - * @param args Command-line parameters (ignored) - */ - public static void main(final String[] args) - { - System.setProperty("HPSF.testdata.path", - "./src/testcases/org/apache/poi/hpsf/data"); - junit.textui.TestRunner.run(TestClassID.class); - } - } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java index 1c400904f6..806b49745a 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java @@ -43,37 +43,22 @@ import org.apache.poi.hpsf.Variant; * @author Rainer Klute <klute@rainer-klute.de> */ -public class TestEmptyProperties extends TestCase -{ +public final class TestEmptyProperties extends TestCase { /** *

This test file's summary information stream contains some empty * properties.

*/ - static final String POI_FS = "TestCorel.shw"; + private static final String POI_FS = "TestCorel.shw"; - static final String[] POI_FILES = new String[] + private static final String[] POI_FILES = new String[] { "PerfectOffice_MAIN", "\005SummaryInformation", "Main" }; - POIFile[] poiFiles; - - - - /** - *

Constructor

- * - * @param name The name of the test case - */ - public TestEmptyProperties(final String name) - { - super(name); - } - - + private POIFile[] poiFiles; /** *

Read a the test file from the "data" directory.

@@ -91,8 +76,6 @@ public class TestEmptyProperties extends TestCase poiFiles = Util.readPOIFiles(data); } - - /** *

Checks the names of the files in the POI filesystem. They * are expected to be in a certain order.

@@ -104,8 +87,6 @@ public class TestEmptyProperties extends TestCase Assert.assertEquals(poiFiles[i].getName(), expected[i]); } - - /** *

Tests whether property sets can be created from the POI * files in the POI file system. This test case expects the first @@ -114,15 +95,15 @@ public class TestEmptyProperties extends TestCase * property sets. In the latter cases a {@link * NoPropertySetStreamException} will be thrown when trying to * create a {@link PropertySet}.

- * + * * @exception IOException if an I/O exception occurs. - * + * * @exception UnsupportedEncodingException if a character encoding is not * supported. */ public void testCreatePropertySets() throws UnsupportedEncodingException, IOException - { + { Class[] expected = new Class[] { NoPropertySetStreamException.class, @@ -150,13 +131,11 @@ public class TestEmptyProperties extends TestCase } } - - /** *

Tests the {@link PropertySet} methods. The test file has two * property sets: the first one is a {@link SummaryInformation}, * the second one is a {@link DocumentSummaryInformation}.

- * + * * @exception IOException if an I/O exception occurs * @exception HPSFException if an HPSF operation fails */ @@ -184,21 +163,4 @@ public class TestEmptyProperties extends TestCase assertNull(s.getThumbnail()); assertNull(s.getApplicationName()); } - - - - /** - *

Runs the test cases stand-alone.

- * - * @param args the command-line arguments (unused) - * - * @exception Throwable if any exception or error occurs - */ - public static void main(final String[] args) throws Throwable - { - System.setProperty("HPSF.testdata.path", - "./src/testcases/org/apache/poi/hpsf/data"); - junit.textui.TestRunner.run(TestBasic.class); - } - } diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java index 14e3c2c56d..f342fd7231 100644 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java @@ -36,41 +36,25 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; import junit.framework.TestCase; /** - * Tests the ModelFactory. - * + * Tests the ModelFactory. + * * @author Andrew C. Oliver acoliver@apache.org */ -public class TestModelFactory extends TestCase -{ +public class TestModelFactory extends TestCase { private ModelFactory factory; private HSSFWorkbook book; private InputStream in; private List models; - /** - * Tests that the listeners collection is created - * @param arg0 - */ - public TestModelFactory(String arg0) - { - super(arg0); - ModelFactory mf = new ModelFactory(); - assertTrue("listeners member cannot be null", mf.listeners != null); - assertTrue("listeners member must be a List", mf.listeners instanceof List); - } - - public static void main(String[] args) - { - junit.textui.TestRunner.run(TestModelFactory.class); - } - protected void setUp() throws Exception { - super.setUp(); + ModelFactory mf = new ModelFactory(); + assertTrue("listeners member cannot be null", mf.listeners != null); + assertTrue("listeners member must be a List", mf.listeners instanceof List); models = new ArrayList(3); factory = new ModelFactory(); book = new HSSFWorkbook(); - ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book); + ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book); POIFSFileSystem fs = new POIFSFileSystem( new ByteArrayInputStream(stream.toByteArray()) ); @@ -91,9 +75,9 @@ public class TestModelFactory extends TestCase public void testRegisterListener() { if (factory.listeners.size() != 0) { - factory = new ModelFactory(); + factory = new ModelFactory(); } - + factory.registerListener(new MFListener(null)); factory.registerListener(new MFListener(null)); assertTrue("Factory listeners should be two, was="+ @@ -109,29 +93,29 @@ public class TestModelFactory extends TestCase { Model temp = null; Iterator mi = null; - + if (factory.listeners.size() != 0) { - factory = new ModelFactory(); + factory = new ModelFactory(); } - + factory.registerListener(new MFListener(models)); factory.run(in); - + assertTrue("Models size must be 2 was = "+models.size(), models.size() == 2); - mi = models.iterator(); + mi = models.iterator(); temp = (Model)mi.next(); - + assertTrue("First model is Workbook was " + temp.getClass().getName(), temp instanceof Workbook); - + temp = (Model)mi.next(); - + assertTrue("Second model is Sheet was " + temp.getClass().getName(), temp instanceof Sheet); - + } - + /** * Sets up a test file */ @@ -153,17 +137,16 @@ public class TestModelFactory extends TestCase class MFListener implements ModelFactoryListener { private List mlist; public MFListener(List mlist) { - this.mlist = mlist; - } - - public boolean process(Model model) - { - mlist.add(model); - return true; - } - - public Iterator models() { - return mlist.iterator(); + this.mlist = mlist; } -} \ No newline at end of file + public boolean process(Model model) + { + mlist.add(model); + return true; + } + + public Iterator models() { + return mlist.iterator(); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java index 744c692f02..607b92ca59 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java @@ -27,22 +27,19 @@ import org.apache.poi.hssf.record.cf.PatternFormatting; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.RefNPtg; import org.apache.poi.hssf.record.formula.RefPtg; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.util.LittleEndian; -import org.apache.poi.ss.formula.Formula; /** * Tests the serialization and deserialization of the TestCFRuleRecord * class works correctly. * - * @author Dmitriy Kumshayev + * @author Dmitriy Kumshayev */ -public final class TestCFRuleRecord extends TestCase -{ - public void testConstructors () - { +public final class TestCFRuleRecord extends TestCase { + public void testConstructors () { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); @@ -65,8 +62,7 @@ public final class TestCFRuleRecord extends TestCase assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2()); } - public void testCreateCFRuleRecord () - { + public void testCreateCFRuleRecord() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); CFRuleRecord record = CFRuleRecord.create(sheet, "7"); @@ -94,8 +90,7 @@ public final class TestCFRuleRecord extends TestCase } } - private void testCFRuleRecord(CFRuleRecord record) - { + private void testCFRuleRecord(CFRuleRecord record) { FontFormatting fontFormatting = new FontFormatting(); testFontFormattingAccessors(fontFormatting); assertFalse(record.containsFontFormattingBlock()); @@ -152,8 +147,7 @@ public final class TestCFRuleRecord extends TestCase assertTrue(record.isPatternStyleModified()); } - private void testPatternFormattingAccessors(PatternFormatting patternFormatting) - { + private void testPatternFormattingAccessors(PatternFormatting patternFormatting) { patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index); assertEquals(HSSFColor.GREEN.index,patternFormatting.getFillBackgroundColor()); @@ -164,8 +158,7 @@ public final class TestCFRuleRecord extends TestCase assertEquals(PatternFormatting.DIAMONDS,patternFormatting.getFillPattern()); } - private void testBorderFormattingAccessors(BorderFormatting borderFormatting) - { + private void testBorderFormattingAccessors(BorderFormatting borderFormatting) { borderFormatting.setBackwardDiagonalOn(false); assertFalse(borderFormatting.isBackwardDiagonalOn()); borderFormatting.setBackwardDiagonalOn(true); @@ -207,8 +200,7 @@ public final class TestCFRuleRecord extends TestCase } - private void testFontFormattingAccessors(FontFormatting fontFormatting) - { + private void testFontFormattingAccessors(FontFormatting fontFormatting) { // Check for defaults assertFalse(fontFormatting.isEscapementTypeModified()); assertFalse(fontFormatting.isFontCancellationModified()); @@ -357,31 +349,6 @@ public final class TestCFRuleRecord extends TestCase assertTrue(refNPtg.isRowRelative()); byte[] data = rr.serialize(); - - if (!compareArrays(DATA_REFN, 0, data, 4, DATA_REFN.length)) { - fail("Did not re-serialize correctly"); - } - } - - private static boolean compareArrays(byte[] arrayA, int offsetA, byte[] arrayB, int offsetB, int length) { - - if (offsetA + length > arrayA.length) { - return false; - } - if (offsetB + length > arrayB.length) { - return false; - } - for (int i = 0; i < length; i++) { - if (arrayA[i+offsetA] != arrayB[i+offsetB]) { - return false; - } - } - return true; - } - - public static void main(String[] ignored_args) - { - System.out.println("Testing org.apache.poi.hssf.record.CFRuleRecord"); - junit.textui.TestRunner.run(TestCFRuleRecord.class); + TestcaseRecordInputStream.confirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java index eea418963b..be40e8fedb 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.record; import java.util.Iterator; @@ -28,20 +27,14 @@ import org.apache.poi.hssf.util.HSSFColor; * * @author Brian Sanders (bsanders at risklabs dot com) */ -public class TestPaletteRecord extends TestCase -{ - public TestPaletteRecord(String name) - { - super(name); - } - +public final class TestPaletteRecord extends TestCase { + /** * Tests that the default palette matches the constants of HSSFColor */ - public void testDefaultPalette() - { + public void testDefaultPalette() { PaletteRecord palette = new PaletteRecord(); - + //make sure all the HSSFColor constants match Map colors = HSSFColor.getIndexHash(); Iterator indexes = colors.keySet().iterator(); diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java index 00af6db238..344bdee5d8 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestAxisOptionsRecord.java @@ -31,7 +31,7 @@ import junit.framework.TestCase; * @author Andrew C. Oliver(acoliver at apache.org) */ public final class TestAxisOptionsRecord extends TestCase { - byte[] data = new byte[] { + private static final byte[] data = { (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01, (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00, (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, @@ -88,14 +88,4 @@ public final class TestAxisOptionsRecord extends TestCase { for (int i = 0; i < data.length; i++) assertEquals("At offset " + i, data[i], recordBytes[i+4]); } - - /** - * The main program for the TestAxisOptionsRecord class - * - *@param args The command line arguments - */ - public static void main(String[] args) { - System.out.println("Testing org.apache.poi.hssf.record.AxisOptionsRecord"); - junit.textui.TestRunner.run(TestAxisOptionsRecord.class); - } } diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java index 0301e7e811..28d13178fc 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestTickRecord.java @@ -27,18 +27,17 @@ import junit.framework.TestCase; * class works correctly. Test data taken directly from a real * Excel file. * - * @author Andrew C. Oliver(acoliver at apache.org) */ public final class TestTickRecord extends TestCase { - byte[] data = new byte[] { - (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01, + private static final byte[] data = { + (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00, - (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00 + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00, + (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00 }; public void testLoad() { @@ -62,8 +61,7 @@ public final class TestTickRecord extends TestCase { assertEquals( 34, record.getRecordSize() ); } - public void testStore() - { + public void testStore() { TickRecord record = new TickRecord(); record.setMajorTickType( (byte)2 ); record.setMinorTickType( (byte)0 ); @@ -86,16 +84,4 @@ public final class TestTickRecord extends TestCase { for (int i = 0; i < data.length; i++) assertEquals("At offset " + i, data[i], recordBytes[i+4]); } - - - /** - * The main program for the TestTickRecord class - * - *@param args The command line arguments - */ - public static void main(String[] args) { - System.out.println("Testing org.apache.poi.hssf.record.TickRecord"); - junit.textui.TestRunner.run(TestTickRecord.class); - } - } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java index 186ee18a6b..77f488d9dd 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java @@ -52,13 +52,7 @@ public final class TestReadWriteChart extends TestCase { Sheet newSheet = workbook.getSheetAt(0).getSheet(); List records = newSheet.getRecords(); - //System.out.println("BOF Assertion"); assertTrue(records.get(0) instanceof BOFRecord); - //System.out.println("EOF Assertion"); assertTrue(records.get(records.size() - 1) instanceof EOFRecord); } - - public static void main(String [] args) { - junit.textui.TestRunner.run(TestReadWriteChart.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java b/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java index c0453918a9..858032ebbd 100644 --- a/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java +++ b/src/testcases/org/apache/poi/poifs/eventfilesystem/TestPOIFSReaderRegistry.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.eventfilesystem; -import junit.framework.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; -import java.util.*; +import junit.framework.TestCase; import org.apache.poi.poifs.filesystem.POIFSDocumentPath; @@ -30,10 +30,7 @@ import org.apache.poi.poifs.filesystem.POIFSDocumentPath; * * @author Marc Johnson */ - -public class TestPOIFSReaderRegistry - extends TestCase -{ +public final class TestPOIFSReaderRegistry extends TestCase { private POIFSReaderListener[] listeners = { new Listener(), new Listener(), new Listener(), new Listener() @@ -56,23 +53,10 @@ public class TestPOIFSReaderRegistry "a0", "a1", "a2", "a3" }; - /** - * Constructor TestPOIFSReaderRegistry - * - * @param name - */ - - public TestPOIFSReaderRegistry(String name) - { - super(name); - } - /** * Test empty registry */ - - public void testEmptyRegistry() - { + public void testEmptyRegistry() { POIFSReaderRegistry registry = new POIFSReaderRegistry(); for (int j = 0; j < paths.length; j++) @@ -90,9 +74,7 @@ public class TestPOIFSReaderRegistry /** * Test mixed registration operations */ - - public void testMixedRegistrationOperations() - { + public void testMixedRegistrationOperations() { POIFSReaderRegistry registry = new POIFSReaderRegistry(); for (int j = 0; j < listeners.length; j++) @@ -172,17 +154,4 @@ public class TestPOIFSReaderRegistry } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.eventfilesystem.POIFSReaderRegistry"); - junit.textui.TestRunner.run(TestPOIFSReaderRegistry.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java index 8af60334ce..fe9eb8ad02 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDirectoryNode.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; @@ -33,31 +32,12 @@ import org.apache.poi.poifs.property.DocumentProperty; * * @author Marc Johnson */ - -public class TestDirectoryNode - extends TestCase -{ - - /** - * Constructor TestDirectoryNode - * - * @param name - */ - - public TestDirectoryNode(String name) - { - super(name); - } +public final class TestDirectoryNode extends TestCase { /** * test trivial constructor (a DirectoryNode with no children) - * - * @exception IOException */ - - public void testEmptyConstructor() - throws IOException - { + public void testEmptyConstructor() { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryProperty property1 = new DirectoryProperty("parent"); DirectoryProperty property2 = new DirectoryProperty("child"); @@ -113,13 +93,8 @@ public class TestDirectoryNode /** * test non-trivial constructor (a DirectoryNode with children) - * - * @exception IOException */ - - public void testNonEmptyConstructor() - throws IOException - { + public void testNonEmptyConstructor() throws IOException { DirectoryProperty property1 = new DirectoryProperty("parent"); DirectoryProperty property2 = new DirectoryProperty("child1"); @@ -177,13 +152,8 @@ public class TestDirectoryNode /** * test deletion methods - * - * @exception IOException */ - - public void testDeletion() - throws IOException - { + public void testDeletion() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry root = fs.getRoot(); @@ -213,13 +183,8 @@ public class TestDirectoryNode /** * test change name methods - * - * @exception IOException */ - - public void testRename() - throws IOException - { + public void testRename() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry root = fs.getRoot(); @@ -237,17 +202,4 @@ public class TestDirectoryNode assertTrue(dir2.renameTo("foo")); assertEquals("foo", dir2.getName()); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.filesystem.DirectoryNode"); - junit.textui.TestRunner.run(TestDirectoryNode.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java index 82dabc7465..e216ed9a88 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocument.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; -import java.util.*; +import junit.framework.TestCase; -import junit.framework.*; - -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.poifs.property.DocumentProperty; import org.apache.poi.poifs.storage.RawDataBlock; import org.apache.poi.poifs.storage.SmallDocumentBlock; @@ -36,31 +32,12 @@ import org.apache.poi.poifs.storage.SmallDocumentBlock; * * @author Marc Johnson */ - -public class TestDocument - extends TestCase -{ - - /** - * Constructor TestDocument - * - * @param name - */ - - public TestDocument(String name) - { - super(name); - } +public final class TestDocument extends TestCase { /** * Integration test -- really about all we can do - * - * @exception IOException */ - - public void testPOIFSDocument() - throws IOException - { + public void testPOIFSDocument() throws IOException { // verify correct number of blocks get created for document // that is exact multituple of block size @@ -158,10 +135,8 @@ public class TestDocument } } - private POIFSDocument makeCopy(POIFSDocument document, byte [] input, - byte [] data) - throws IOException - { + private static POIFSDocument makeCopy(POIFSDocument document, byte[] input, byte[] data) + throws IOException { POIFSDocument copy = null; if (input.length >= 4096) @@ -194,10 +169,8 @@ public class TestDocument return copy; } - private void checkDocument(final POIFSDocument document, - final byte [] input) - throws IOException - { + private static void checkDocument(final POIFSDocument document, final byte[] input) + throws IOException { int big_blocks = 0; int small_blocks = 0; int total_output = 0; @@ -221,11 +194,8 @@ public class TestDocument input)), input); } - private byte [] checkValues(int big_blocks, int small_blocks, - int total_output, POIFSDocument document, - byte [] input) - throws IOException - { + private static byte[] checkValues(int big_blocks, int small_blocks, int total_output, + POIFSDocument document, byte[] input) throws IOException { assertEquals(document, document.getDocumentProperty().getDocument()); int increment = ( int ) Math.sqrt(input.length); @@ -267,17 +237,4 @@ public class TestDocument } return output; } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.filesystem.POIFSDocument"); - junit.textui.TestRunner.run(TestDocument.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java index 7272e4223c..9b69b1a2cb 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,53 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test DocumentDescriptor functionality * * @author Marc Johnson */ - -public class TestDocumentDescriptor - extends TestCase -{ - - /** - * Constructor TestDocumentDescriptor - * - * @param name - */ - - public TestDocumentDescriptor(String name) - { - super(name); - } +public final class TestDocumentDescriptor extends TestCase { /** * test equality */ - - public void testEquality() - { - String[] names = - { - "c1", "c2", "c3", "c4", "c5" - }; + public void testEquality() { + String[] names = { "c1", "c2", "c3", "c4", "c5" }; POIFSDocumentPath a1 = new POIFSDocumentPath(); POIFSDocumentPath a2 = new POIFSDocumentPath(null); POIFSDocumentPath a3 = new POIFSDocumentPath(new String[ 0 ]); POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null); POIFSDocumentPath a5 = new POIFSDocumentPath(a1, new String[ 0 ]); - POIFSDocumentPath[] paths = - { - a1, a2, a3, a4, a5 - }; + POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 }; for (int j = 0; j < paths.length; j++) { @@ -196,17 +172,4 @@ public class TestDocumentDescriptor } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.eventfilesystem.DocumentDescriptor"); - junit.textui.TestRunner.run(TestDocumentDescriptor.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java index 211c300898..ad077891c5 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; @@ -32,31 +31,12 @@ import org.apache.poi.poifs.storage.RawDataBlock; * * @author Marc Johnson */ - -public class TestDocumentNode - extends TestCase -{ - - /** - * Constructor TestDocumentNode - * - * @param name - */ - - public TestDocumentNode(String name) - { - super(name); - } +public final class TestDocumentNode extends TestCase { /** * test constructor - * - * @exception IOException */ - - public void testConstructor() - throws IOException - { + public void testConstructor() throws IOException { DirectoryProperty property1 = new DirectoryProperty("directory"); RawDataBlock[] rawBlocks = new RawDataBlock[ 4 ]; ByteArrayInputStream stream = @@ -90,17 +70,4 @@ public class TestDocumentNode // verify getParent behaves correctly assertEquals(parent, node.getParent()); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.filesystem.DocumentNode"); - junit.textui.TestRunner.run(TestDocumentNode.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java index 7fa9471aa4..4218367d27 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java @@ -15,53 +15,26 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; -import java.util.*; - -import junit.framework.*; - -import org.apache.poi.poifs.property.DirectoryProperty; -import org.apache.poi.poifs.property.DocumentProperty; -import org.apache.poi.poifs.storage.RawDataBlock; +import junit.framework.TestCase; /** * Class to test DocumentOutputStream functionality * * @author Marc Johnson */ - -public class TestDocumentOutputStream - extends TestCase -{ - - /** - * Constructor TestDocumentOutputStream - * - * @param name - * - * @exception IOException - */ - - public TestDocumentOutputStream(String name) - throws IOException - { - super(name); - } +public final class TestDocumentOutputStream extends TestCase { /** * test write(int) behavior - * - * @exception IOException */ - - public void testWrite1() - throws IOException - { + public void testWrite1() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DocumentOutputStream dstream = new DocumentOutputStream(stream, 25); @@ -89,13 +62,8 @@ public class TestDocumentOutputStream /** * test write(byte[]) behavior - * - * @exception IOException */ - - public void testWrite2() - throws IOException - { + public void testWrite2() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DocumentOutputStream dstream = new DocumentOutputStream(stream, 25); @@ -133,13 +101,8 @@ public class TestDocumentOutputStream /** * test write(byte[], int, int) behavior - * - * @exception IOException */ - - public void testWrite3() - throws IOException - { + public void testWrite3() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DocumentOutputStream dstream = new DocumentOutputStream(stream, 25); byte[] array = new byte[ 50 ]; @@ -169,13 +132,8 @@ public class TestDocumentOutputStream /** * test writeFiller() - * - * @exception IOException */ - - public void testWriteFiller() - throws IOException - { + public void testWriteFiller() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DocumentOutputStream dstream = new DocumentOutputStream(stream, 25); @@ -205,17 +163,4 @@ public class TestDocumentOutputStream } stream.close(); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.filesystem.DocumentOutputStream"); - junit.textui.TestRunner.run(TestDocumentOutputStream.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java index 870d752522..36886af982 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java @@ -30,143 +30,88 @@ import org.apache.poi.poifs.filesystem.POIFSWriterEvent; import org.apache.poi.poifs.filesystem.POIFSWriterListener; import org.apache.poi.poifs.filesystem.DirectoryEntry; -public class TestEmptyDocument extends TestCase { +public final class TestEmptyDocument extends TestCase { - public static void main(String[] args) { - TestEmptyDocument driver = new TestEmptyDocument(); + public void testSingleEmptyDocument() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {})); - System.out.println(); - System.out.println("As only file..."); - System.out.println(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } - System.out.print("Trying using createDocument(String,InputStream): "); - try { - driver.testSingleEmptyDocument(); - System.out.println("Worked!"); - } catch (IOException exception) { - System.out.println("failed! "); - System.out.println(exception.toString()); - } - System.out.println(); + public void testSingleEmptyDocumentEvent() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir.createDocument("Foo", 0, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + System.out.println("written"); + } + }); - System.out.print - ("Trying using createDocument(String,int,POIFSWriterListener): "); - try { - driver.testSingleEmptyDocumentEvent(); - System.out.println("Worked!"); - } catch (IOException exception) { - System.out.println("failed!"); - System.out.println(exception.toString()); - } - System.out.println(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } - System.out.println(); - System.out.println("After another file..."); - System.out.println(); + public void testEmptyDocumentWithFriend() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 })); + dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {})); - System.out.print("Trying using createDocument(String,InputStream): "); - try { - driver.testEmptyDocumentWithFriend(); - System.out.println("Worked!"); - } catch (IOException exception) { - System.out.println("failed! "); - System.out.println(exception.toString()); - } - System.out.println(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } - System.out.print - ("Trying using createDocument(String,int,POIFSWriterListener): "); - try { - driver.testEmptyDocumentWithFriend(); - System.out.println("Worked!"); - } catch (IOException exception) { - System.out.println("failed!"); - System.out.println(exception.toString()); - } - System.out.println(); - } + public void testEmptyDocumentEventWithFriend() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir.createDocument("Bar", 1, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + try { + event.getStream().write(0); + } catch (IOException exception) { + throw new RuntimeException("exception on write: " + exception); + } + } + }); + dir.createDocument("Foo", 0, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + } + }); - public void testSingleEmptyDocument() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry dir = fs.getRoot(); - dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { })); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } - public void testSingleEmptyDocumentEvent() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry dir = fs.getRoot(); - dir.createDocument("Foo", 0, new POIFSWriterListener() { - public void processPOIFSWriterEvent(POIFSWriterEvent event) { - System.out.println("written"); - } - }); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - } + public void testEmptyDocumentBug11744() throws Exception { + byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public void testEmptyDocumentWithFriend() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry dir = fs.getRoot(); - dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 })); - dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { })); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - } + POIFSFileSystem fs = new POIFSFileSystem(); + fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty"); + fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + out.toByteArray(); - public void testEmptyDocumentEventWithFriend() throws IOException { - POIFSFileSystem fs = new POIFSFileSystem(); - DirectoryEntry dir = fs.getRoot(); - dir.createDocument("Bar", 1, new POIFSWriterListener() { - public void processPOIFSWriterEvent(POIFSWriterEvent event) { - try { - event.getStream().write(0); - } catch (IOException exception) { - throw new RuntimeException("exception on write: " + exception); - } - } - }); - dir.createDocument("Foo", 0, new POIFSWriterListener() { - public void processPOIFSWriterEvent(POIFSWriterEvent event) { - } - }); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - } + // This line caused the error. + fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - public void testEmptyDocumentBug11744() throws Exception { - byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty"); + assertEquals("Expected zero size", 0, entry.getSize()); + byte[] actualReadbackData; + actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry)); + assertEquals("Expected zero read from stream", 0, actualReadbackData.length); - POIFSFileSystem fs = new POIFSFileSystem(); - fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty"); - fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty"); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - fs.writeFilesystem(out); - out.toByteArray(); - - // This line caused the error. - fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); - - DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty"); - assertEquals("Expected zero size", 0, entry.getSize()); - byte[] actualReadbackData; - actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry)); - assertEquals("Expected zero read from stream", 0, - actualReadbackData.length); - - entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty"); - actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry)); - assertEquals("Expected size was wrong", testData.length, entry.getSize()); - assertTrue("Expected different data read from stream", - Arrays.equals(testData, actualReadbackData)); - } + entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty"); + actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry)); + assertEquals("Expected size was wrong", testData.length, entry.getSize()); + assertTrue("Expected different data read from stream", Arrays.equals(testData, + actualReadbackData)); + } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java index 5c8ea8874b..b09c469458 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,39 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.filesystem; -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test POIFSDocumentPath functionality * * @author Marc Johnson */ +public final class TestPOIFSDocumentPath extends TestCase { -public class TestPOIFSDocumentPath - extends TestCase -{ - - /** - * Constructor TestPOIFSDocumentPath - * - * @param name - */ - - public TestPOIFSDocumentPath(String name) - { - super(name); - } /** * Test default constructor */ - - public void testDefaultConstructor() - { + public void testDefaultConstructor() { POIFSDocumentPath path = new POIFSDocumentPath(); assertEquals(0, path.length()); @@ -56,9 +39,7 @@ public class TestPOIFSDocumentPath /** * Test full path constructor */ - - public void testFullPathConstructor() - { + public void testFullPathConstructor() { String[] components = { "foo", "bar", "foobar", "fubar" @@ -125,9 +106,7 @@ public class TestPOIFSDocumentPath /** * Test relative path constructor */ - - public void testRelativePathConstructor() - { + public void testRelativePathConstructor() { String[] initialComponents = { "a", "b", "c" @@ -216,9 +195,7 @@ public class TestPOIFSDocumentPath /** * test equality */ - - public void testEquality() - { + public void testEquality() { POIFSDocumentPath a1 = new POIFSDocumentPath(); POIFSDocumentPath a2 = new POIFSDocumentPath(null); POIFSDocumentPath a3 = new POIFSDocumentPath(new String[ 0 ]); @@ -318,17 +295,4 @@ public class TestPOIFSDocumentPath } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.eventfilesystem.POIFSDocumentPath"); - junit.textui.TestRunner.run(TestPOIFSDocumentPath.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java index 20605a7a84..a2bd9a748b 100644 --- a/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java +++ b/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,63 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.property; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; -import java.util.*; - -import junit.framework.*; - -import org.apache.poi.poifs.common.POIFSConstants; +import junit.framework.TestCase; /** * Class to test DirectoryProperty functionality * * @author Marc Johnson */ - -public class TestDirectoryProperty - extends TestCase -{ +public final class TestDirectoryProperty extends TestCase { private DirectoryProperty _property; private byte[] _testblock; - /** - * Constructor TestDirectoryProperty - * - * @param name - */ - - public TestDirectoryProperty(String name) - { - super(name); - } - /** * Test constructing DirectoryProperty - * - * @exception IOException */ - - public void testConstructor() - throws IOException - { + public void testConstructor() throws IOException { createBasicDirectoryProperty(); verifyProperty(); } /** * Test pre-write functionality - * - * @exception IOException */ - - public void testPreWrite() - throws IOException - { + public void testPreWrite() throws IOException { createBasicDirectoryProperty(); _property.preWrite(); @@ -119,9 +94,7 @@ public class TestDirectoryProperty } } - private void verifyChildren(int count) - throws IOException - { + private void verifyChildren(int count) { Iterator iter = _property.getChildren(); List children = new ArrayList(); @@ -175,8 +148,7 @@ public class TestDirectoryProperty } } - private void createBasicDirectoryProperty() - { + private void createBasicDirectoryProperty() { String name = "MyDirectory"; _property = new DirectoryProperty(name); @@ -209,9 +181,7 @@ public class TestDirectoryProperty } } - private void verifyProperty() - throws IOException - { + private void verifyProperty() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(512); _property.writeData(stream); @@ -225,15 +195,7 @@ public class TestDirectoryProperty } } - /** - * Test addChild - * - * @exception IOException - */ - - public void testAddChild() - throws IOException - { + public void testAddChild() throws IOException { createBasicDirectoryProperty(); _property.addChild(new LocalProperty(1)); _property.addChild(new LocalProperty(2)); @@ -260,15 +222,7 @@ public class TestDirectoryProperty _property.addChild(new LocalProperty(3)); } - /** - * Test deleteChild - * - * @exception IOException - */ - - public void testDeleteChild() - throws IOException - { + public void testDeleteChild() throws IOException { createBasicDirectoryProperty(); Property p1 = new LocalProperty(1); @@ -288,15 +242,7 @@ public class TestDirectoryProperty _property.addChild(new LocalProperty(1)); } - /** - * Test changeName - * - * @exception IOException - */ - - public void testChangeName() - throws IOException - { + public void testChangeName() throws IOException { createBasicDirectoryProperty(); Property p1 = new LocalProperty(1); String originalName = p1.getName(); @@ -314,15 +260,7 @@ public class TestDirectoryProperty assertTrue(_property.changeName(p1, originalName)); } - /** - * Test reading constructor - * - * @exception IOException - */ - - public void testReadingConstructor() - throws IOException - { + public void testReadingConstructor() throws IOException { byte[] input = { ( byte ) 0x42, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00, @@ -362,7 +300,7 @@ public class TestDirectoryProperty verifyReadingProperty(0, input, 0, "Boot Entry"); } - private void verifyReadingProperty(int index, byte [] input, int offset, + private static void verifyReadingProperty(int index, byte [] input, int offset, String name) throws IOException { @@ -385,17 +323,4 @@ public class TestDirectoryProperty assertEquals(name, property.getName()); assertTrue(!property.getChildren().hasNext()); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.property.DirectoryProperty"); - junit.textui.TestRunner.run(TestDirectoryProperty.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java index 8bf8d00ae8..8f3ccdca68 100644 --- a/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java +++ b/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,49 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.property; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; - -import org.apache.poi.poifs.property.DocumentProperty; +import junit.framework.TestCase; /** * Class to test DocumentProperty functionality * * @author Marc Johnson */ +public final class TestDocumentProperty extends TestCase { -public class TestDocumentProperty - extends TestCase -{ - - /** - * Constructor TestDocumentProperty - * - * @param name - */ - - public TestDocumentProperty(String name) - { - super(name); - } - - /** - * Test constructing DocumentPropertys - * - * @exception IOException - */ - - public void testConstructor() - throws IOException - { - + public void testConstructor() throws IOException { // test with short name, small file verifyProperty("foo", 1234); @@ -71,15 +43,7 @@ public class TestDocumentProperty verifyProperty("A.really.long.long.long.name123", 4096); } - /** - * Test reading constructor - * - * @exception IOException - */ - - public void testReadingConstructor() - throws IOException - { + public void testReadingConstructor() throws IOException { byte[] input = { ( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00, @@ -217,14 +181,11 @@ public class TestDocumentProperty verifyReadingProperty(1, input, 128, "Workbook"); verifyReadingProperty(2, input, 256, "\005SummaryInformation"); - verifyReadingProperty(3, input, 384, - "\005DocumentSummaryInformation"); + verifyReadingProperty(3, input, 384, "\005DocumentSummaryInformation"); } - private void verifyReadingProperty(int index, byte [] input, int offset, - String name) - throws IOException - { + private void verifyReadingProperty(int index, byte[] input, int offset, String name) + throws IOException { DocumentProperty property = new DocumentProperty(index, input, offset); ByteArrayOutputStream stream = new ByteArrayOutputStream(128); @@ -244,9 +205,7 @@ public class TestDocumentProperty assertEquals(name, property.getName()); } - private void verifyProperty(String name, int size) - throws IOException - { + private void verifyProperty(String name, int size) throws IOException { DocumentProperty property = new DocumentProperty(name, size); if (size >= 4096) @@ -309,17 +268,4 @@ public class TestDocumentProperty output[ j ]); } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.property.DocumentProperty"); - junit.textui.TestRunner.run(TestDocumentProperty.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java b/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java index 20ff82e9bf..b3fc34ea2a 100644 --- a/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java +++ b/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.property; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.List; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.storage.RawDataBlock; @@ -32,31 +30,9 @@ import org.apache.poi.poifs.storage.RawDataBlock; * * @author Marc Johnson */ +public final class TestPropertyFactory extends TestCase { -public class TestPropertyFactory - extends TestCase -{ - - /** - * Constructor TestPropertyFactory - * - * @param name - */ - - public TestPropertyFactory(String name) - { - super(name); - } - - /** - * Test executing convertToProperties - * - * @exception IOException - */ - - public void testConvertToProperties() - throws IOException - { + public void testConvertToProperties() throws IOException { // real data from a real file! byte[] testdata = @@ -2223,17 +2199,4 @@ public class TestPropertyFactory } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.property.PropertyFactory"); - junit.textui.TestRunner.run(TestPropertyFactory.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java b/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java index 008504fb00..53adb01f9f 100644 --- a/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java +++ b/src/testcases/org/apache/poi/poifs/property/TestPropertyTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.property; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Iterator; -import java.util.*; - -import junit.framework.*; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.storage.BlockAllocationTableReader; @@ -34,21 +34,7 @@ import org.apache.poi.poifs.storage.RawDataBlockList; * * @author Marc Johnson */ - -public class TestPropertyTable - extends TestCase -{ - - /** - * Constructor TestPropertyTable - * - * @param name - */ - - public TestPropertyTable(String name) - { - super(name); - } +public final class TestPropertyTable extends TestCase { /** * Test PropertyTable @@ -65,13 +51,8 @@ public class TestPropertyTable * the output (including the preWrite phase first), and comparing * it against a real property table extracted from a file known to * be acceptable to Excel. - * - * @exception IOException */ - - public void testWriterPropertyTable() - throws IOException - { + public void testWriterPropertyTable() throws IOException { // create the PropertyTable PropertyTable table = new PropertyTable(); @@ -105,6 +86,7 @@ public class TestPropertyTable ByteArrayOutputStream stream = new ByteArrayOutputStream(512); byte[] testblock = { + // TODO - put this raw data in a better format ( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6f, ( byte ) 0x00, ( byte ) 0x6f, ( byte ) 0x00, ( byte ) 0x74, ( byte ) 0x00, ( byte ) 0x20, ( byte ) 0x00, ( byte ) 0x45, ( byte ) 0x00, @@ -2622,6 +2604,9 @@ public class TestPropertyTable child = ( Property ) iter.next(); ++count; } + if (child == null) { + throw new AssertionFailedError("no children found"); + } assertEquals(1, count); assertTrue(child.isDirectory()); iter = (( DirectoryProperty ) child).getChildren(); @@ -2633,17 +2618,4 @@ public class TestPropertyTable } assertEquals(35, count); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.property.PropertyTable"); - junit.textui.TestRunner.run(TestPropertyTable.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java index 6ba5da07a5..84e802fe19 100644 --- a/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java +++ b/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.property; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.common.POIFSConstants; @@ -32,33 +29,12 @@ import org.apache.poi.poifs.common.POIFSConstants; * * @author Marc Johnson */ - -public class TestRootProperty - extends TestCase -{ +public final class TestRootProperty extends TestCase { private RootProperty _property; private byte[] _testblock; - /** - * Constructor TestRootProperty - * - * @param name - */ - public TestRootProperty(String name) - { - super(name); - } - - /** - * Test constructing RootProperty - * - * @exception IOException - */ - - public void testConstructor() - throws IOException - { + public void testConstructor() throws IOException { createBasicRootProperty(); verifyProperty(); } @@ -105,9 +81,7 @@ public class TestRootProperty } } - private void verifyProperty() - throws IOException - { + private void verifyProperty() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(512); _property.writeData(stream); @@ -121,12 +95,7 @@ public class TestRootProperty } } - /** - * test setSize - */ - - public void testSetSize() - { + public void testSetSize() { for (int j = 0; j < 10; j++) { createBasicRootProperty(); @@ -136,15 +105,7 @@ public class TestRootProperty } } - /** - * Test reading constructor - * - * @exception IOException - */ - - public void testReadingConstructor() - throws IOException - { + public void testReadingConstructor() throws IOException { byte[] input = { ( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00, @@ -184,10 +145,8 @@ public class TestRootProperty verifyReadingProperty(0, input, 0, "Root Entry", "{00020820-0000-0000-C000-000000000046}"); } - private void verifyReadingProperty(int index, byte [] input, int offset, - String name, String sClsId) - throws IOException - { + private void verifyReadingProperty(int index, byte[] input, int offset, String name, + String sClsId) throws IOException { RootProperty property = new RootProperty(index, input, offset); ByteArrayOutputStream stream = new ByteArrayOutputStream(128); @@ -208,17 +167,4 @@ public class TestRootProperty assertTrue(!property.getChildren().hasNext()); assertEquals(property.getStorageClsid().toString(), sClsId); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.property.RootProperty"); - junit.textui.TestRunner.run(TestRootProperty.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java index c39454d54a..950c0c0d7d 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestBATBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,49 +14,29 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test BATBlock functionality * * @author Marc Johnson */ - -public class TestBATBlock - extends TestCase -{ - - /** - * Constructor TestBATBlock - * - * @param name - */ - - public TestBATBlock(String name) - { - super(name); - } +public final class TestBATBlock extends TestCase { /** * Test the createBATBlocks method. The test involves setting up * various arrays of int's and ensuring that the correct number of * BATBlocks is created for each array, and that the data from * each array is correctly written to the BATBlocks. - * - * @exception IOException */ - - public void testCreateBATBlocks() - throws IOException - { + public void testCreateBATBlocks() throws IOException { // test 0 length array (basic sanity) BATBlock[] rvalue = BATBlock.createBATBlocks(createTestArray(0)); @@ -85,8 +64,7 @@ public class TestBATBlock verifyContents(rvalue, 129); } - private int [] createTestArray(int count) - { + private static int[] createTestArray(int count) { int[] rvalue = new int[ count ]; for (int j = 0; j < count; j++) @@ -96,9 +74,7 @@ public class TestBATBlock return rvalue; } - private void verifyContents(BATBlock [] blocks, int entries) - throws IOException - { + private static void verifyContents(BATBlock[] blocks, int entries) throws IOException { byte[] expected = new byte[ 512 * blocks.length ]; Arrays.fill(expected, ( byte ) 0xFF); @@ -127,16 +103,7 @@ public class TestBATBlock } } - /** - * test createXBATBlocks - * - * @exception IOException - */ - - public void testCreateXBATBlocks() - throws IOException - { - + public void testCreateXBATBlocks() throws IOException { // test 0 length array (basic sanity) BATBlock[] rvalue = BATBlock.createXBATBlocks(createTestArray(0), 1); @@ -168,10 +135,8 @@ public class TestBATBlock verifyXBATContents(rvalue, 255, 1); } - private void verifyXBATContents(BATBlock [] blocks, int entries, - int start_block) - throws IOException - { + private static void verifyXBATContents(BATBlock[] blocks, int entries, int start_block) + throws IOException { byte[] expected = new byte[ 512 * blocks.length ]; Arrays.fill(expected, ( byte ) 0xFF); @@ -220,20 +185,9 @@ public class TestBATBlock } } - /** - * test calculateXBATStorageRequirements - */ - - public void testCalculateXBATStorageRequirements() - { - int[] blockCounts = - { - 0, 1, 127, 128 - }; - int[] requirements = - { - 0, 1, 1, 2 - }; + public void testCalculateXBATStorageRequirements() { + int[] blockCounts = { 0, 1, 127, 128 }; + int[] requirements = { 0, 1, 1, 2 }; for (int j = 0; j < blockCounts.length; j++) { @@ -243,42 +197,13 @@ public class TestBATBlock } } - /** - * test entriesPerBlock - */ - - public void testEntriesPerBlock() - { + public void testEntriesPerBlock() { assertEquals(128, BATBlock.entriesPerBlock()); } - - /** - * test entriesPerXBATBlock - */ - - public void testEntriesPerXBATBlock() - { + public void testEntriesPerXBATBlock() { assertEquals(127, BATBlock.entriesPerXBATBlock()); } - - /** - * test getXBATChainOffset - */ - - public void testGetXBATChainOffset() - { + public void testGetXBATChainOffset() { assertEquals(508, BATBlock.getXBATChainOffset()); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println("Testing org.apache.poi.poifs.storage.BATBlock"); - junit.textui.TestRunner.run(TestBATBlock.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java index b2042319ce..39764c6748 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.LittleEndian; @@ -34,36 +31,18 @@ import org.apache.poi.util.LittleEndianConsts; * * @author Marc Johnson */ - -public class TestBlockAllocationTableReader - extends TestCase -{ - - /** - * Constructor TestBlockAllocationTableReader - * - * @param name - */ - - public TestBlockAllocationTableReader(String name) - { - super(name); - } +public final class TestBlockAllocationTableReader extends TestCase { /** * Test small block allocation table constructor - * - * @exception IOException */ - - public void testSmallBATConstructor() - throws IOException - { + public void testSmallBATConstructor() throws IOException { // need to create an array of raw blocks containing the SBAT, // and a small document block list byte[] sbat_data = { + // TODO - put this raw data in a better format ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, @@ -1160,28 +1139,20 @@ public class TestBlockAllocationTableReader } } - /** - * Test reading constructor - * - * @exception IOException - */ - - public void testReadingConstructor() - throws IOException - { + public void testReadingConstructor() throws IOException { // create a document, minus the header block, and use that to // create a RawDataBlockList. The document will exist entire // of BATBlocks and XBATBlocks - // + // // we will create two XBAT blocks, which will encompass 128 // BAT blocks between them, and two extra BAT blocks which // will be in the block array passed to the constructor. This // makes a total of 130 BAT blocks, which will encompass // 16,640 blocks, for a file size of some 8.5 megabytes. - // + // // Naturally, we'll fake that out ... - // + // // map of blocks: // block 0: xbat block 0 // block 1: xbat block 1 @@ -1229,18 +1200,10 @@ public class TestBlockAllocationTableReader } } - /** - * Test fetchBlocks - * - * @exception IOException - */ - - public void testFetchBlocks() - throws IOException - { + public void testFetchBlocks() throws IOException { // strategy: - // + // // 1. set up a single BAT block from which to construct a // BAT. create nonsense blocks in the raw data block list // corresponding to the indices in the BAT block. @@ -1350,17 +1313,4 @@ public class TestBlockAllocationTableReader } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.BlockAllocationTableReader"); - junit.textui.TestRunner.run(TestBlockAllocationTableReader.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java index e13191a7f0..69dd5943bd 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.LittleEndian; @@ -34,28 +32,9 @@ import org.apache.poi.util.LittleEndianConsts; * * @author Marc Johnson */ +public final class TestBlockAllocationTableWriter extends TestCase { -public class TestBlockAllocationTableWriter - extends TestCase -{ - - /** - * Constructor TestBlockAllocationTableWriter - * - * @param name - */ - - public TestBlockAllocationTableWriter(String name) - { - super(name); - } - - /** - * Test the allocateSpace method. - */ - - public void testAllocateSpace() - { + public void testAllocateSpace() { BlockAllocationTableWriter table = new BlockAllocationTableWriter(); int[] blockSizes = @@ -71,15 +50,7 @@ public class TestBlockAllocationTableWriter } } - /** - * Test the createBlocks method - * - * @exception IOException - */ - - public void testCreateBlocks() - throws IOException - { + public void testCreateBlocks() { BlockAllocationTableWriter table = new BlockAllocationTableWriter(); table.allocateSpace(127); @@ -117,13 +88,8 @@ public class TestBlockAllocationTableWriter /** * Test content produced by BlockAllocationTableWriter - * - * @exception IOException */ - - public void testProduct() - throws IOException - { + public void testProduct() throws IOException { BlockAllocationTableWriter table = new BlockAllocationTableWriter(); for (int k = 1; k <= 22; k++) @@ -168,28 +134,16 @@ public class TestBlockAllocationTableWriter } } - private void verifyBlocksCreated(BlockAllocationTableWriter table, - int count) - throws IOException - { + private static void verifyBlocksCreated(BlockAllocationTableWriter table, int count){ ByteArrayOutputStream stream = new ByteArrayOutputStream(); - table.writeBlocks(stream); + try { + table.writeBlocks(stream); + } catch (IOException e) { + throw new RuntimeException(e); + } byte[] output = stream.toByteArray(); assertEquals(count * 512, output.length); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.BlockAllocationTableWriter"); - junit.textui.TestRunner.run(TestBlockAllocationTableWriter.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java b/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java index 194a951a1d..35715f65b1 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; @@ -33,31 +33,9 @@ import org.apache.poi.util.LittleEndianConsts; * * @author Marc Johnson */ +public final class TestBlockListImpl extends TestCase { -public class TestBlockListImpl - extends TestCase -{ - - /** - * Constructor TestBlockListImpl - * - * @param name - */ - - public TestBlockListImpl(String name) - { - super(name); - } - - /** - * test zap method - * - * @exception IOException - */ - - public void testZap() - throws IOException - { + public void testZap() throws IOException { BlockListImpl list = new BlockListImpl(); // verify that you can zap anything @@ -92,15 +70,7 @@ public class TestBlockListImpl } } - /** - * test remove method - * - * @exception IOException - */ - - public void testRemove() - throws IOException - { + public void testRemove() throws IOException { BlockListImpl list = new BlockListImpl(); RawDataBlock[] blocks = new RawDataBlock[ 5 ]; byte[] data = new byte[ 512 * 5 ]; @@ -159,15 +129,7 @@ public class TestBlockListImpl } } - /** - * test setBAT - * - * @exception IOException - */ - - public void testSetBAT() - throws IOException - { + public void testSetBAT() throws IOException { BlockListImpl list = new BlockListImpl(); list.setBAT(null); @@ -182,18 +144,10 @@ public class TestBlockListImpl } } - /** - * Test fetchBlocks - * - * @exception IOException - */ - - public void testFetchBlocks() - throws IOException - { + public void testFetchBlocks() throws IOException { // strategy: - // + // // 1. set up a single BAT block from which to construct a // BAT. create nonsense blocks in the raw data block list // corresponding to the indices in the BAT block. @@ -310,17 +264,4 @@ public class TestBlockListImpl } } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.storage.BlockListImpl"); - junit.textui.TestRunner.run(TestBlockListImpl.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReader.java b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReader.java index 738aeb11cd..611f8e9081 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReader.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReader.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,49 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; - -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.LittleEndianConsts; +import junit.framework.TestCase; /** * Class to test HeaderBlockReader functionality * * @author Marc Johnson */ +public final class TestHeaderBlockReader extends TestCase { -public class TestHeaderBlockReader - extends TestCase -{ - - /** - * Constructor TestHeaderBlockReader - * - * @param name - */ - - public TestHeaderBlockReader(String name) - { - super(name); - } - - /** - * Test creating a HeaderBlockReader - * - * @exception IOException - */ - - public void testConstructors() - throws IOException - { + public void testConstructors() throws IOException { byte[] content = { ( byte ) 0xD0, ( byte ) 0xCF, ( byte ) 0x11, ( byte ) 0xE0, @@ -231,17 +203,4 @@ public class TestHeaderBlockReader content[ index ] = ( byte ) (content[ index ] + 1); } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.HeaderBlockReader"); - junit.textui.TestRunner.run(TestHeaderBlockReader.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriter.java b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriter.java index 9fe75beca4..747482bb71 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriter.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; @@ -33,38 +31,19 @@ import org.apache.poi.util.LittleEndianConsts; * * @author Marc Johnson */ - -public class TestHeaderBlockWriter - extends TestCase -{ - - /** - * Constructor TestHeaderBlockWriter - * - * @param name - */ - - public TestHeaderBlockWriter(String name) - { - super(name); - } +public final class TestHeaderBlockWriter extends TestCase { /** * Test creating a HeaderBlockWriter - * - * @exception IOException */ - - public void testConstructors() - throws IOException - { + public void testConstructors() throws IOException { HeaderBlockWriter block = new HeaderBlockWriter(); ByteArrayOutputStream output = new ByteArrayOutputStream(512); block.writeBlocks(output); byte[] copy = output.toByteArray(); byte[] expected = - { + { // TODO - put this raw data in a better format ( byte ) 0xD0, ( byte ) 0xCF, ( byte ) 0x11, ( byte ) 0xE0, ( byte ) 0xA1, ( byte ) 0xB1, ( byte ) 0x1A, ( byte ) 0xE1, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, @@ -213,13 +192,8 @@ public class TestHeaderBlockWriter /** * Test setting the SBAT start block - * - * @exception IOException */ - - public void testSetSBATStart() - throws IOException - { + public void testSetSBATStart() throws IOException { HeaderBlockWriter block = new HeaderBlockWriter(); block.setSBATStart(0x01234567); @@ -368,13 +342,8 @@ public class TestHeaderBlockWriter /** * test setPropertyStart and getPropertyStart - * - * @exception IOException */ - - public void testSetPropertyStart() - throws IOException - { + public void testSetPropertyStart() throws IOException { HeaderBlockWriter block = new HeaderBlockWriter(); block.setPropertyStart(0x01234567); @@ -524,13 +493,8 @@ public class TestHeaderBlockWriter /** * test setting the BAT blocks; also tests getBATCount, * getBATArray, getXBATCount - * - * @exception IOException */ - - public void testSetBATBlocks() - throws IOException - { + public void testSetBATBlocks() throws IOException { // first, a small set of blocks HeaderBlockWriter block = new HeaderBlockWriter(); @@ -1009,17 +973,4 @@ public class TestHeaderBlockWriter assertEquals("XBAT End of chain", -2, LittleEndian.getInt(copy, offset)); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.HeaderBlockWriter"); - junit.textui.TestRunner.run(TestHeaderBlockWriter.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java index 64750b13e3..2bbec9e629 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,48 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -import java.util.*; - -import junit.framework.*; - -import org.apache.poi.poifs.property.Property; +import junit.framework.TestCase; /** * Class to test PropertyBlock functionality * * @author Marc Johnson */ +public final class TestPropertyBlock extends TestCase { -public class TestPropertyBlock - extends TestCase -{ - - /** - * Constructor TestPropertyBlock - * - * @param name - */ - - public TestPropertyBlock(String name) - { - super(name); - } - - /** - * Test constructing PropertyBlocks - * - * @exception IOException - */ - - public void testCreatePropertyBlocks() - throws IOException - { + public void testCreatePropertyBlocks() { // test with 0 properties List properties = new ArrayList(); @@ -178,7 +153,7 @@ public class TestPropertyBlock verifyCorrect(blocks, testblock); } - private void setDefaultBlock(byte [] testblock, int j) + private static void setDefaultBlock(byte [] testblock, int j) { int base = j * 128; int index = 0; @@ -204,15 +179,16 @@ public class TestPropertyBlock } } - private void verifyCorrect(BlockWritable [] blocks, byte [] testblock) - throws IOException - { + private static void verifyCorrect(BlockWritable[] blocks, byte[] testblock) { ByteArrayOutputStream stream = new ByteArrayOutputStream(512 * blocks.length); - for (int j = 0; j < blocks.length; j++) - { - blocks[ j ].writeBlocks(stream); + for (int j = 0; j < blocks.length; j++) { + try { + blocks[ j ].writeBlocks(stream); + } catch (IOException e) { + throw new RuntimeException(e); + } } byte[] output = stream.toByteArray(); @@ -223,17 +199,4 @@ public class TestPropertyBlock output[ j ]); } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.storage.PropertyBlock"); - junit.textui.TestRunner.run(TestPropertyBlock.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java index 4447ceed5d..5b632ce833 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,235 +14,212 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; -import java.util.Random; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Field; +import java.util.Random; + +import junit.framework.TestCase; import org.apache.poi.util.DummyPOILogger; -import junit.framework.*; - /** * Class to test RawDataBlock functionality * * @author Marc Johnson */ - -public class TestRawDataBlock - extends TestCase -{ +public final class TestRawDataBlock extends TestCase { static { - // We always want to use our own - // logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.DummyPOILogger" - ); + // We always want to use our own + // logger + System.setProperty( + "org.apache.poi.util.POILogger", + "org.apache.poi.util.DummyPOILogger" + ); } - /** - * Constructor TestRawDataBlock - * - * @param name - */ - public TestRawDataBlock(String name) - { - super(name); - } + /** + * Test creating a normal RawDataBlock + */ + public void testNormalConstructor() throws IOException { + byte[] data = new byte[ 512 ]; - /** - * Test creating a normal RawDataBlock - * - * @exception IOException - */ + for (int j = 0; j < 512; j++) + { + data[ j ] = ( byte ) j; + } + RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data)); - public void testNormalConstructor() - throws IOException - { - byte[] data = new byte[ 512 ]; + assertTrue("Should not be at EOF", !block.eof()); + byte[] out_data = block.getData(); - for (int j = 0; j < 512; j++) - { - data[ j ] = ( byte ) j; - } - RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data)); + assertEquals("Should be same length", data.length, out_data.length); + for (int j = 0; j < 512; j++) + { + assertEquals("Should be same value at offset " + j, data[ j ], + out_data[ j ]); + } + } - assertTrue("Should not be at EOF", !block.eof()); - byte[] out_data = block.getData(); + /** + * Test creating an empty RawDataBlock + */ + public void testEmptyConstructor() throws IOException { + byte[] data = new byte[ 0 ]; + RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data)); - assertEquals("Should be same length", data.length, out_data.length); - for (int j = 0; j < 512; j++) - { - assertEquals("Should be same value at offset " + j, data[ j ], - out_data[ j ]); - } - } + assertTrue("Should be at EOF", block.eof()); + try + { + block.getData(); + } + catch (IOException ignored) + { - /** - * Test creating an empty RawDataBlock - * - * @exception IOException - */ + // as expected + } + } - public void testEmptyConstructor() - throws IOException - { - byte[] data = new byte[ 0 ]; - RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data)); + /** + * Test creating a short RawDataBlock + * Will trigger a warning, but no longer an IOException, + * as people seem to have "valid" truncated files + */ + public void testShortConstructor() throws Exception { + // Get the logger to be used + DummyPOILogger logger = new DummyPOILogger(); + Field fld = RawDataBlock.class.getDeclaredField("log"); + fld.setAccessible(true); + fld.set(null, logger); + assertEquals(0, logger.logged.size()); - assertTrue("Should be at EOF", block.eof()); - try - { - block.getData(); - } - catch (IOException ignored) - { + // Test for various data sizes + for (int k = 1; k <= 512; k++) + { + byte[] data = new byte[ k ]; - // as expected - } - } + for (int j = 0; j < k; j++) + { + data[ j ] = ( byte ) j; + } + RawDataBlock block = null; - /** - * Test creating a short RawDataBlock - * Will trigger a warning, but no longer an IOException, - * as people seem to have "valid" truncated files - */ - public void testShortConstructor() throws Exception - { - // Get the logger to be used - DummyPOILogger logger = new DummyPOILogger(); - Field fld = RawDataBlock.class.getDeclaredField("log"); - fld.setAccessible(true); - fld.set(null, logger); - assertEquals(0, logger.logged.size()); - - // Test for various data sizes - for (int k = 1; k <= 512; k++) - { - byte[] data = new byte[ k ]; + logger.reset(); + assertEquals(0, logger.logged.size()); - for (int j = 0; j < k; j++) - { - data[ j ] = ( byte ) j; - } - RawDataBlock block = null; - - logger.reset(); - assertEquals(0, logger.logged.size()); - - // Have it created - block = new RawDataBlock(new ByteArrayInputStream(data)); - assertNotNull(block); - - // Check for the warning is there for <512 - if(k < 512) { - assertEquals( - "Warning on " + k + " byte short block", - 1, logger.logged.size() - ); - - // Build the expected warning message, and check - String bts = k + " byte"; - if(k > 1) { - bts += "s"; - } - - assertEquals( - "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", - (String)(logger.logged.get(0)) - ); - } else { - assertEquals(0, logger.logged.size()); - } - } - } - - /** - * Tests that when using a slow input stream, which - * won't return a full block at a time, we don't - * incorrectly think that there's not enough data - */ - public void testSlowInputStream() throws Exception { - // Get the logger to be used - DummyPOILogger logger = new DummyPOILogger(); - Field fld = RawDataBlock.class.getDeclaredField("log"); - fld.setAccessible(true); - fld.set(null, logger); - assertEquals(0, logger.logged.size()); - - // Test for various ok data sizes - for (int k = 1; k < 512; k++) { - byte[] data = new byte[ 512 ]; - for (int j = 0; j < data.length; j++) { - data[j] = (byte) j; - } - - // Shouldn't complain, as there is enough data, - // even if it dribbles through - RawDataBlock block = - new RawDataBlock(new SlowInputStream(data, k)); - assertFalse(block.eof()); - } - - // But if there wasn't enough data available, will - // complain - for (int k = 1; k < 512; k++) { - byte[] data = new byte[ 511 ]; - for (int j = 0; j < data.length; j++) { - data[j] = (byte) j; - } - - logger.reset(); - assertEquals(0, logger.logged.size()); - - // Should complain, as there isn't enough data - RawDataBlock block = - new RawDataBlock(new SlowInputStream(data, k)); - assertNotNull(block); - assertEquals( - "Warning on " + k + " byte short block", - 1, logger.logged.size() - ); - } - } - - /** - * An input stream which will return a maximum of - * a given number of bytes to read, and often claims - * not to have any data - */ - public static class SlowInputStream extends InputStream { - private Random rnd = new Random(); - private byte[] data; - private int chunkSize; - private int pos = 0; - - public SlowInputStream(byte[] data, int chunkSize) { - this.chunkSize = chunkSize; - this.data = data; - } - - /** - * 75% of the time, claim there's no data available - */ - private boolean claimNoData() { - if(rnd.nextFloat() < 0.25f) { - return false; - } - return true; - } - - public int read() throws IOException { + // Have it created + block = new RawDataBlock(new ByteArrayInputStream(data)); + assertNotNull(block); + + // Check for the warning is there for <512 + if(k < 512) { + assertEquals( + "Warning on " + k + " byte short block", + 1, logger.logged.size() + ); + + // Build the expected warning message, and check + String bts = k + " byte"; + if(k > 1) { + bts += "s"; + } + + assertEquals( + "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", + (String)(logger.logged.get(0)) + ); + } else { + assertEquals(0, logger.logged.size()); + } + } + } + + /** + * Tests that when using a slow input stream, which + * won't return a full block at a time, we don't + * incorrectly think that there's not enough data + */ + public void testSlowInputStream() throws Exception { + // Get the logger to be used + DummyPOILogger logger = new DummyPOILogger(); + Field fld = RawDataBlock.class.getDeclaredField("log"); + fld.setAccessible(true); + fld.set(null, logger); + assertEquals(0, logger.logged.size()); + + // Test for various ok data sizes + for (int k = 1; k < 512; k++) { + byte[] data = new byte[ 512 ]; + for (int j = 0; j < data.length; j++) { + data[j] = (byte) j; + } + + // Shouldn't complain, as there is enough data, + // even if it dribbles through + RawDataBlock block = + new RawDataBlock(new SlowInputStream(data, k)); + assertFalse(block.eof()); + } + + // But if there wasn't enough data available, will + // complain + for (int k = 1; k < 512; k++) { + byte[] data = new byte[ 511 ]; + for (int j = 0; j < data.length; j++) { + data[j] = (byte) j; + } + + logger.reset(); + assertEquals(0, logger.logged.size()); + + // Should complain, as there isn't enough data + RawDataBlock block = + new RawDataBlock(new SlowInputStream(data, k)); + assertNotNull(block); + assertEquals( + "Warning on " + k + " byte short block", + 1, logger.logged.size() + ); + } + } + + /** + * An input stream which will return a maximum of + * a given number of bytes to read, and often claims + * not to have any data + */ + public static class SlowInputStream extends InputStream { + private Random rnd = new Random(); + private byte[] data; + private int chunkSize; + private int pos = 0; + + public SlowInputStream(byte[] data, int chunkSize) { + this.chunkSize = chunkSize; + this.data = data; + } + + /** + * 75% of the time, claim there's no data available + */ + private boolean claimNoData() { + if(rnd.nextFloat() < 0.25f) { + return false; + } + return true; + } + + public int read() { if(pos >= data.length) { return -1; } int ret = data[pos]; pos++; - + if(ret < 0) ret += 256; return ret; } @@ -253,7 +229,7 @@ public class TestRawDataBlock * size, whichever is lower. * Quite often will simply claim to have no data */ - public int read(byte[] b, int off, int len) throws IOException { + public int read(byte[] b, int off, int len) { // Keep the length within the chunk size if(len > chunkSize) { len = chunkSize; @@ -261,40 +237,26 @@ public class TestRawDataBlock // Don't read off the end of the data if(pos + len > data.length) { len = data.length - pos; - + // Spot when we're out of data if(len == 0) { return -1; } } - + // 75% of the time, claim there's no data if(claimNoData()) { return 0; } - + // Copy, and return what we read System.arraycopy(data, pos, b, off, len); pos += len; return len; } - public int read(byte[] b) throws IOException { + public int read(byte[] b) { return read(b, 0, b.length); } - - } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.storage.RawDataBlock"); - junit.textui.TestRunner.run(TestRawDataBlock.class); - } + } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java index 81ee0501c4..ec07c38649 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,27 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.lang.reflect.Field; +import junit.framework.TestCase; + import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.DummyPOILogger; -import junit.framework.*; - /** * Class to test RawDataBlockList functionality * * @author Marc Johnson */ - -public class TestRawDataBlockList - extends TestCase -{ +public final class TestRawDataBlockList extends TestCase { static { // We always want to use our own // logger @@ -45,24 +41,10 @@ public class TestRawDataBlockList ); } - /** - * Constructor TestRawDataBlockList - * - * @param name - */ - public TestRawDataBlockList(String name) - { - super(name); - } - /** * Test creating a normal RawDataBlockList - * - * @exception IOException */ - public void testNormalConstructor() - throws IOException - { + public void testNormalConstructor() throws IOException { byte[] data = new byte[ 2560 ]; for (int j = 0; j < 2560; j++) @@ -74,29 +56,22 @@ public class TestRawDataBlockList /** * Test creating an empty RawDataBlockList - * - * @exception IOException */ - - public void testEmptyConstructor() - throws IOException - { + public void testEmptyConstructor() throws IOException { new RawDataBlockList(new ByteArrayInputStream(new byte[ 0 ]), POIFSConstants.BIG_BLOCK_SIZE); } /** * Test creating a short RawDataBlockList */ - - public void testShortConstructor() throws Exception - { + public void testShortConstructor() throws Exception { // Get the logger to be used DummyPOILogger logger = new DummyPOILogger(); Field fld = RawDataBlock.class.getDeclaredField("log"); fld.setAccessible(true); fld.set(null, logger); assertEquals(0, logger.logged.size()); - + // Test for various short sizes for (int k = 2049; k < 2560; k++) { @@ -113,17 +88,4 @@ public class TestRawDataBlockList assertEquals(1, logger.logged.size()); } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out - .println("Testing org.apache.poi.poifs.storage.RawDataBlockList"); - junit.textui.TestRunner.run(TestRawDataBlockList.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableReader.java b/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableReader.java index 4d4254a91e..c88d2957d2 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableReader.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableReader.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.property.PropertyTable; @@ -34,35 +31,13 @@ import org.apache.poi.poifs.property.RootProperty; * * @author Marc Johnson */ +public final class TestSmallBlockTableReader extends TestCase { -public class TestSmallBlockTableReader - extends TestCase -{ - - /** - * Constructor TestSmallBlockTableReader - * - * @param name - */ - - public TestSmallBlockTableReader(String name) - { - super(name); - } - - /** - * test reading constructor - * - * @exception IOException - */ - - public void testReadingConstructor() - throws IOException - { + public void testReadingConstructor() throws IOException { // first, we need the raw data blocks byte[] raw_data_array = - { + { // TODO - put this raw data in a better format ( byte ) 0x52, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00, ( byte ) 0x74, ( byte ) 0x00, ( byte ) 0x20, ( byte ) 0x00, ( byte ) 0x45, ( byte ) 0x00, @@ -2130,17 +2105,4 @@ public class TestSmallBlockTableReader SmallBlockTableReader.getSmallDocumentBlocks(data_blocks, root, 14); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.SmallBlockTableReader"); - junit.textui.TestRunner.run(TestSmallBlockTableReader.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableWriter.java b/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableWriter.java index 981b244102..5b2534b28b 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableWriter.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestSmallBlockTableWriter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -import java.util.*; - -import junit.framework.*; +import junit.framework.TestCase; import org.apache.poi.poifs.filesystem.POIFSDocument; import org.apache.poi.poifs.property.PropertyTable; @@ -34,32 +33,10 @@ import org.apache.poi.poifs.property.RootProperty; * * @author Marc Johnson */ +public final class TestSmallBlockTableWriter extends TestCase { -public class TestSmallBlockTableWriter - extends TestCase -{ - - /** - * Constructor TestSmallBlockTableWriter - * - * @param name - */ - - public TestSmallBlockTableWriter(String name) - { - super(name); - } - - /** - * test writing constructor - * - * @exception IOException - */ - - public void testWritingConstructor() - throws IOException - { - List documents = new ArrayList(); + public void testWritingConstructor() throws IOException { + List documents = new ArrayList(); documents.add( new POIFSDocument( @@ -113,17 +90,4 @@ public class TestSmallBlockTableWriter sbtw.setStartBlock(start_block); assertEquals(start_block, root.getStartBlock()); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.SmallBlockTableWriter"); - junit.textui.TestRunner.run(TestSmallBlockTableWriter.class); - } } diff --git a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlockList.java b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlockList.java index 6901112f96..02403a3624 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlockList.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlockList.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,44 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.poifs.storage; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test SmallDocumentBlockList functionality * * @author Marc Johnson */ +public final class TestSmallDocumentBlockList extends TestCase { -public class TestSmallDocumentBlockList - extends TestCase -{ - - /** - * Constructor TestSmallDocumentBlockList - * - * @param name - */ - - public TestSmallDocumentBlockList(String name) - { - super(name); - } - - /** - * Test creating a SmallDocumentBlockList - * - * @exception IOException - */ - - public void testConstructor() - throws IOException - { + public void testConstructor() throws IOException { byte[] data = new byte[ 2560 ]; for (int j = 0; j < 2560; j++) @@ -85,17 +62,4 @@ public class TestSmallDocumentBlockList // it better have thrown one!! } } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println( - "Testing org.apache.poi.poifs.storage.SmallDocumentBlockList"); - junit.textui.TestRunner.run(TestSmallDocumentBlockList.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestBinaryTree.java b/src/testcases/org/apache/poi/util/TestBinaryTree.java index 7f53623bc8..f9474adee1 100644 --- a/src/testcases/org/apache/poi/util/TestBinaryTree.java +++ b/src/testcases/org/apache/poi/util/TestBinaryTree.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -28,28 +27,9 @@ import java.util.*; * * @author Marc Johnson (mjohnson at apache dot org) */ +public final class TestBinaryTree extends TestCase { -public class TestBinaryTree - extends TestCase -{ - - /** - * constructor - * - * @param name - */ - - public TestBinaryTree(final String name) - { - super(name); - } - - /** - * test size() method - */ - - public void testSize() - { + public void testSize() { Map m = new BinaryTree(); assertEquals(0, m.size()); @@ -74,12 +54,7 @@ public class TestBinaryTree } } - /** - * test IsEmpty() method - */ - - public void testIsEmpty() - { + public void testIsEmpty() { Map m = new BinaryTree(); assertTrue(m.isEmpty()); @@ -118,12 +93,7 @@ public class TestBinaryTree } } - /** - * test containsKey() method - */ - - public void testContainsKey() - { + public void testContainsKey() { Map m = new BinaryTree(); try @@ -166,12 +136,7 @@ public class TestBinaryTree } } - /** - * test containsValue() method - */ - - public void testContainsValue() - { + public void testContainsValue() { Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -187,12 +152,7 @@ public class TestBinaryTree } } - /** - * test get() method - */ - - public void testGet() - { + public void testGet() { Map m = new BinaryTree(); try @@ -236,12 +196,7 @@ public class TestBinaryTree } } - /** - * test put() method - */ - - public void testPut() - { + public void testPut() { Map m = new BinaryTree(); try @@ -291,12 +246,7 @@ public class TestBinaryTree } } - /** - * test remove() method - */ - - public void testRemove() - { + public void testRemove() { BinaryTree m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -350,12 +300,7 @@ public class TestBinaryTree assertTrue(m.isEmpty()); } - /** - * Method testPutAll - */ - - public void testPutAll() - { + public void testPutAll() { Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -419,12 +364,7 @@ public class TestBinaryTree } } - /** - * test clear() method - */ - - public void testClear() - { + public void testClear() { Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -448,12 +388,7 @@ public class TestBinaryTree } } - /** - * test keySet() method - */ - - public void testKeySet() - { + public void testKeySet() { testKeySet(new BinaryTree()); Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -600,12 +535,7 @@ public class TestBinaryTree assertTrue(m.size() == 0); } - /** - * test values() method - */ - - public void testValues() - { + public void testValues() { testValues(new BinaryTree()); Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -741,12 +671,7 @@ public class TestBinaryTree assertEquals(0, m.size()); } - /** - * test entrySet() method - */ - - public void testEntrySet() - { + public void testEntrySet() { testEntrySet(new BinaryTree()); Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -820,12 +745,7 @@ public class TestBinaryTree } } - /** - * Method testEquals - */ - - public void testEquals() - { + public void testEquals() { Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -871,12 +791,7 @@ public class TestBinaryTree assertEquals(m, m1); } - /** - * test hashCode() method - */ - - public void testHashCode() - { + public void testHashCode() { Map m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -893,12 +808,7 @@ public class TestBinaryTree assertTrue(m.hashCode() == m1.hashCode()); } - /** - * test constructors - */ - - public void testConstructors() - { + public void testConstructors() { BinaryTree m = new BinaryTree(); assertTrue(m.isEmpty()); @@ -995,12 +905,7 @@ public class TestBinaryTree } } - /** - * test getKeyForValue() method - */ - - public void testGetKeyForValue() - { + public void testGetKeyForValue() { BinaryTree m = new BinaryTree(); try @@ -1044,12 +949,7 @@ public class TestBinaryTree } } - /** - * test removeValue() method - */ - - public void testRemoveValue() - { + public void testRemoveValue() { BinaryTree m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -1099,12 +999,7 @@ public class TestBinaryTree assertTrue(m.isEmpty()); } - /** - * test entrySetByValue() method - */ - - public void testEntrySetByValue() - { + public void testEntrySetByValue() { testEntrySetByValue(new BinaryTree()); BinaryTree m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -1178,12 +1073,7 @@ public class TestBinaryTree } } - /** - * test keySetByValue() method - */ - - public void testKeySetByValue() - { + public void testKeySetByValue() { testKeySetByValue(new BinaryTree()); BinaryTree m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -1330,12 +1220,7 @@ public class TestBinaryTree assertTrue(m.size() == 0); } - /** - * test valuesByValue() method - */ - - public void testValuesByValue() - { + public void testValuesByValue() { testValuesByValue(new BinaryTree()); BinaryTree m = new BinaryTree(); LocalTestNode nodes[] = makeLocalNodes(); @@ -1472,8 +1357,7 @@ public class TestBinaryTree } /* ********** START helper methods ********** */ - private void testKeySet(final Map m) - { + private static void testKeySet(final Map m) { Set s = m.keySet(); assertEquals(m.size(), s.size()); @@ -1699,8 +1583,7 @@ public class TestBinaryTree assertTrue(s.hashCode() == hs.hashCode()); } - private void testKeySetByValue(final BinaryTree m) - { + private static void testKeySetByValue(final BinaryTree m) { Set s = m.keySetByValue(); assertEquals(m.size(), s.size()); @@ -1922,8 +1805,7 @@ public class TestBinaryTree assertTrue(s.hashCode() == hs.hashCode()); } - private void testValues(Map m) - { + private static void testValues(Map m) { Collection s = m.values(); assertEquals(m.size(), s.size()); @@ -2140,8 +2022,7 @@ public class TestBinaryTree assertTrue(!hs.equals(s)); } - private void testValuesByValue(BinaryTree m) - { + private static void testValuesByValue(BinaryTree m) { Collection s = m.valuesByValue(); assertEquals(m.size(), s.size()); @@ -2325,8 +2206,7 @@ public class TestBinaryTree assertTrue(!hs.equals(s)); } - private void testEntrySet(Map m) - { + private static void testEntrySet(Map m) { Set s = m.entrySet(); assertEquals(m.size(), s.size()); @@ -2539,8 +2419,7 @@ public class TestBinaryTree assertTrue(s.hashCode() == hs.hashCode()); } - private void testEntrySetByValue(BinaryTree m) - { + private static void testEntrySetByValue(BinaryTree m) { Set s = m.entrySetByValue(); assertEquals(m.size(), s.size()); @@ -2763,17 +2642,4 @@ public class TestBinaryTree } return nodes; } - - /* ********** END helper methods ********** */ - - /** - * Method main - * - * @param unused_args - */ - - public static void main(final String unused_args[]) - { - junit.textui.TestRunner.run(TestBinaryTree.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestBitField.java b/src/testcases/org/apache/poi/util/TestBitField.java index 26f641411b..ef55ab7451 100644 --- a/src/testcases/org/apache/poi/util/TestBitField.java +++ b/src/testcases/org/apache/poi/util/TestBitField.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -27,66 +25,32 @@ import junit.framework.*; * @author Marc Johnson * @author Glen Stampoultzis (gstamp@iprimus.com.au) */ - -public class TestBitField - extends TestCase -{ +public final class TestBitField extends TestCase { private static BitField bf_multi = BitFieldFactory.getInstance(0x3F80); private static BitField bf_single = BitFieldFactory.getInstance(0x4000); - /** - * Constructor TestBitField - * - * @param name - */ - - public TestBitField(String name) - { - super(name); - } - - /** - * test the getValue() method - */ - - public void testGetValue() - { + public void testGetValue() { assertEquals(bf_multi.getValue(-1), 127); assertEquals(bf_multi.getValue(0), 0); assertEquals(bf_single.getValue(-1), 1); assertEquals(bf_single.getValue(0), 0); } - /** - * test the getShortValue() method - */ - - public void testGetShortValue() - { + public void testGetShortValue() { assertEquals(bf_multi.getShortValue(( short ) -1), ( short ) 127); assertEquals(bf_multi.getShortValue(( short ) 0), ( short ) 0); assertEquals(bf_single.getShortValue(( short ) -1), ( short ) 1); assertEquals(bf_single.getShortValue(( short ) 0), ( short ) 0); } - /** - * test the getRawValue() method - */ - - public void testGetRawValue() - { + public void testGetRawValue() { assertEquals(bf_multi.getRawValue(-1), 0x3F80); assertEquals(bf_multi.getRawValue(0), 0); assertEquals(bf_single.getRawValue(-1), 0x4000); assertEquals(bf_single.getRawValue(0), 0); } - /** - * test the getShortRawValue() method - */ - - public void testGetShortRawValue() - { + public void testGetShortRawValue() { assertEquals(bf_multi.getShortRawValue(( short ) -1), ( short ) 0x3F80); assertEquals(bf_multi.getShortRawValue(( short ) 0), ( short ) 0); @@ -95,12 +59,7 @@ public class TestBitField assertEquals(bf_single.getShortRawValue(( short ) 0), ( short ) 0); } - /** - * test the isSet() method - */ - - public void testIsSet() - { + public void testIsSet() { assertTrue(!bf_multi.isSet(0)); for (int j = 0x80; j <= 0x3F80; j += 0x80) { @@ -110,12 +69,7 @@ public class TestBitField assertTrue(bf_single.isSet(0x4000)); } - /** - * test the isAllSet() method - */ - - public void testIsAllSet() - { + public void testIsAllSet() { for (int j = 0; j < 0x3F80; j += 0x80) { assertTrue(!bf_multi.isAllSet(j)); @@ -125,12 +79,7 @@ public class TestBitField assertTrue(bf_single.isAllSet(0x4000)); } - /** - * test the setValue() method - */ - - public void testSetValue() - { + public void testSetValue() { for (int j = 0; j < 128; j++) { assertEquals(bf_multi.getValue(bf_multi.setValue(0, j)), j); @@ -149,12 +98,7 @@ public class TestBitField assertEquals(bf_single.setValue(0x4000, 2), 0); } - /** - * test the setShortValue() method - */ - - public void testSetShortValue() - { + public void testSetShortValue() { for (int j = 0; j < 128; j++) { assertEquals(bf_multi @@ -181,8 +125,7 @@ public class TestBitField ( short ) 0); } - public void testByte() - { + public void testByte() { assertEquals(1, BitFieldFactory.getInstance(1).setByteBoolean(( byte ) 0, true)); assertEquals(2, BitFieldFactory.getInstance(2).setByteBoolean(( byte ) 0, true)); assertEquals(4, BitFieldFactory.getInstance(4).setByteBoolean(( byte ) 0, true)); @@ -208,64 +151,34 @@ public class TestBitField assertEquals(false, BitFieldFactory.getInstance(0x40).isSet(clearedBit)); } - /** - * test the clear() method - */ - - public void testClear() - { + public void testClear() { assertEquals(bf_multi.clear(-1), 0xFFFFC07F); assertEquals(bf_single.clear(-1), 0xFFFFBFFF); } - /** - * test the clearShort() method - */ - - public void testClearShort() - { + public void testClearShort() { assertEquals(bf_multi.clearShort(( short ) -1), ( short ) 0xC07F); assertEquals(bf_single.clearShort(( short ) -1), ( short ) 0xBFFF); } - /** - * test the set() method - */ - - public void testSet() - { + public void testSet() { assertEquals(bf_multi.set(0), 0x3F80); assertEquals(bf_single.set(0), 0x4000); } - /** - * test the setShort() method - */ - - public void testSetShort() - { + public void testSetShort() { assertEquals(bf_multi.setShort(( short ) 0), ( short ) 0x3F80); assertEquals(bf_single.setShort(( short ) 0), ( short ) 0x4000); } - /** - * test the setBoolean() method - */ - - public void testSetBoolean() - { + public void testSetBoolean() { assertEquals(bf_multi.set(0), bf_multi.setBoolean(0, true)); assertEquals(bf_single.set(0), bf_single.setBoolean(0, true)); assertEquals(bf_multi.clear(-1), bf_multi.setBoolean(-1, false)); assertEquals(bf_single.clear(-1), bf_single.setBoolean(-1, false)); } - /** - * test the setShortBoolean() method - */ - - public void testSetShortBoolean() - { + public void testSetShortBoolean() { assertEquals(bf_multi.setShort(( short ) 0), bf_multi.setShortBoolean(( short ) 0, true)); assertEquals(bf_single.setShort(( short ) 0), @@ -275,16 +188,4 @@ public class TestBitField assertEquals(bf_single.clearShort(( short ) -1), bf_single.setShortBoolean(( short ) -1, false)); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println("Testing util.BitField functionality"); - junit.textui.TestRunner.run(TestBitField.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestByteField.java b/src/testcases/org/apache/poi/util/TestByteField.java index 2afeb06de5..2c3c4996d7 100644 --- a/src/testcases/org/apache/poi/util/TestByteField.java +++ b/src/testcases/org/apache/poi/util/TestByteField.java @@ -15,46 +15,27 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; -import junit.framework.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import java.io.*; +import junit.framework.TestCase; /** * Title: Unit test for ByteField class * Description: Unit test for ByteField class * @author Marc Johnson (mjohnson at apache dot org) */ +public final class TestByteField extends TestCase { -public class TestByteField - extends TestCase -{ - - /** - * Constructor - * - * @param name - */ - - public TestByteField(String name) - { - super(name); - } - - static private final byte[] _test_array = + private static final byte[] _test_array = { Byte.MIN_VALUE, ( byte ) -1, ( byte ) 0, ( byte ) 1, Byte.MAX_VALUE }; - /** - * Test constructors. - */ - - public void testConstructors() - { + public void testConstructors() { try { new ByteField(-1); @@ -114,12 +95,7 @@ public class TestByteField } } - /** - * Test set() methods - */ - - public void testSet() - { + public void testSet() { ByteField field = new ByteField(0); byte[] array = new byte[ 1 ]; @@ -134,12 +110,7 @@ public class TestByteField } } - /** - * Test readFromBytes - */ - - public void testReadFromBytes() - { + public void testReadFromBytes() { ByteField field = new ByteField(1); byte[] array = new byte[ 1 ]; @@ -162,15 +133,7 @@ public class TestByteField } } - /** - * Test readFromStream - * - * @exception IOException - */ - - public void testReadFromStream() - throws IOException - { + public void testReadFromStream() throws IOException { ByteField field = new ByteField(0); byte[] buffer = new byte[ _test_array.length ]; @@ -184,12 +147,7 @@ public class TestByteField } } - /** - * test writeToBytes - */ - - public void testWriteToBytes() - { + public void testWriteToBytes() { ByteField field = new ByteField(0); byte[] array = new byte[ 1 ]; @@ -200,16 +158,4 @@ public class TestByteField assertEquals("testing ", _test_array[ j ], array[ 0 ]); } } - - /** - * Main - * - * @param ignored_args - */ - - public static void main(String [] ignored_args) - { - System.out.println("Testing util.ByteField functionality"); - junit.textui.TestRunner.run(TestByteField.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestIntList.java b/src/testcases/org/apache/poi/util/TestIntList.java index c67377e04c..1037c2eaf3 100644 --- a/src/testcases/org/apache/poi/util/TestIntList.java +++ b/src/testcases/org/apache/poi/util/TestIntList.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,39 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test IntList * * @author Marc Johnson */ +public final class TestIntList extends TestCase { -public class TestIntList - extends TestCase -{ - - /** - * Constructor TestIntList - * - * @param name - */ - - public TestIntList(String name) - { - super(name); - } - - /** - * test the various IntListconstructors - */ - - public void testConstructors() - { + public void testConstructors() { IntList list = new IntList(); assertTrue(list.isEmpty()); @@ -61,12 +40,7 @@ public class TestIntList assertTrue(list3.isEmpty()); } - /** - * test the add method - */ - - public void testAdd() - { + public void testAdd() { IntList list = new IntList(); int[] testArray = { @@ -144,12 +118,7 @@ public class TestIntList } } - /** - * test the addAll method - */ - - public void testAddAll() - { + public void testAddAll() { IntList list = new IntList(); for (int j = 0; j < 5; j++) @@ -223,12 +192,7 @@ public class TestIntList assertEquals(list.get(4), empty.get(14)); } - /** - * test the clear method - */ - - public void testClear() - { + public void testClear() { IntList list = new IntList(); for (int j = 0; j < 500; j++) @@ -249,12 +213,7 @@ public class TestIntList } } - /** - * test the contains method - */ - - public void testContains() - { + public void testContains() { IntList list = new IntList(); for (int j = 0; j < 1000; j += 2) @@ -274,12 +233,7 @@ public class TestIntList } } - /** - * test the containsAll method - */ - - public void testContainsAll() - { + public void testContainsAll() { IntList list = new IntList(); assertTrue(list.containsAll(list)); @@ -299,12 +253,7 @@ public class TestIntList assertTrue(!list.containsAll(list2)); } - /** - * test the equals method - */ - - public void testEquals() - { + public void testEquals() { IntList list = new IntList(); assertEquals(list, list); @@ -328,12 +277,7 @@ public class TestIntList assertTrue(!list2.equals(list)); } - /** - * test the get method - */ - - public void testGet() - { + public void testGet() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -360,12 +304,7 @@ public class TestIntList } } - /** - * test the indexOf method - */ - - public void testIndexOf() - { + public void testIndexOf() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -385,12 +324,7 @@ public class TestIntList } } - /** - * test the isEmpty method - */ - - public void testIsEmpty() - { + public void testIsEmpty() { IntList list1 = new IntList(); IntList list2 = new IntList(1000); IntList list3 = new IntList(list1); @@ -412,12 +346,7 @@ public class TestIntList assertTrue(list3.isEmpty()); } - /** - * test the lastIndexOf method - */ - - public void testLastIndexOf() - { + public void testLastIndexOf() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -437,12 +366,7 @@ public class TestIntList } } - /** - * test the remove method - */ - - public void testRemove() - { + public void testRemove() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -475,12 +399,7 @@ public class TestIntList } } - /** - * test the removeValue method - */ - - public void testRemoveValue() - { + public void testRemoveValue() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -498,12 +417,7 @@ public class TestIntList } } - /** - * test the removeAll method - */ - - public void testRemoveAll() - { + public void testRemoveAll() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -535,12 +449,7 @@ public class TestIntList assertTrue(listCopy.isEmpty()); } - /** - * test the retainAll method - */ - - public void testRetainAll() - { + public void testRetainAll() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -572,12 +481,7 @@ public class TestIntList assertTrue(listCopy.isEmpty()); } - /** - * test the set method - */ - - public void testSet() - { + public void testSet() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -605,12 +509,7 @@ public class TestIntList } } - /** - * test the size method - */ - - public void testSize() - { + public void testSize() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -627,12 +526,7 @@ public class TestIntList } } - /** - * test the toArray method - */ - - public void testToArray() - { + public void testToArray() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) @@ -672,16 +566,4 @@ public class TestIntList assertEquals(a5[ j ], list.get(j)); } } - - /** - * main method to run the unit tests - * - * @param unused_args - */ - - public static void main(String [] unused_args) - { - System.out.println("Testing util.IntList functionality"); - junit.textui.TestRunner.run(TestIntList.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestIntegerField.java b/src/testcases/org/apache/poi/util/TestIntegerField.java index 861f411426..a26f09cca0 100644 --- a/src/testcases/org/apache/poi/util/TestIntegerField.java +++ b/src/testcases/org/apache/poi/util/TestIntegerField.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,46 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; -import junit.framework.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; -import java.io.*; +import junit.framework.TestCase; /** * Test IntegerField code * * @author Marc Johnson (mjohnson at apache dot org) */ +public final class TestIntegerField extends TestCase { -public class TestIntegerField - extends TestCase -{ - - /** - * Constructor - * - * @param name - */ - - public TestIntegerField(String name) - { - super(name); - } - - static private final int[] _test_array = + private static final int[] _test_array = { Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE }; - /** - * Test constructors. - */ - - public void testConstructors() - { + public void testConstructors() { try { new IntegerField(-1); @@ -117,12 +97,7 @@ public class TestIntegerField } } - /** - * Test set() methods - */ - - public void testSet() - { + public void testSet() { IntegerField field = new IntegerField(0); byte[] array = new byte[ 4 ]; @@ -147,12 +122,7 @@ public class TestIntegerField } } - /** - * Test readFromBytes - */ - - public void testReadFromBytes() - { + public void testReadFromBytes() { IntegerField field = new IntegerField(1); byte[] array = new byte[ 4 ]; @@ -178,15 +148,7 @@ public class TestIntegerField } } - /** - * Test readFromStream - * - * @exception IOException - */ - - public void testReadFromStream() - throws IOException - { + public void testReadFromStream() throws IOException { IntegerField field = new IntegerField(0); byte[] buffer = new byte[ _test_array.length * 4 ]; @@ -206,12 +168,7 @@ public class TestIntegerField } } - /** - * test writeToBytes - */ - - public void testWriteToBytes() - { + public void testWriteToBytes() { IntegerField field = new IntegerField(0); byte[] array = new byte[ 4 ]; @@ -228,16 +185,4 @@ public class TestIntegerField assertEquals("testing ", _test_array[ j ], val); } } - - /** - * Main - * - * @param args - */ - - public static void main(String [] args) - { - System.out.println("Testing util.IntegerField functionality"); - junit.textui.TestRunner.run(TestIntegerField.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestPOILogFactory.java b/src/testcases/org/apache/poi/util/TestPOILogFactory.java index 27fddabeac..115ec733e7 100644 --- a/src/testcases/org/apache/poi/util/TestPOILogFactory.java +++ b/src/testcases/org/apache/poi/util/TestPOILogFactory.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,43 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; import junit.framework.TestCase; -import java.io.IOException; - /** * @author Marc Johnson (mjohnson at apache dot org) * @author Glen Stampoultzis (glens at apache.org) * @author Nicola Ken Barozzi (nicolaken at apache.org) */ +public final class TestPOILogFactory extends TestCase { -public class TestPOILogFactory - extends TestCase -{ - /** - * Creates new TestPOILogFactory - * - * @param name - */ - - public TestPOILogFactory( String name ) - { - super( name ); - } /** * test log creation - * - * @exception IOException */ - - public void testLog() - throws IOException - { + public void testLog() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging // output is done. @@ -72,16 +51,4 @@ public class TestPOILogFactory l2.log( POILogger.DEBUG, "testing cat org.apache.poi.hdf.*:DEBUG" ); } - - /** - * main method to run the unit tests - * - * @param ignored_args - */ - - public static void main( String[] ignored_args ) - { - System.out.println( "Testing basic util.POILogFactory functionality" ); - junit.textui.TestRunner.run( TestPOILogFactory.class ); - } } diff --git a/src/testcases/org/apache/poi/util/TestPOILogger.java b/src/testcases/org/apache/poi/util/TestPOILogger.java index 6dfa1d7db6..90732d3637 100644 --- a/src/testcases/org/apache/poi/util/TestPOILogger.java +++ b/src/testcases/org/apache/poi/util/TestPOILogger.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -28,31 +27,12 @@ import junit.framework.TestCase; * @author Marc Johnson (mjohnson at apache dot org) * @author Nicola Ken Barozzi (nicolaken at apache.org) */ - -public class TestPOILogger - extends TestCase -{ - /** - * Constructor TestPOILogger - * - * - * @param s - * - */ - - public TestPOILogger( String s ) - { - super( s ); - } +public final class TestPOILogger extends TestCase { /** * Test different types of log output. - * - * @exception Exception */ - public void testVariousLogTypes() - throws Exception - { + public void testVariousLogTypes() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging // output is done. diff --git a/src/testcases/org/apache/poi/util/TestShortField.java b/src/testcases/org/apache/poi/util/TestShortField.java index 999a735f88..dd93c1a48d 100644 --- a/src/testcases/org/apache/poi/util/TestShortField.java +++ b/src/testcases/org/apache/poi/util/TestShortField.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -28,34 +26,15 @@ import java.io.*; * * @author Marc Johnson (mjohnson at apache dot org) */ +public final class TestShortField extends TestCase { -public class TestShortField - extends TestCase -{ - - /** - * Constructor - * - * @param name - */ - - public TestShortField(String name) - { - super(name); - } - - static private final short[] _test_array = + private static final short[] _test_array = { Short.MIN_VALUE, ( short ) -1, ( short ) 0, ( short ) 1, Short.MAX_VALUE }; - /** - * Test constructors. - */ - - public void testConstructors() - { + public void testConstructors() { try { new ShortField(-1); @@ -116,12 +95,7 @@ public class TestShortField } } - /** - * Test set() methods - */ - - public void testSet() - { + public void testSet() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ]; @@ -140,12 +114,7 @@ public class TestShortField } } - /** - * Test readFromBytes - */ - - public void testReadFromBytes() - { + public void testReadFromBytes() { ShortField field = new ShortField(1); byte[] array = new byte[ 2 ]; @@ -169,15 +138,7 @@ public class TestShortField } } - /** - * Test readFromStream - * - * @exception IOException - */ - - public void testReadFromStream() - throws IOException - { + public void testReadFromStream() throws IOException { ShortField field = new ShortField(0); byte[] buffer = new byte[ _test_array.length * 2 ]; @@ -195,12 +156,7 @@ public class TestShortField } } - /** - * test writeToBytes - */ - - public void testWriteToBytes() - { + public void testWriteToBytes() { ShortField field = new ShortField(0); byte[] array = new byte[ 2 ]; @@ -215,16 +171,4 @@ public class TestShortField assertEquals("testing ", _test_array[ j ], val); } } - - /** - * Main - * - * @param args - */ - - public static void main(String [] args) - { - System.out.println("Testing util.ShortField functionality"); - junit.textui.TestRunner.run(TestShortField.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestShortList.java b/src/testcases/org/apache/poi/util/TestShortList.java index aeae2761df..1605b51ff3 100644 --- a/src/testcases/org/apache/poi/util/TestShortList.java +++ b/src/testcases/org/apache/poi/util/TestShortList.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,39 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; -import junit.framework.*; +import junit.framework.TestCase; /** * Class to test ShortList * * @author Marc Johnson */ +public final class TestShortList extends TestCase { -public class TestShortList - extends TestCase -{ - - /** - * Constructor TestShortList - * - * @param name - */ - - public TestShortList(String name) - { - super(name); - } - - /** - * test the various ShortListconstructors - */ - - public void testConstructors() - { + public void testConstructors() { ShortList list = new ShortList(); assertTrue(list.isEmpty()); @@ -61,12 +40,7 @@ public class TestShortList assertTrue(list3.isEmpty()); } - /** - * test the add method - */ - - public void testAdd() - { + public void testAdd() { ShortList list = new ShortList(); short[] testArray = { @@ -144,12 +118,7 @@ public class TestShortList } } - /** - * test the addAll method - */ - - public void testAddAll() - { + public void testAddAll() { ShortList list = new ShortList(); for (short j = 0; j < 5; j++) @@ -223,12 +192,7 @@ public class TestShortList assertEquals(list.get(4), empty.get(14)); } - /** - * test the clear method - */ - - public void testClear() - { + public void testClear() { ShortList list = new ShortList(); for (short j = 0; j < 500; j++) @@ -249,12 +213,7 @@ public class TestShortList } } - /** - * test the contains method - */ - - public void testContains() - { + public void testContains() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j += 2) @@ -274,12 +233,7 @@ public class TestShortList } } - /** - * test the containsAll method - */ - - public void testContainsAll() - { + public void testContainsAll() { ShortList list = new ShortList(); assertTrue(list.containsAll(list)); @@ -299,12 +253,7 @@ public class TestShortList assertTrue(!list.containsAll(list2)); } - /** - * test the equals method - */ - - public void testEquals() - { + public void testEquals() { ShortList list = new ShortList(); assertEquals(list, list); @@ -328,12 +277,7 @@ public class TestShortList assertTrue(!list2.equals(list)); } - /** - * test the get method - */ - - public void testGet() - { + public void testGet() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -360,12 +304,7 @@ public class TestShortList } } - /** - * test the indexOf method - */ - - public void testIndexOf() - { + public void testIndexOf() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -385,12 +324,7 @@ public class TestShortList } } - /** - * test the isEmpty method - */ - - public void testIsEmpty() - { + public void testIsEmpty() { ShortList list1 = new ShortList(); ShortList list2 = new ShortList(1000); ShortList list3 = new ShortList(list1); @@ -412,12 +346,7 @@ public class TestShortList assertTrue(list3.isEmpty()); } - /** - * test the lastIndexOf method - */ - - public void testLastIndexOf() - { + public void testLastIndexOf() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -437,12 +366,7 @@ public class TestShortList } } - /** - * test the remove method - */ - - public void testRemove() - { + public void testRemove() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -476,12 +400,7 @@ public class TestShortList } } - /** - * test the removeValue method - */ - - public void testRemoveValue() - { + public void testRemoveValue() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -499,12 +418,7 @@ public class TestShortList } } - /** - * test the removeAll method - */ - - public void testRemoveAll() - { + public void testRemoveAll() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -536,12 +450,7 @@ public class TestShortList assertTrue(listCopy.isEmpty()); } - /** - * test the retainAll method - */ - - public void testRetainAll() - { + public void testRetainAll() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -573,12 +482,7 @@ public class TestShortList assertTrue(listCopy.isEmpty()); } - /** - * test the set method - */ - - public void testSet() - { + public void testSet() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -606,12 +510,7 @@ public class TestShortList } } - /** - * test the size method - */ - - public void testSize() - { + public void testSize() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -628,12 +527,7 @@ public class TestShortList } } - /** - * test the toArray method - */ - - public void testToArray() - { + public void testToArray() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) @@ -673,16 +567,4 @@ public class TestShortList assertEquals(a5[ j ], list.get(j)); } } - - /** - * main method to run the unit tests - * - * @param unused_args - */ - - public static void main(String [] unused_args) - { - System.out.println("Testing util.ShortList functionality"); - junit.textui.TestRunner.run(TestShortList.class); - } } diff --git a/src/testcases/org/apache/poi/util/TestStringUtil.java b/src/testcases/org/apache/poi/util/TestStringUtil.java index f1b5cfd954..abfba6c297 100644 --- a/src/testcases/org/apache/poi/util/TestStringUtil.java +++ b/src/testcases/org/apache/poi/util/TestStringUtil.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.util; -import junit.framework.*; - +import java.io.UnsupportedEncodingException; import java.text.NumberFormat; +import junit.framework.TestCase; + /** * Unit test for StringUtil * @@ -29,26 +29,12 @@ import java.text.NumberFormat; * @author Glen Stampoultzis (glens at apache.org) * @author Sergei Kozello (sergeikozello at mail.ru) */ -public class TestStringUtil - extends TestCase -{ - /** - * Creates new TestStringUtil - * - * @param name - */ - public TestStringUtil( String name ) - { - super( name ); - } - - +public final class TestStringUtil extends TestCase { /** * test getFromUnicodeHigh for symbols with code below and more 127 */ - public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127() - { + public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127() { byte[] test_data = new byte[]{0x22, 0x04, 0x35, 0x04, 0x41, 0x04, @@ -65,13 +51,7 @@ public class TestStringUtil StringUtil.getFromUnicodeLE( test_data ) ); } - - - /** - * Test putCompressedUnicode - */ - public void testPutCompressedUnicode() throws Exception - { + public void testPutCompressedUnicode() { byte[] output = new byte[100]; byte[] expected_output = { @@ -79,7 +59,12 @@ public class TestStringUtil (byte) 'o', (byte) ' ', (byte) 'W', (byte) 'o', (byte) 'r', (byte) 'l', (byte) 'd', (byte) 0xAE }; - String input = new String( expected_output, StringUtil.getPreferredEncoding() ); + String input; + try { + input = new String( expected_output, StringUtil.getPreferredEncoding() ); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } StringUtil.putCompressedUnicode( input, output, 0 ); for ( int j = 0; j < expected_output.length; j++ ) @@ -106,11 +91,7 @@ public class TestStringUtil } } - /** - * Test putUncompressedUnicode - */ - public void testPutUncompressedUnicode() - { + public void testPutUncompressedUnicode() { byte[] output = new byte[100]; String input = "Hello World"; byte[] expected_output = @@ -147,10 +128,7 @@ public class TestStringUtil } } - - public void testFormat() - throws Exception - { + public void testFormat() { assertEquals( "This is a test " + fmt( 1.2345, 2, 2 ), StringUtil.format( "This is a test %2.2", new Object[] { @@ -192,8 +170,7 @@ public class TestStringUtil } - private String fmt( double num, int minIntDigits, int maxFracDigitis ) - { + private static String fmt(double num, int minIntDigits, int maxFracDigitis) { NumberFormat nf = NumberFormat.getInstance(); if ( minIntDigits != -1 ) @@ -207,28 +184,5 @@ public class TestStringUtil return nf.format( num ); } - - - /** - * main - * - * @param ignored_args - */ - public static void main( String[] ignored_args ) - { - System.out.println( "Testing util.StringUtil functionality" ); - junit.textui.TestRunner.run( TestStringUtil.class ); - } - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - - // System.setProperty() - } - }