From d58466c8b35926f4c434e363bf63777ea26a572d Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Fri, 14 Feb 2014 23:21:30 +0000 Subject: [PATCH] update *ssf-workbook tests to junit4 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568541 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/streaming/TestSXSSFWorkbook.java | 45 +++++--- .../poi/xssf/usermodel/TestXSSFWorkbook.java | 82 +++++++++----- .../poi/hssf/usermodel/TestHSSFWorkbook.java | 102 ++++++++++++------ .../poi/ss/usermodel/BaseTestWorkbook.java | 68 +++++++----- 4 files changed, 204 insertions(+), 93 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index f33bd48b8b..3a7a084994 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -19,6 +19,12 @@ package org.apache.poi.xssf.streaming; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -35,6 +41,9 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; public final class TestSXSSFWorkbook extends BaseTestWorkbook { public static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance; @@ -43,7 +52,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { super(_testDataProvider); } - @Override + @After public void tearDown(){ _testDataProvider.cleanup(); } @@ -52,9 +61,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { * cloning of sheets is not supported in SXSSF */ @Override - public void testCloneSheet() { + @Test + public void cloneSheet() { try { - super.testCloneSheet(); + super.cloneSheet(); fail("expected exception"); } catch (RuntimeException e){ assertEquals("NotImplemented", e.getMessage()); @@ -65,9 +75,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { * this test involves evaluation of formulas which isn't supported for SXSSF */ @Override - public void testSetSheetName() { + @Test + public void setSheetName() { try { - super.testSetSheetName(); + super.setSheetName(); fail("expected exception"); } catch (Exception e){ assertEquals( @@ -76,7 +87,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { } } - public void testExistingWorkbook() { + @Test + public void existingWorkbook() { XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); xssfWorkbook.createSheet("S1"); SXSSFWorkbook wb = new SXSSFWorkbook(xssfWorkbook); @@ -92,7 +104,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { } - public void testUseSharedStringsTable() throws Exception { + @Test + public void useSharedStringsTable() throws Exception { SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true); Field f = SXSSFWorkbook.class.getDeclaredField("_sharedStringSource"); @@ -128,7 +141,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { assertEquals("A", cell.getStringCellValue()); } - public void testAddToExistingWorkbook() { + @Test + public void addToExistingWorkbook() { XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); xssfWorkbook.createSheet("S1"); Sheet sheet = xssfWorkbook.createSheet("S2"); @@ -195,7 +209,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { assertEquals("value 3_1_1", cell3_1_1.getStringCellValue()); } - public void testSheetdataWriter(){ + @Test + public void sheetdataWriter(){ SXSSFWorkbook wb = new SXSSFWorkbook(); SXSSFSheet sh = (SXSSFSheet)wb.createSheet(); SheetDataWriter wr = sh.getSheetDataWriter(); @@ -226,7 +241,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { } - public void testGZipSheetdataWriter(){ + @Test + public void gzipSheetdataWriter(){ SXSSFWorkbook wb = new SXSSFWorkbook(); wb.setCompressTempFiles(true); int rowNum = 1000; @@ -298,7 +314,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { } } - public void testWorkbookDispose() + @Test + public void workbookDispose() { SXSSFWorkbook wb = new SXSSFWorkbook(); // the underlying writer is SheetDataWriter @@ -312,7 +329,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { } // currently writing the same sheet multiple times is not supported... - public void DISABLEDtestBug53515() throws Exception { + @Ignore + public void bug53515() throws Exception { Workbook wb = new SXSSFWorkbook(10); populateWorkbook(wb); saveTwice(wb); @@ -323,7 +341,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { // Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files // See http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html - public void DISABLEDtestBug53515a() throws Exception { + @Ignore + public void bug53515a() throws Exception { File out = new File("Test.xlsx"); out.delete(); for (int i = 0; i < 2; i++) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 4f09813b11..72d63e49fa 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -17,6 +17,14 @@ package org.apache.poi.xssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -47,6 +55,7 @@ import org.apache.poi.util.TempFile; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.StylesTable; +import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; @@ -61,7 +70,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { /** * Tests that we can save, and then re-load a new document */ - public void testSaveLoadNew() throws Exception { + @Test + public void saveLoadNew() throws Exception { XSSFWorkbook workbook = new XSSFWorkbook(); //check that the default date system is set to 1900 @@ -130,7 +140,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { pkg.close(); } - public void testExisting() throws Exception { + @Test + public void existing() throws Exception { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); assertNotNull(workbook.getSharedStringSource()); @@ -148,7 +159,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { pkg.close(); } - public void testGetCellStyleAt(){ + @Test + public void getCellStyleAt(){ XSSFWorkbook workbook = new XSSFWorkbook(); short i = 0; //get default style @@ -166,7 +178,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertNotNull(cellStyleAt); } - public void testGetFontAt(){ + @Test + public void getFontAt(){ XSSFWorkbook workbook = new XSSFWorkbook(); StylesTable styleSource = workbook.getStylesSource(); short i = 0; @@ -182,14 +195,16 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertNotNull(fontAt); } - public void testGetNumCellStyles(){ + @Test + public void getNumCellStyles(){ XSSFWorkbook workbook = new XSSFWorkbook(); short i = workbook.getNumCellStyles(); //get default cellStyles assertEquals(1, i); } - public void testLoadSave() { + @Test + public void loadSave() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); assertEquals(3, workbook.getNumberOfSheets()); assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString()); @@ -212,7 +227,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertNotNull(wb2.getStylesSource()); } - public void testStyles() { + @Test + public void styles() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); StylesTable ss = workbook.getStylesSource(); @@ -250,7 +266,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertEquals(1, st.getBorders().size()); } - public void testIncrementSheetId() { + @Test + public void incrementSheetId() { XSSFWorkbook wb = new XSSFWorkbook(); int sheetId = (int)wb.createSheet().sheet.getSheetId(); assertEquals(1, sheetId); @@ -267,7 +284,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { /** * Test setting of core properties such as Title and Author */ - public void testWorkbookProperties() { + @Test + public void workbookProperties() { XSSFWorkbook workbook = new XSSFWorkbook(); POIXMLProperties props = workbook.getProperties(); assertNotNull(props); @@ -292,7 +310,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { * Verify that the attached test data was not modified. If this test method * fails, the test data is not working properly. */ - public void testBug47668() throws Exception { + @Test + public void bug47668() throws Exception { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx"); List allPictures = workbook.getAllPictures(); assertEquals(1, allPictures.size()); @@ -327,7 +346,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { /** * When deleting a sheet make sure that we adjust sheet indices of named ranges */ - public void testBug47737() { + @Test + public void bug47737() { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx"); assertEquals(2, wb.getNumberOfNames()); assertNotNull(wb.getCalculationChain()); @@ -353,7 +373,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { /** * Problems with XSSFWorkbook.removeSheetAt when workbook contains charts */ - public void testBug47813() { + @Test + public void bug47813() { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx"); assertEquals(3, wb.getNumberOfSheets()); assertNotNull(wb.getCalculationChain()); @@ -380,7 +401,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { * Problems with the count of the number of styles * coming out wrong */ - public void testBug49702() throws Exception { + @Test + public void bug49702() throws Exception { // First try with a new file XSSFWorkbook wb = new XSSFWorkbook(); @@ -427,7 +449,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { } catch(IndexOutOfBoundsException e) {} } - public void testRecalcId() { + @Test + public void recalcId() { XSSFWorkbook wb = new XSSFWorkbook(); assertFalse(wb.getForceFormulaRecalculation()); CTWorkbook ctWorkbook = wb.getCTWorkbook(); @@ -453,11 +476,13 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { } - public void testChangeSheetNameWithSharedFormulas() { + @Test + public void changeSheetNameWithSharedFormulas() { changeSheetNameWithSharedFormulas("shared_formulas.xlsx"); } - public void testSetTabColor() { + @Test + public void setTabColor() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.createSheet(); assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor()); @@ -467,7 +492,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed()); } - public void testColumnWidthPOI52233() throws Exception { + @Test + public void columnWidthPOI52233() throws Exception { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); XSSFRow row = sheet.createRow(0); @@ -500,8 +526,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works } - - public void testBug48495() { + @Test + public void bug48495() { try { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx"); @@ -532,7 +558,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { System.out.println("Done"); } - public void testBug47090a() { + @Test + public void bug47090a() { Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); assertSheetOrder(workbook, "Sheet1", "Sheet2"); workbook.removeSheetAt(0); @@ -543,7 +570,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Sheet2", "Sheet1"); } - public void testBug47090b() { + @Test + public void bug47090b() { Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); assertSheetOrder(workbook, "Sheet1", "Sheet2"); workbook.removeSheetAt(1); @@ -554,7 +582,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Sheet1", "Sheet0"); } - public void testBug47090c() { + @Test + public void bug47090c() { Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); assertSheetOrder(workbook, "Sheet1", "Sheet2"); workbook.removeSheetAt(0); @@ -565,7 +594,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Sheet2", "Sheet2 (2)"); } - public void testBug47090d() { + @Test + public void bug47090d() { Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); assertSheetOrder(workbook, "Sheet1", "Sheet2"); workbook.createSheet(); @@ -578,7 +608,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1"); } - public void testBug51158() throws IOException { + @Test + public void bug51158() throws IOException { // create a workbook final XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Test Sheet"); @@ -614,7 +645,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertEquals("test2", readBack.getSheetAt(0).getRow(2).getCell(4).getStringCellValue()); } - public void testBug51158a() throws IOException { + @Test + public void bug51158a() throws IOException { // create a workbook final XSSFWorkbook workbook = new XSSFWorkbook(); workbook.createSheet("Test Sheet"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 6f20eacbc2..110773fe4a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -17,6 +17,13 @@ package org.apache.poi.hssf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -52,6 +59,7 @@ import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.TempFile; +import org.junit.Test; /** * Tests for {@link HSSFWorkbook} @@ -68,7 +76,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { return wb.getWorkbook(); } - public void testWindowOneDefaults() { + @Test + public void windowOneDefaults() { HSSFWorkbook b = new HSSFWorkbook( ); try { assertEquals(b.getActiveSheetIndex(), 0); @@ -81,7 +90,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { /** * Tests for {@link HSSFWorkbook#isHidden()} etc */ - public void testHidden() { + @Test + public void hidden() { HSSFWorkbook wb = new HSSFWorkbook(); WindowOneRecord w1 = wb.getWorkbook().getWindowOne(); @@ -105,7 +115,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertEquals(false, w1.getHidden()); } - public void testSheetClone() { + @Test + public void sheetClone() { // First up, try a simple file HSSFWorkbook b = new HSSFWorkbook(); assertEquals(0, b.getNumberOfSheets()); @@ -123,7 +134,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertEquals(2, b.getNumberOfSheets()); } - public void testReadWriteWithCharts() { + @Test + public void readWriteWithCharts() { HSSFWorkbook b; HSSFSheet s; @@ -188,7 +200,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } @SuppressWarnings("deprecation") - public void testSelectedSheet_bug44523() { + @Test + public void selectedSheet_bug44523() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet2 = wb.createSheet("Sheet2"); @@ -221,7 +234,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { confirmActiveSelected(sheet4, false); } - public void testSelectMultiple() { + @SuppressWarnings("unused") + @Test + public void selectMultiple() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet2 = wb.createSheet("Sheet2"); @@ -276,7 +291,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } - public void testActiveSheetAfterDelete_bug40414() { + @Test + public void activeSheetAfterDelete_bug40414() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet0 = wb.createSheet("Sheet0"); HSSFSheet sheet1 = wb.createSheet("Sheet1"); @@ -359,7 +375,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * errors are particularly hard to track down. This test ensures that HSSFWorkbook throws * a specific exception as soon as the situation is detected. See bugzilla 45066 */ - public void testSheetSerializeSizeMismatch_bug45066() { + @Test + public void sheetSerializeSizeMismatch_bug45066() { HSSFWorkbook wb = new HSSFWorkbook(); InternalSheet sheet = wb.createSheet("Sheet1").getSheet(); List sheetRecords = sheet.getRecords(); @@ -379,7 +396,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * Checks that us and HSSFName play nicely with named ranges * that point to deleted sheets */ - public void testNamesToDeleteSheets() { + @Test + public void namesToDeleteSheets() { HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls"); assertEquals(3, b.getNumberOfNames()); @@ -484,7 +502,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { /** * The sample file provided with bug 45582 seems to have one extra byte after the EOFRecord */ - public void testExtraDataAfterEOFRecord() { + @Test + public void extraDataAfterEOFRecord() { try { HSSFTestDataSamples.openSampleWorkbook("ex45582-22397.xls"); } catch (RecordFormatException e) { @@ -498,7 +517,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * Test to make sure that NameRecord.getSheetNumber() is interpreted as a * 1-based sheet tab index (not a 1-based extern sheet index) */ - public void testFindBuiltInNameRecord() { + @Test + public void findBuiltInNameRecord() { // testRRaC has multiple (3) built-in name records // The second print titles name record has getSheetNumber()==4 HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls"); @@ -527,7 +547,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { /** * Test that the storage clsid property is preserved */ - public void test47920() throws IOException { + @Test + public void bug47920() throws IOException { POIFSFileSystem fs1 = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("47920.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs1); ClassID clsid1 = fs1.getRoot().getStorageClsid(); @@ -545,7 +566,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * Tests that we can work with both {@link POIFSFileSystem} * and {@link NPOIFSFileSystem} */ - public void testDifferentPOIFS() throws Exception { + @Test + public void differentPOIFS() throws Exception { // Open the two filesystems DirectoryNode[] files = new DirectoryNode[2]; files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot(); @@ -573,7 +595,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } - public void testWordDocEmbeddedInXls() throws IOException { + @Test + public void wordDocEmbeddedInXls() throws IOException { // Open the two filesystems DirectoryNode[] files = new DirectoryNode[2]; files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot(); @@ -610,7 +633,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { * again (via POIFS) and have it be valid * @throws IOException */ - public void testWriteWorkbookFromNPOIFS() throws IOException { + @Test + public void writeWorkbookFromNPOIFS() throws IOException { InputStream is = HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"); NPOIFSFileSystem fs = new NPOIFSFileSystem(is); @@ -627,7 +651,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { fs.close(); } - public void testCellStylesLimit() { + @Test + public void cellStylesLimit() { HSSFWorkbook wb = new HSSFWorkbook(); int numBuiltInStyles = wb.getNumCellStyles(); int MAX_STYLES = 4030; @@ -647,7 +672,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertEquals(MAX_STYLES, wb.getNumCellStyles()); } - public void testSetSheetOrderHSSF(){ + @Test + public void setSheetOrderHSSF(){ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s1 = wb.createSheet("first sheet"); HSSFSheet s2 = wb.createSheet("other sheet"); @@ -712,7 +738,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } - public void testClonePictures() throws IOException { + @Test + public void clonePictures() throws IOException { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls"); InternalWorkbook iwb = wb.getWorkbook(); iwb.findDrawingGroup(); @@ -735,11 +762,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } - public void testChangeSheetNameWithSharedFormulas() { + @Test + public void changeSheetNameWithSharedFormulas() { changeSheetNameWithSharedFormulas("shared_formulas.xls"); } - public void testEmptyDirectoryNode() throws IOException { + @Test + public void emptyDirectoryNode() throws IOException { try { assertNotNull(new HSSFWorkbook(new POIFSFileSystem())); fail("Should catch exception about invalid POIFSFileSystem"); @@ -749,7 +778,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } @SuppressWarnings("deprecation") - public void testSelectedSheetShort() { + @Test + public void selectedSheetShort() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet2 = wb.createSheet("Sheet2"); @@ -787,7 +817,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertEquals(2, wb.getDisplayedTab()); } - public void testAddSheetTwice() { + @Test + public void addSheetTwice() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("Sheet1"); assertNotNull(sheet1); @@ -799,7 +830,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } - public void testGetSheetIndex() { + @Test + public void getSheetIndex() { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet2 = wb.createSheet("Sheet2"); @@ -823,7 +855,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } @SuppressWarnings("deprecation") - public void testGetExternSheetIndex() { + @Test + public void getExternSheetIndex() { HSSFWorkbook wb=new HSSFWorkbook(); wb.createSheet("Sheet1"); wb.createSheet("Sheet2"); @@ -842,7 +875,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } @SuppressWarnings("deprecation") - public void testSSTString() { + @Test + public void sstString() { HSSFWorkbook wb=new HSSFWorkbook(); int sst = wb.addSSTString("somestring"); @@ -850,7 +884,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { //assertNull(wb.getSSTString(sst+1)); } - public void testNames() { + @Test + public void names() { HSSFWorkbook wb=new HSSFWorkbook(); try { @@ -886,14 +921,16 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } - public void testTestMethods() { + @Test + public void testMethods() { HSSFWorkbook wb=new HSSFWorkbook(); wb.insertChartRecord(); //wb.dumpDrawingGroupRecords(true); //wb.dumpDrawingGroupRecords(false); } - public void testWriteProtection() { + @Test + public void writeProtection() { HSSFWorkbook wb=new HSSFWorkbook(); assertFalse(wb.isWriteProtected()); @@ -905,7 +942,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertFalse(wb.isWriteProtected()); } - public void testBug50298() throws Exception { + @Test + public void bug50298() throws Exception { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); @@ -937,7 +975,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); } - public void testBug50298a() throws Exception { + @Test + public void bug50298a() throws Exception { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); @@ -977,7 +1016,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest"); } - public void testBug54500() throws Exception { + @Test + public void bug54500() throws Exception { String nameName = "AName"; String sheetName = "ASheet"; HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls"); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 30ecd1990f..ce3b78712a 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -17,16 +17,23 @@ package org.apache.poi.ss.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.util.CellRangeAddress; +import org.junit.Test; /** * @author Yegor Kozlov */ -public abstract class BaseTestWorkbook extends TestCase { +public abstract class BaseTestWorkbook { private final ITestDataProvider _testDataProvider; @@ -34,7 +41,8 @@ public abstract class BaseTestWorkbook extends TestCase { _testDataProvider = testDataProvider; } - public void testCreateSheet() { + @Test + public void createSheet() { Workbook wb = _testDataProvider.createWorkbook(); assertEquals(0, wb.getNumberOfSheets()); @@ -140,7 +148,8 @@ public abstract class BaseTestWorkbook extends TestCase { * avoid funny duplicate sheet name errors, POI enforces uniqueness on only the first 31 chars. * but for the purpose of uniqueness long sheet names are silently truncated to 31 chars. */ - public void testCreateSheetWithLongNames() { + @Test + public void createSheetWithLongNames() { Workbook wb = _testDataProvider.createWorkbook(); String sheetName1 = "My very long sheet name which is longer than 31 chars"; @@ -176,7 +185,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(1, wb.getSheetIndex(truncatedSheetName3)); } - public void testRemoveSheetAt() { + @Test + public void removeSheetAt() { Workbook workbook = _testDataProvider.createWorkbook(); workbook.createSheet("sheet1"); workbook.createSheet("sheet2"); @@ -198,7 +208,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(3, workbook.getNumberOfSheets()); } - public void testDefaultValues() { + @Test + public void defaultValues() { Workbook b = _testDataProvider.createWorkbook(); assertEquals(0, b.getActiveSheetIndex()); assertEquals(0, b.getFirstVisibleTab()); @@ -206,7 +217,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(0, b.getNumberOfSheets()); } - public void testSheetSelection() { + @Test + public void sheetSelection() { Workbook b = _testDataProvider.createWorkbook(); b.createSheet("Sheet One"); b.createSheet("Sheet Two"); @@ -217,7 +229,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(1, b.getFirstVisibleTab()); } - public void testPrintArea() { + @Test + public void printArea() { Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet1 = workbook.createSheet("Test Print Area"); String sheetName1 = sheet1.getSheetName(); @@ -236,7 +249,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertNull(workbook.getPrintArea(0)); } - public void testGetSetActiveSheet(){ + @Test + public void getSetActiveSheet(){ Workbook workbook = _testDataProvider.createWorkbook(); assertEquals(0, workbook.getActiveSheetIndex()); @@ -253,7 +267,8 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals(0, workbook.getActiveSheetIndex()); } - public void testSetSheetOrder() { + @Test + public void setSheetOrder() { Workbook wb = _testDataProvider.createWorkbook(); for (int i=0; i < 10; i++) { @@ -309,7 +324,8 @@ public abstract class BaseTestWorkbook extends TestCase { } } - public void testCloneSheet() { + @Test + public void cloneSheet() { Workbook book = _testDataProvider.createWorkbook(); Sheet sheet = book.createSheet("TEST"); sheet.createRow(0).createCell(0).setCellValue("Test"); @@ -337,7 +353,8 @@ public abstract class BaseTestWorkbook extends TestCase { } - public void testParentReferences(){ + @Test + public void parentReferences(){ Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet(); assertSame(workbook, sheet.getWorkbook()); @@ -370,7 +387,8 @@ public abstract class BaseTestWorkbook extends TestCase { * is removed */ @Deprecated - public void testSetRepeatingRowsAnsColumns(){ + @Test + public void setRepeatingRowsAnsColumns(){ Workbook wb = _testDataProvider.createWorkbook(); Sheet sheet1 = wb.createSheet(); wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3); @@ -387,7 +405,8 @@ public abstract class BaseTestWorkbook extends TestCase { /** * Tests that all of the unicode capable string fields can be set, written and then read back */ - public void testUnicodeInAll() { + @Test + public void unicodeInAll() { Workbook wb = _testDataProvider.createWorkbook(); CreationHelper factory = wb.getCreationHelper(); //Create a unicode dataformat (contains euro symbol) @@ -501,7 +520,8 @@ public abstract class BaseTestWorkbook extends TestCase { * * @see Bugzilla 47100 */ - public void testSetSheetName() throws Exception { + @Test + public void setSheetName() throws Exception { Workbook wb = newSetSheetNameTestingWorkbook(); @@ -528,9 +548,9 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals("SUM('Testing 47100'!A1:C1,'To be renamed'!A1:A5)", cell1.getCellFormula()); assertEquals("sale_2+sale_3+'Testing 47100'!C1", cell2.getCellFormula()); - assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); - assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); - assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); + assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0); + assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0); + assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0); wb.setSheetName(1, "47100 - First"); wb.setSheetName(2, "47100 - Second"); @@ -547,9 +567,9 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals("sale_2+sale_3+'47100 - First'!C1", cell2.getCellFormula()); evaluator.clearAllCachedResultValues(); - assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); - assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); - assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); + assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0); + assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0); + assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0); wb = _testDataProvider.writeOutAndReadBack(wb); @@ -575,9 +595,9 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals("sale_2+sale_3+'47100 - First'!C1", cell2.getCellFormula()); evaluator = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); - assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); - assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); + assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0); + assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0); + assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0); } public void changeSheetNameWithSharedFormulas(String sampleFile){ -- 2.39.5