update *ssf-workbook tests to junit4

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-02-14 23:21:30 +00:00
parent a0831ba0f9
commit f8bf66308e
4 changed files with 204 additions and 93 deletions

View File

@ -19,6 +19,12 @@
package org.apache.poi.xssf.streaming; 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.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; 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.SXSSFITestDataProvider;
import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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 final class TestSXSSFWorkbook extends BaseTestWorkbook {
public static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance; public static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance;
@ -43,7 +52,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
super(_testDataProvider); super(_testDataProvider);
} }
@Override @After
public void tearDown(){ public void tearDown(){
_testDataProvider.cleanup(); _testDataProvider.cleanup();
} }
@ -52,9 +61,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
* cloning of sheets is not supported in SXSSF * cloning of sheets is not supported in SXSSF
*/ */
@Override @Override
public void testCloneSheet() { @Test
public void cloneSheet() {
try { try {
super.testCloneSheet(); super.cloneSheet();
fail("expected exception"); fail("expected exception");
} catch (RuntimeException e){ } catch (RuntimeException e){
assertEquals("NotImplemented", e.getMessage()); 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 * this test involves evaluation of formulas which isn't supported for SXSSF
*/ */
@Override @Override
public void testSetSheetName() { @Test
public void setSheetName() {
try { try {
super.testSetSheetName(); super.setSheetName();
fail("expected exception"); fail("expected exception");
} catch (Exception e){ } catch (Exception e){
assertEquals( assertEquals(
@ -76,7 +87,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
} }
public void testExistingWorkbook() { @Test
public void existingWorkbook() {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
xssfWorkbook.createSheet("S1"); xssfWorkbook.createSheet("S1");
SXSSFWorkbook wb = new SXSSFWorkbook(xssfWorkbook); 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); SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true);
Field f = SXSSFWorkbook.class.getDeclaredField("_sharedStringSource"); Field f = SXSSFWorkbook.class.getDeclaredField("_sharedStringSource");
@ -128,7 +141,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
assertEquals("A", cell.getStringCellValue()); assertEquals("A", cell.getStringCellValue());
} }
public void testAddToExistingWorkbook() { @Test
public void addToExistingWorkbook() {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
xssfWorkbook.createSheet("S1"); xssfWorkbook.createSheet("S1");
Sheet sheet = xssfWorkbook.createSheet("S2"); Sheet sheet = xssfWorkbook.createSheet("S2");
@ -195,7 +209,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
assertEquals("value 3_1_1", cell3_1_1.getStringCellValue()); assertEquals("value 3_1_1", cell3_1_1.getStringCellValue());
} }
public void testSheetdataWriter(){ @Test
public void sheetdataWriter(){
SXSSFWorkbook wb = new SXSSFWorkbook(); SXSSFWorkbook wb = new SXSSFWorkbook();
SXSSFSheet sh = (SXSSFSheet)wb.createSheet(); SXSSFSheet sh = (SXSSFSheet)wb.createSheet();
SheetDataWriter wr = sh.getSheetDataWriter(); 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(); SXSSFWorkbook wb = new SXSSFWorkbook();
wb.setCompressTempFiles(true); wb.setCompressTempFiles(true);
int rowNum = 1000; int rowNum = 1000;
@ -298,7 +314,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
} }
} }
public void testWorkbookDispose() @Test
public void workbookDispose()
{ {
SXSSFWorkbook wb = new SXSSFWorkbook(); SXSSFWorkbook wb = new SXSSFWorkbook();
// the underlying writer is SheetDataWriter // 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... // 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); Workbook wb = new SXSSFWorkbook(10);
populateWorkbook(wb); populateWorkbook(wb);
saveTwice(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 // 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 // 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"); File out = new File("Test.xlsx");
out.delete(); out.delete();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {

View File

@ -17,6 +17,14 @@
package org.apache.poi.xssf.usermodel; 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.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; 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.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable; 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.CTCalcPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; 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 * 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(); XSSFWorkbook workbook = new XSSFWorkbook();
//check that the default date system is set to 1900 //check that the default date system is set to 1900
@ -130,7 +140,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
pkg.close(); pkg.close();
} }
public void testExisting() throws Exception { @Test
public void existing() throws Exception {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
assertNotNull(workbook.getSharedStringSource()); assertNotNull(workbook.getSharedStringSource());
@ -148,7 +159,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
pkg.close(); pkg.close();
} }
public void testGetCellStyleAt(){ @Test
public void getCellStyleAt(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
short i = 0; short i = 0;
//get default style //get default style
@ -166,7 +178,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertNotNull(cellStyleAt); assertNotNull(cellStyleAt);
} }
public void testGetFontAt(){ @Test
public void getFontAt(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
StylesTable styleSource = workbook.getStylesSource(); StylesTable styleSource = workbook.getStylesSource();
short i = 0; short i = 0;
@ -182,14 +195,16 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertNotNull(fontAt); assertNotNull(fontAt);
} }
public void testGetNumCellStyles(){ @Test
public void getNumCellStyles(){
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
short i = workbook.getNumCellStyles(); short i = workbook.getNumCellStyles();
//get default cellStyles //get default cellStyles
assertEquals(1, i); assertEquals(1, i);
} }
public void testLoadSave() { @Test
public void loadSave() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString()); 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()); assertNotNull(wb2.getStylesSource());
} }
public void testStyles() { @Test
public void styles() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
StylesTable ss = workbook.getStylesSource(); StylesTable ss = workbook.getStylesSource();
@ -250,7 +266,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(1, st.getBorders().size()); assertEquals(1, st.getBorders().size());
} }
public void testIncrementSheetId() { @Test
public void incrementSheetId() {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
int sheetId = (int)wb.createSheet().sheet.getSheetId(); int sheetId = (int)wb.createSheet().sheet.getSheetId();
assertEquals(1, sheetId); assertEquals(1, sheetId);
@ -267,7 +284,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
/** /**
* Test setting of core properties such as Title and Author * Test setting of core properties such as Title and Author
*/ */
public void testWorkbookProperties() { @Test
public void workbookProperties() {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
POIXMLProperties props = workbook.getProperties(); POIXMLProperties props = workbook.getProperties();
assertNotNull(props); 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 * Verify that the attached test data was not modified. If this test method
* fails, the test data is not working properly. * 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"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx");
List<XSSFPictureData> allPictures = workbook.getAllPictures(); List<XSSFPictureData> allPictures = workbook.getAllPictures();
assertEquals(1, allPictures.size()); 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 * 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"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
assertEquals(2, wb.getNumberOfNames()); assertEquals(2, wb.getNumberOfNames());
assertNotNull(wb.getCalculationChain()); assertNotNull(wb.getCalculationChain());
@ -353,7 +373,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
/** /**
* Problems with XSSFWorkbook.removeSheetAt when workbook contains charts * Problems with XSSFWorkbook.removeSheetAt when workbook contains charts
*/ */
public void testBug47813() { @Test
public void bug47813() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
assertEquals(3, wb.getNumberOfSheets()); assertEquals(3, wb.getNumberOfSheets());
assertNotNull(wb.getCalculationChain()); assertNotNull(wb.getCalculationChain());
@ -380,7 +401,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
* Problems with the count of the number of styles * Problems with the count of the number of styles
* coming out wrong * coming out wrong
*/ */
public void testBug49702() throws Exception { @Test
public void bug49702() throws Exception {
// First try with a new file // First try with a new file
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
@ -427,7 +449,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
} catch(IndexOutOfBoundsException e) {} } catch(IndexOutOfBoundsException e) {}
} }
public void testRecalcId() { @Test
public void recalcId() {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
assertFalse(wb.getForceFormulaRecalculation()); assertFalse(wb.getForceFormulaRecalculation());
CTWorkbook ctWorkbook = wb.getCTWorkbook(); 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"); changeSheetNameWithSharedFormulas("shared_formulas.xlsx");
} }
public void testSetTabColor() { @Test
public void setTabColor() {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sh = wb.createSheet(); XSSFSheet sh = wb.createSheet();
assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor()); assertTrue(sh.getCTWorksheet().getSheetPr() == null || !sh.getCTWorksheet().getSheetPr().isSetTabColor());
@ -467,7 +492,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed()); sh.getCTWorksheet().getSheetPr().getTabColor().getIndexed());
} }
public void testColumnWidthPOI52233() throws Exception { @Test
public void columnWidthPOI52233() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(); XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0); XSSFRow row = sheet.createRow(0);
@ -500,8 +526,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
} }
@Test
public void testBug48495() { public void bug48495() {
try { try {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx");
@ -532,7 +558,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
System.out.println("Done"); System.out.println("Done");
} }
public void testBug47090a() { @Test
public void bug47090a() {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
assertSheetOrder(workbook, "Sheet1", "Sheet2"); assertSheetOrder(workbook, "Sheet1", "Sheet2");
workbook.removeSheetAt(0); workbook.removeSheetAt(0);
@ -543,7 +570,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Sheet2", "Sheet1"); assertSheetOrder(read, "Sheet2", "Sheet1");
} }
public void testBug47090b() { @Test
public void bug47090b() {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
assertSheetOrder(workbook, "Sheet1", "Sheet2"); assertSheetOrder(workbook, "Sheet1", "Sheet2");
workbook.removeSheetAt(1); workbook.removeSheetAt(1);
@ -554,7 +582,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Sheet1", "Sheet0"); assertSheetOrder(read, "Sheet1", "Sheet0");
} }
public void testBug47090c() { @Test
public void bug47090c() {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
assertSheetOrder(workbook, "Sheet1", "Sheet2"); assertSheetOrder(workbook, "Sheet1", "Sheet2");
workbook.removeSheetAt(0); workbook.removeSheetAt(0);
@ -565,7 +594,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Sheet2", "Sheet2 (2)"); assertSheetOrder(read, "Sheet2", "Sheet2 (2)");
} }
public void testBug47090d() { @Test
public void bug47090d() {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
assertSheetOrder(workbook, "Sheet1", "Sheet2"); assertSheetOrder(workbook, "Sheet1", "Sheet2");
workbook.createSheet(); workbook.createSheet();
@ -578,7 +608,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1"); assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1");
} }
public void testBug51158() throws IOException { @Test
public void bug51158() throws IOException {
// create a workbook // create a workbook
final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Test Sheet"); 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()); assertEquals("test2", readBack.getSheetAt(0).getRow(2).getCell(4).getStringCellValue());
} }
public void testBug51158a() throws IOException { @Test
public void bug51158a() throws IOException {
// create a workbook // create a workbook
final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFWorkbook workbook = new XSSFWorkbook();
workbook.createSheet("Test Sheet"); workbook.createSheet("Test Sheet");

View File

@ -17,6 +17,13 @@
package org.apache.poi.hssf.usermodel; 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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; 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.ss.util.CellRangeAddress;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.junit.Test;
/** /**
* Tests for {@link HSSFWorkbook} * Tests for {@link HSSFWorkbook}
@ -68,7 +76,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
return wb.getWorkbook(); return wb.getWorkbook();
} }
public void testWindowOneDefaults() { @Test
public void windowOneDefaults() {
HSSFWorkbook b = new HSSFWorkbook( ); HSSFWorkbook b = new HSSFWorkbook( );
try { try {
assertEquals(b.getActiveSheetIndex(), 0); assertEquals(b.getActiveSheetIndex(), 0);
@ -81,7 +90,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
/** /**
* Tests for {@link HSSFWorkbook#isHidden()} etc * Tests for {@link HSSFWorkbook#isHidden()} etc
*/ */
public void testHidden() { @Test
public void hidden() {
HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb = new HSSFWorkbook();
WindowOneRecord w1 = wb.getWorkbook().getWindowOne(); WindowOneRecord w1 = wb.getWorkbook().getWindowOne();
@ -105,7 +115,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(false, w1.getHidden()); assertEquals(false, w1.getHidden());
} }
public void testSheetClone() { @Test
public void sheetClone() {
// First up, try a simple file // First up, try a simple file
HSSFWorkbook b = new HSSFWorkbook(); HSSFWorkbook b = new HSSFWorkbook();
assertEquals(0, b.getNumberOfSheets()); assertEquals(0, b.getNumberOfSheets());
@ -123,7 +134,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(2, b.getNumberOfSheets()); assertEquals(2, b.getNumberOfSheets());
} }
public void testReadWriteWithCharts() { @Test
public void readWriteWithCharts() {
HSSFWorkbook b; HSSFWorkbook b;
HSSFSheet s; HSSFSheet s;
@ -188,7 +200,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testSelectedSheet_bug44523() { @Test
public void selectedSheet_bug44523() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2"); HSSFSheet sheet2 = wb.createSheet("Sheet2");
@ -221,7 +234,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
confirmActiveSelected(sheet4, false); confirmActiveSelected(sheet4, false);
} }
public void testSelectMultiple() { @SuppressWarnings("unused")
@Test
public void selectMultiple() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2"); 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(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet0 = wb.createSheet("Sheet0"); HSSFSheet sheet0 = wb.createSheet("Sheet0");
HSSFSheet sheet1 = wb.createSheet("Sheet1"); 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 * 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 * 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(); HSSFWorkbook wb = new HSSFWorkbook();
InternalSheet sheet = wb.createSheet("Sheet1").getSheet(); InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
List<RecordBase> sheetRecords = sheet.getRecords(); List<RecordBase> sheetRecords = sheet.getRecords();
@ -379,7 +396,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* Checks that us and HSSFName play nicely with named ranges * Checks that us and HSSFName play nicely with named ranges
* that point to deleted sheets * that point to deleted sheets
*/ */
public void testNamesToDeleteSheets() { @Test
public void namesToDeleteSheets() {
HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls"); HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls");
assertEquals(3, b.getNumberOfNames()); 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 * The sample file provided with bug 45582 seems to have one extra byte after the EOFRecord
*/ */
public void testExtraDataAfterEOFRecord() { @Test
public void extraDataAfterEOFRecord() {
try { try {
HSSFTestDataSamples.openSampleWorkbook("ex45582-22397.xls"); HSSFTestDataSamples.openSampleWorkbook("ex45582-22397.xls");
} catch (RecordFormatException e) { } catch (RecordFormatException e) {
@ -498,7 +517,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* Test to make sure that NameRecord.getSheetNumber() is interpreted as a * Test to make sure that NameRecord.getSheetNumber() is interpreted as a
* 1-based sheet tab index (not a 1-based extern sheet index) * 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 // testRRaC has multiple (3) built-in name records
// The second print titles name record has getSheetNumber()==4 // The second print titles name record has getSheetNumber()==4
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls");
@ -527,7 +547,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
/** /**
* Test that the storage clsid property is preserved * 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")); POIFSFileSystem fs1 = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("47920.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs1); HSSFWorkbook wb = new HSSFWorkbook(fs1);
ClassID clsid1 = fs1.getRoot().getStorageClsid(); ClassID clsid1 = fs1.getRoot().getStorageClsid();
@ -545,7 +566,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
* Tests that we can work with both {@link POIFSFileSystem} * Tests that we can work with both {@link POIFSFileSystem}
* and {@link NPOIFSFileSystem} * and {@link NPOIFSFileSystem}
*/ */
public void testDifferentPOIFS() throws Exception { @Test
public void differentPOIFS() throws Exception {
// Open the two filesystems // Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2]; DirectoryNode[] files = new DirectoryNode[2];
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot(); 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 // Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2]; DirectoryNode[] files = new DirectoryNode[2];
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot(); 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 * again (via POIFS) and have it be valid
* @throws IOException * @throws IOException
*/ */
public void testWriteWorkbookFromNPOIFS() throws IOException { @Test
public void writeWorkbookFromNPOIFS() throws IOException {
InputStream is = HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"); InputStream is = HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls");
NPOIFSFileSystem fs = new NPOIFSFileSystem(is); NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
@ -627,7 +651,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
fs.close(); fs.close();
} }
public void testCellStylesLimit() { @Test
public void cellStylesLimit() {
HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb = new HSSFWorkbook();
int numBuiltInStyles = wb.getNumCellStyles(); int numBuiltInStyles = wb.getNumCellStyles();
int MAX_STYLES = 4030; int MAX_STYLES = 4030;
@ -647,7 +672,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(MAX_STYLES, wb.getNumCellStyles()); assertEquals(MAX_STYLES, wb.getNumCellStyles());
} }
public void testSetSheetOrderHSSF(){ @Test
public void setSheetOrderHSSF(){
HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s1 = wb.createSheet("first sheet"); HSSFSheet s1 = wb.createSheet("first sheet");
HSSFSheet s2 = wb.createSheet("other 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"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
InternalWorkbook iwb = wb.getWorkbook(); InternalWorkbook iwb = wb.getWorkbook();
iwb.findDrawingGroup(); iwb.findDrawingGroup();
@ -735,11 +762,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
} }
public void testChangeSheetNameWithSharedFormulas() { @Test
public void changeSheetNameWithSharedFormulas() {
changeSheetNameWithSharedFormulas("shared_formulas.xls"); changeSheetNameWithSharedFormulas("shared_formulas.xls");
} }
public void testEmptyDirectoryNode() throws IOException { @Test
public void emptyDirectoryNode() throws IOException {
try { try {
assertNotNull(new HSSFWorkbook(new POIFSFileSystem())); assertNotNull(new HSSFWorkbook(new POIFSFileSystem()));
fail("Should catch exception about invalid POIFSFileSystem"); fail("Should catch exception about invalid POIFSFileSystem");
@ -749,7 +778,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testSelectedSheetShort() { @Test
public void selectedSheetShort() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2"); HSSFSheet sheet2 = wb.createSheet("Sheet2");
@ -787,7 +817,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals(2, wb.getDisplayedTab()); assertEquals(2, wb.getDisplayedTab());
} }
public void testAddSheetTwice() { @Test
public void addSheetTwice() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet1 = wb.createSheet("Sheet1");
assertNotNull(sheet1); assertNotNull(sheet1);
@ -799,7 +830,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
} }
public void testGetSheetIndex() { @Test
public void getSheetIndex() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1"); HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2"); HSSFSheet sheet2 = wb.createSheet("Sheet2");
@ -823,7 +855,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testGetExternSheetIndex() { @Test
public void getExternSheetIndex() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
wb.createSheet("Sheet1"); wb.createSheet("Sheet1");
wb.createSheet("Sheet2"); wb.createSheet("Sheet2");
@ -842,7 +875,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testSSTString() { @Test
public void sstString() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
int sst = wb.addSSTString("somestring"); int sst = wb.addSSTString("somestring");
@ -850,7 +884,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
//assertNull(wb.getSSTString(sst+1)); //assertNull(wb.getSSTString(sst+1));
} }
public void testNames() { @Test
public void names() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
try { try {
@ -886,14 +921,16 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} }
} }
public void testTestMethods() { @Test
public void testMethods() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
wb.insertChartRecord(); wb.insertChartRecord();
//wb.dumpDrawingGroupRecords(true); //wb.dumpDrawingGroupRecords(true);
//wb.dumpDrawingGroupRecords(false); //wb.dumpDrawingGroupRecords(false);
} }
public void testWriteProtection() { @Test
public void writeProtection() {
HSSFWorkbook wb=new HSSFWorkbook(); HSSFWorkbook wb=new HSSFWorkbook();
assertFalse(wb.isWriteProtected()); assertFalse(wb.isWriteProtected());
@ -905,7 +942,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertFalse(wb.isWriteProtected()); assertFalse(wb.isWriteProtected());
} }
public void testBug50298() throws Exception { @Test
public void bug50298() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls");
assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
@ -937,7 +975,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
} }
public void testBug50298a() throws Exception { @Test
public void bug50298a() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("50298.xls");
assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received"); assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
@ -977,7 +1016,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest"); assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
} }
public void testBug54500() throws Exception { @Test
public void bug54500() throws Exception {
String nameName = "AName"; String nameName = "AName";
String sheetName = "ASheet"; String sheetName = "ASheet";
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls"); HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls");

View File

@ -17,16 +17,23 @@
package org.apache.poi.ss.usermodel; 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.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Test;
/** /**
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class BaseTestWorkbook extends TestCase { public abstract class BaseTestWorkbook {
private final ITestDataProvider _testDataProvider; private final ITestDataProvider _testDataProvider;
@ -34,7 +41,8 @@ public abstract class BaseTestWorkbook extends TestCase {
_testDataProvider = testDataProvider; _testDataProvider = testDataProvider;
} }
public void testCreateSheet() { @Test
public void createSheet() {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
assertEquals(0, wb.getNumberOfSheets()); 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. * 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. * 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(); Workbook wb = _testDataProvider.createWorkbook();
String sheetName1 = "My very long sheet name which is longer than 31 chars"; 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)); assertEquals(1, wb.getSheetIndex(truncatedSheetName3));
} }
public void testRemoveSheetAt() { @Test
public void removeSheetAt() {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("sheet1"); workbook.createSheet("sheet1");
workbook.createSheet("sheet2"); workbook.createSheet("sheet2");
@ -198,7 +208,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
} }
public void testDefaultValues() { @Test
public void defaultValues() {
Workbook b = _testDataProvider.createWorkbook(); Workbook b = _testDataProvider.createWorkbook();
assertEquals(0, b.getActiveSheetIndex()); assertEquals(0, b.getActiveSheetIndex());
assertEquals(0, b.getFirstVisibleTab()); assertEquals(0, b.getFirstVisibleTab());
@ -206,7 +217,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(0, b.getNumberOfSheets()); assertEquals(0, b.getNumberOfSheets());
} }
public void testSheetSelection() { @Test
public void sheetSelection() {
Workbook b = _testDataProvider.createWorkbook(); Workbook b = _testDataProvider.createWorkbook();
b.createSheet("Sheet One"); b.createSheet("Sheet One");
b.createSheet("Sheet Two"); b.createSheet("Sheet Two");
@ -217,7 +229,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(1, b.getFirstVisibleTab()); assertEquals(1, b.getFirstVisibleTab());
} }
public void testPrintArea() { @Test
public void printArea() {
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet1 = workbook.createSheet("Test Print Area"); Sheet sheet1 = workbook.createSheet("Test Print Area");
String sheetName1 = sheet1.getSheetName(); String sheetName1 = sheet1.getSheetName();
@ -236,7 +249,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertNull(workbook.getPrintArea(0)); assertNull(workbook.getPrintArea(0));
} }
public void testGetSetActiveSheet(){ @Test
public void getSetActiveSheet(){
Workbook workbook = _testDataProvider.createWorkbook(); Workbook workbook = _testDataProvider.createWorkbook();
assertEquals(0, workbook.getActiveSheetIndex()); assertEquals(0, workbook.getActiveSheetIndex());
@ -253,7 +267,8 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(0, workbook.getActiveSheetIndex()); assertEquals(0, workbook.getActiveSheetIndex());
} }
public void testSetSheetOrder() { @Test
public void setSheetOrder() {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
for (int i=0; i < 10; i++) { 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(); Workbook book = _testDataProvider.createWorkbook();
Sheet sheet = book.createSheet("TEST"); Sheet sheet = book.createSheet("TEST");
sheet.createRow(0).createCell(0).setCellValue("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(); Workbook workbook = _testDataProvider.createWorkbook();
Sheet sheet = workbook.createSheet(); Sheet sheet = workbook.createSheet();
assertSame(workbook, sheet.getWorkbook()); assertSame(workbook, sheet.getWorkbook());
@ -370,7 +387,8 @@ public abstract class BaseTestWorkbook extends TestCase {
* is removed * is removed
*/ */
@Deprecated @Deprecated
public void testSetRepeatingRowsAnsColumns(){ @Test
public void setRepeatingRowsAnsColumns(){
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet1 = wb.createSheet(); Sheet sheet1 = wb.createSheet();
wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3); 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 * 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(); Workbook wb = _testDataProvider.createWorkbook();
CreationHelper factory = wb.getCreationHelper(); CreationHelper factory = wb.getCreationHelper();
//Create a unicode dataformat (contains euro symbol) //Create a unicode dataformat (contains euro symbol)
@ -501,7 +520,8 @@ public abstract class BaseTestWorkbook extends TestCase {
* *
* @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47100">Bugzilla 47100</a> * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47100">Bugzilla 47100</a>
*/ */
public void testSetSheetName() throws Exception { @Test
public void setSheetName() throws Exception {
Workbook wb = newSetSheetNameTestingWorkbook(); 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("SUM('Testing 47100'!A1:C1,'To be renamed'!A1:A5)", cell1.getCellFormula());
assertEquals("sale_2+sale_3+'Testing 47100'!C1", cell2.getCellFormula()); assertEquals("sale_2+sale_3+'Testing 47100'!C1", cell2.getCellFormula());
assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0);
assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0);
assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0);
wb.setSheetName(1, "47100 - First"); wb.setSheetName(1, "47100 - First");
wb.setSheetName(2, "47100 - Second"); 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()); assertEquals("sale_2+sale_3+'47100 - First'!C1", cell2.getCellFormula());
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0);
assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0);
assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0);
wb = _testDataProvider.writeOutAndReadBack(wb); wb = _testDataProvider.writeOutAndReadBack(wb);
@ -575,9 +595,9 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals("sale_2+sale_3+'47100 - First'!C1", cell2.getCellFormula()); assertEquals("sale_2+sale_3+'47100 - First'!C1", cell2.getCellFormula());
evaluator = wb.getCreationHelper().createFormulaEvaluator(); evaluator = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell0).getNumberValue(), 0);
assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue()); assertEquals(21.0, evaluator.evaluate(cell1).getNumberValue(), 0);
assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue()); assertEquals(6.0, evaluator.evaluate(cell2).getNumberValue(), 0);
} }
public void changeSheetNameWithSharedFormulas(String sampleFile){ public void changeSheetNameWithSharedFormulas(String sampleFile){