aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-09-12 18:45:07 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-09-12 18:45:07 +0000
commitfbcf869f48e696a28ea364b8ff394476a96cdd21 (patch)
tree636ea213a2b2f8c826ee4ba8f1ac650d918869e3 /src/testcases/org/apache/poi/ss
parentf580fb0d728ad52873fb28be121e436f92fadfbb (diff)
downloadpoi-fbcf869f48e696a28ea364b8ff394476a96cdd21.tar.gz
poi-fbcf869f48e696a28ea364b8ff394476a96cdd21.zip
fix eclipse warning - mostly generics cosmetics
close resources in tests junit4 conversions convert spreadsheet based formular test to junit parameterized tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1702659 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java138
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java20
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java51
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java48
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java367
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java13
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java13
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java10
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java16
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java11
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java11
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java11
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java9
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java9
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java13
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java13
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java12
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java49
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java12
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java234
-rw-r--r--src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java18
28 files changed, 597 insertions, 563 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
index 31ad51246b..f66cd06595 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestFormulaBugs.java
@@ -17,13 +17,12 @@
package org.apache.poi.ss.formula.eval;
-import java.io.FileOutputStream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.io.InputStream;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@@ -31,31 +30,25 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellValue;
+import org.junit.Test;
/**
* Miscellaneous tests for bugzilla entries.<p/> The test name contains the
* bugzilla bug id.
- *
- *
- * @author Josh Micich
*/
-public final class TestFormulaBugs extends TestCase {
+public final class TestFormulaBugs {
/**
* Bug 27349 - VLOOKUP with reference to another sheet.<p/> This test was
* added <em>long</em> after the relevant functionality was fixed.
*/
- public void test27349() {
+ @Test
+ public void test27349() throws Exception {
// 27349-vlookupAcrossSheets.xls is bugzilla/attachment.cgi?id=10622
InputStream is = HSSFTestDataSamples.openSampleFileStream("27349-vlookupAcrossSheets.xls");
- HSSFWorkbook wb;
- try {
- // original bug may have thrown exception here, or output warning to
- // stderr
- wb = new HSSFWorkbook(is);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ // original bug may have thrown exception here,
+ // or output warning to stderr
+ HSSFWorkbook wb = new HSSFWorkbook(is);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(1);
@@ -71,6 +64,9 @@ public final class TestFormulaBugs extends TestCase {
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
assertEquals(3.0, cv.getNumberValue(), 0.0);
+
+ wb.close();
+ is.close();
}
/**
@@ -78,7 +74,8 @@ public final class TestFormulaBugs extends TestCase {
*
* seems to be a duplicate of 24925
*/
- public void test27405() {
+ @Test
+ public void test27405() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("input");
@@ -99,16 +96,16 @@ public final class TestFormulaBugs extends TestCase {
cell = row.createCell(3); // D5
cell.setCellFormula("IF(ISNUMBER(b1),b1,b2)");
- if (false) { // set true to check excel file manually
- // bug report mentions 'Editing the formula in excel "fixes" the problem.'
- try {
- FileOutputStream fileOut = new FileOutputStream("27405output.xls");
- wb.write(fileOut);
- fileOut.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+// if (false) { // set true to check excel file manually
+// // bug report mentions 'Editing the formula in excel "fixes" the problem.'
+// try {
+// FileOutputStream fileOut = new FileOutputStream("27405output.xls");
+// wb.write(fileOut);
+// fileOut.close();
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// }
// use POI's evaluator as an extra sanity check
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
@@ -120,58 +117,59 @@ public final class TestFormulaBugs extends TestCase {
cv = fe.evaluate(row.getCell(1));
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cv.getCellType());
assertEquals(true, cv.getBooleanValue());
+
+ wb.close();
}
/**
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
* @throws IOException
*/
+ @Test
public void test42448() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet1 = wb.createSheet("Sheet1");
+
+ HSSFRow row = sheet1.createRow(0);
+ HSSFCell cell = row.createCell(0);
+
+ // it's important to create the referenced sheet first
+ HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A'
+ // TODO - POI crashes if the formula is added before this sheet
+ // RuntimeException("Zero length string is an invalid sheet name")
+ // Excel doesn't crash but the formula doesn't work until it is
+ // re-entered
+
+ String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report
try {
- HSSFSheet sheet1 = wb.createSheet("Sheet1");
-
- HSSFRow row = sheet1.createRow(0);
- HSSFCell cell = row.createCell(0);
-
- // it's important to create the referenced sheet first
- HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A'
- // TODO - POI crashes if the formula is added before this sheet
- // RuntimeException("Zero length string is an invalid sheet name")
- // Excel doesn't crash but the formula doesn't work until it is
- // re-entered
-
- String inputFormula = "SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"; // as per bug report
- try {
- cell.setCellFormula(inputFormula);
- } catch (StringIndexOutOfBoundsException e) {
- throw new AssertionFailedError("Identified bug 42448");
- }
-
- assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula());
-
- // might as well evaluate the sucker...
-
- addCell(sheet2, 5, 2, 3.0); // A!C6
- addCell(sheet2, 6, 2, 4.0); // A!C7
- addCell(sheet2, 66, 2, 5.0); // A!C67
- addCell(sheet2, 67, 2, 6.0); // A!C68
-
- addCell(sheet1, 6, 1, 7.0); // B7
- addCell(sheet1, 7, 1, 8.0); // B8
- addCell(sheet1, 67, 1, 9.0); // B68
- addCell(sheet1, 68, 1, 10.0); // B69
-
- double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0;
-
- HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
- CellValue cv = fe.evaluate(cell);
-
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
- assertEquals(expectedResult, cv.getNumberValue(), 0.0);
- } finally {
- wb.close();
+ cell.setCellFormula(inputFormula);
+ } catch (StringIndexOutOfBoundsException e) {
+ fail("Identified bug 42448");
}
+
+ assertEquals("SUMPRODUCT(A!C7:A!C67,B8:B68)/B69", cell.getCellFormula());
+
+ // might as well evaluate the sucker...
+
+ addCell(sheet2, 5, 2, 3.0); // A!C6
+ addCell(sheet2, 6, 2, 4.0); // A!C7
+ addCell(sheet2, 66, 2, 5.0); // A!C67
+ addCell(sheet2, 67, 2, 6.0); // A!C68
+
+ addCell(sheet1, 6, 1, 7.0); // B7
+ addCell(sheet1, 7, 1, 8.0); // B8
+ addCell(sheet1, 67, 1, 9.0); // B68
+ addCell(sheet1, 68, 1, 10.0); // B69
+
+ double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0;
+
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ CellValue cv = fe.evaluate(cell);
+
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(expectedResult, cv.getNumberValue(), 0.0);
+
+ wb.close();
}
private static void addCell(HSSFSheet sheet, int rowIx, int colIx,
diff --git a/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java b/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java
index 5bbf8f0131..1931bdbcd1 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/AllFormulaFunctionTests.java
@@ -17,21 +17,17 @@
package org.apache.poi.ss.formula.function;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for this <tt>org.apache.poi.hssf.record.formula.function</tt>.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestFunctionMetadataRegistry.class,
+ TestParseMissingBuiltInFuncs.class,
+ TestReadMissingBuiltInFuncs.class
+})
public class AllFormulaFunctionTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllFormulaFunctionTests.class.getName());
- result.addTestSuite(TestFunctionMetadataRegistry.class);
- result.addTestSuite(TestParseMissingBuiltInFuncs.class);
- result.addTestSuite(TestReadMissingBuiltInFuncs.class);
- return result;
- }
}
diff --git a/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java b/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
index 617f7b052d..aada5e7240 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
@@ -621,12 +621,12 @@ public final class ExcelFileFormatDocFunctionExtractor {
File outFile = new File("functionMetadata-asGenerated.txt");
- if (false) { // set true to use local file
- File dir = new File("c:/temp");
- File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
- processFile(effDocFile, outFile);
- return;
- }
+// if (false) { // set true to use local file
+// File dir = new File("c:/temp");
+// File effDocFile = new File(dir, SOURCE_DOC_FILE_NAME);
+// processFile(effDocFile, outFile);
+// return;
+// }
File tempEFFDocFile = downloadSourceFile();
processFile(tempEFFDocFile, outFile);
diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
index 6a18bd9e14..38afaaa9cb 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/TestParseMissingBuiltInFuncs.java
@@ -17,28 +17,34 @@
package org.apache.poi.ss.formula.function;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
import org.apache.poi.hssf.model.HSSFFormulaParser;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
import org.apache.poi.ss.formula.ptg.FuncPtg;
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
/**
* Tests parsing of some built-in functions that were not properly
* registered in POI as of bug #44675, #44733 (March/April 2008).
- *
- * @author Josh Micich
*/
-public final class TestParseMissingBuiltInFuncs extends TestCase {
+public final class TestParseMissingBuiltInFuncs {
- private static Ptg[] parse(String formula) {
+ private static Ptg[] parse(String formula) throws IOException {
HSSFWorkbook book = new HSSFWorkbook();
- return HSSFFormulaParser.parse(formula, book);
+ Ptg[] ptgs = HSSFFormulaParser.parse(formula, book);
+ book.close();
+ return ptgs;
}
- private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) {
+
+ private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx)
+ throws IOException {
Ptg[] ptgs = parse(formula);
Ptg ptgF = ptgs[ptgs.length-1]; // func is last RPN token in all these formulas
@@ -53,38 +59,49 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
}
assertEquals(expPtgArraySize, ptgs.length);
assertEquals(funcIx, func.getFunctionIndex());
- Class expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class;
+ Class<? extends AbstractFunctionPtg> expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class;
assertEquals(expCls, ptgF.getClass());
// check that parsed Ptg array converts back to formula text OK
HSSFWorkbook book = new HSSFWorkbook();
String reRenderedFormula = HSSFFormulaParser.toFormulaString(book, ptgs);
assertEquals(formula, reRenderedFormula);
+ book.close();
}
- public void testDatedif() {
+ @Test
+ public void testDatedif() throws IOException {
int expSize = 4; // NB would be 5 if POI added tAttrVolatile properly
confirmFunc("DATEDIF(NOW(),NOW(),\"d\")", expSize, false, 351);
}
- public void testDdb() {
+ @Test
+ public void testDdb() throws IOException {
confirmFunc("DDB(1,1,1,1,1)", 6, true, 144);
}
- public void testAtan() {
+
+ @Test
+ public void testAtan() throws IOException {
confirmFunc("ATAN(1)", 2, false, 18);
}
- public void testUsdollar() {
+ @Test
+ public void testUsdollar() throws IOException {
confirmFunc("USDOLLAR(1)", 2, true, 204);
}
- public void testDBCS() {
+ @Test
+ public void testDBCS() throws IOException {
confirmFunc("DBCS(\"abc\")", 2, false, 215);
}
- public void testIsnontext() {
+
+ @Test
+ public void testIsnontext() throws IOException {
confirmFunc("ISNONTEXT(\"abc\")", 2, false, 190);
}
- public void testDproduct() {
+
+ @Test
+ public void testDproduct() throws IOException {
confirmFunc("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", 4, false, 189);
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java b/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java
new file mode 100644
index 0000000000..e2d0095caf
--- /dev/null
+++ b/src/testcases/org/apache/poi/ss/formula/functions/AllSpreadsheetBasedTests.java
@@ -0,0 +1,48 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula.functions;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Direct tests for all implementors of <code>Function</code>.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestCodeFunctionsFromSpreadsheet.class,
+ TestComplexFunctionsFromSpreadsheet.class,
+ TestDeltaFunctionsFromSpreadsheet.class,
+ TestDGetFunctionsFromSpreadsheet.class,
+ TestDStarFunctionsFromSpreadsheet.class,
+ TestFactDoubleFunctionsFromSpreadsheet.class,
+ TestFixedFunctionsFromSpreadsheet.class,
+ TestImaginaryFunctionsFromSpreadsheet.class,
+ TestImRealFunctionsFromSpreadsheet.class,
+ TestIndexFunctionFromSpreadsheet.class,
+ TestIndirectFunctionFromSpreadsheet.class,
+ TestLookupFunctionsFromSpreadsheet.class,
+ TestMatchFunctionsFromSpreadsheet.class,
+ TestQuotientFunctionsFromSpreadsheet.class,
+ TestReptFunctionsFromSpreadsheet.class,
+ TestRomanFunctionsFromSpreadsheet.class,
+ TestWeekNumFunctionsFromSpreadsheet.class,
+ TestWeekNumFunctionsFromSpreadsheet2013.class
+})
+public class AllSpreadsheetBasedTests {
+}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
index 98169a0c3e..e222220cef 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java
@@ -17,198 +17,102 @@
package org.apache.poi.ss.formula.functions;
-import java.io.PrintStream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.CellValue;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
-/**
- *
- */
-public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
-
- private static final class Result {
- public static final int SOME_EVALUATIONS_FAILED = -1;
- public static final int ALL_EVALUATIONS_SUCCEEDED = +1;
- public static final int NO_EVALUATIONS_FOUND = 0;
- }
+@RunWith(Parameterized.class)
+public abstract class BaseTestFunctionsFromSpreadsheet {
/**
* This class defines constants for navigating around the test data spreadsheet used for these tests.
*/
- private static final class SS {
-
+ interface SS {
/** Name of the test spreadsheet (found in the standard test data folder) */
-
/** Name of the first sheet in the spreadsheet (contains comments) */
- public final static String README_SHEET_NAME = "Read Me";
+ String README_SHEET_NAME = "Read Me";
/** Row (zero-based) in each sheet where the evaluation cases start. */
- public static final int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
+ int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
/** Index of the column that contains the function names */
- public static final int COLUMN_INDEX_MARKER = 0; // Column 'A'
- public static final int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
- public static final int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
- public static final int COLUMN_ROW_COMMENT = 3; // Column 'D'
+ int COLUMN_INDEX_MARKER = 0; // Column 'A'
+ int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
+ int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
+ int COLUMN_ROW_COMMENT = 3; // Column 'D'
/** Used to indicate when there are no more test cases on the current sheet */
- public static final String TEST_CASES_END_MARKER = "<end>";
+ String TEST_CASES_END_MARKER = "<end>";
/** Used to indicate that the test on the current row should be ignored */
- public static final String SKIP_CURRENT_TEST_CASE_MARKER = "<skip>";
+ String SKIP_CURRENT_TEST_CASE_MARKER = "<skip>";
}
- // Note - multiple failures are aggregated before ending.
- // If one or more functions fail, a single AssertionFailedError is thrown at the end
- private int _sheetFailureCount;
- private int _sheetSuccessCount;
- private int _evaluationFailureCount;
- private int _evaluationSuccessCount;
-
-
-
- private static void confirmExpectedResult(String msg, HSSFCell expected, CellValue actual) {
- if (expected == null) {
- throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
- }
- if(actual == null) {
- throw new AssertionFailedError(msg + " - actual value was null");
- }
- if(expected.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
- confirmErrorResult(msg, expected.getErrorCellValue(), actual);
- return;
- }
- if(actual.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
- throw unexpectedError(msg, expected, actual.getErrorValue());
- }
- if(actual.getCellType() != expected.getCellType()) {
- throw wrongTypeError(msg, expected, actual);
- }
+ @Parameter(value = 0)
+ public String testName;
+ @Parameter(value = 1)
+ public String filename;
+ @Parameter(value = 2)
+ public HSSFSheet sheet;
+ @Parameter(value = 3)
+ public int formulasRowIdx;
+ @Parameter(value = 4)
+ public HSSFFormulaEvaluator evaluator;
- switch (expected.getCellType()) {
- case HSSFCell.CELL_TYPE_BOOLEAN:
- assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
- break;
- case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
- throw new IllegalStateException("Cannot expect formula as result of formula evaluation: " + msg);
- case HSSFCell.CELL_TYPE_NUMERIC:
- assertEquals(expected.getNumericCellValue(), actual.getNumberValue(), 0.0);
- break;
- case HSSFCell.CELL_TYPE_STRING:
- assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
- break;
- }
- }
+
+ protected static Collection<Object[]> data(Class<? extends BaseTestFunctionsFromSpreadsheet> clazz, String filename) throws Exception {
+ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(filename);
+ confirmReadMeSheet(workbook, clazz);
+ List<Object[]> data = new ArrayList<Object[]>();
- private static AssertionFailedError wrongTypeError(String msgPrefix, HSSFCell expectedCell, CellValue actualValue) {
- return new AssertionFailedError(msgPrefix + " Result type mismatch. Evaluated result was "
- + actualValue.formatAsString()
- + " but the expected result was "
- + formatValue(expectedCell)
- );
- }
- private static AssertionFailedError unexpectedError(String msgPrefix, HSSFCell expected, int actualErrorCode) {
- return new AssertionFailedError(msgPrefix + " Error code ("
- + ErrorEval.getText(actualErrorCode)
- + ") was evaluated, but the expected result was "
- + formatValue(expected)
- );
- }
-
-
- private static void confirmErrorResult(String msgPrefix, int expectedErrorCode, CellValue actual) {
- if(actual.getCellType() != HSSFCell.CELL_TYPE_ERROR) {
- throw new AssertionFailedError(msgPrefix + " Expected cell error ("
- + ErrorEval.getText(expectedErrorCode) + ") but actual value was "
- + actual.formatAsString());
- }
- if(expectedErrorCode != actual.getErrorValue()) {
- throw new AssertionFailedError(msgPrefix + " Expected cell error code ("
- + ErrorEval.getText(expectedErrorCode)
- + ") but actual error code was ("
- + ErrorEval.getText(actual.getErrorValue())
- + ")");
- }
- }
-
-
- private static String formatValue(HSSFCell expecedCell) {
- switch (expecedCell.getCellType()) {
- case HSSFCell.CELL_TYPE_BLANK: return "<blank>";
- case HSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf(expecedCell.getBooleanCellValue());
- case HSSFCell.CELL_TYPE_NUMERIC: return String.valueOf(expecedCell.getNumericCellValue());
- case HSSFCell.CELL_TYPE_STRING: return expecedCell.getRichStringCellValue().getString();
- }
- throw new RuntimeException("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
- }
-
-
- protected void setUp() {
- _sheetFailureCount = 0;
- _sheetSuccessCount = 0;
- _evaluationFailureCount = 0;
- _evaluationSuccessCount = 0;
- }
-
- public void testFunctionsFromTestSpreadsheet() {
- HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook(this.getFilename());
-
- confirmReadMeSheet(workbook);
int nSheets = workbook.getNumberOfSheets();
- for(int i=1; i< nSheets; i++) {
- int sheetResult = processTestSheet(workbook, i, workbook.getSheetName(i));
- switch(sheetResult) {
- case Result.ALL_EVALUATIONS_SUCCEEDED: _sheetSuccessCount ++; break;
- case Result.SOME_EVALUATIONS_FAILED: _sheetFailureCount ++; break;
- }
- }
-
- // confirm results
- String successMsg = "There were "
- + _sheetSuccessCount + " successful sheets(s) and "
- + _evaluationSuccessCount + " function(s) without error";
- if(_sheetFailureCount > 0) {
- String msg = _sheetFailureCount + " sheets(s) failed with "
- + _evaluationFailureCount + " evaluation(s). " + successMsg;
- throw new AssertionFailedError(msg);
- }
- if(false) { // normally no output for successful tests
- System.out.println(getClass().getName() + ": " + successMsg);
+ for(int sheetIdx=1; sheetIdx< nSheets; sheetIdx++) {
+ HSSFSheet sheet = workbook.getSheetAt(sheetIdx);
+ processFunctionGroup(data, sheet, SS.START_TEST_CASES_ROW_INDEX, null, filename);
}
+
+ workbook.close();
+
+ return data;
}
- protected abstract String getFilename();
-
- private int processTestSheet(HSSFWorkbook workbook, int sheetIndex, String sheetName) {
- HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
- HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);
- int maxRows = sheet.getLastRowNum()+1;
- int result = Result.NO_EVALUATIONS_FOUND; // so far
+ private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String testFocusFunctionName, String filename) {
+ HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook());
- String currentGroupComment = null;
- for(int rowIndex=SS.START_TEST_CASES_ROW_INDEX; rowIndex<maxRows; rowIndex++) {
+ String currentGroupComment = "";
+ final int maxRows = sheet.getLastRowNum()+1;
+ for(int rowIndex=startRowIndex; rowIndex<maxRows; rowIndex++) {
HSSFRow r = sheet.getRow(rowIndex);
- String newMarkerValue = getMarkerColumnValue(r);
if(r == null) {
continue;
}
+ String newMarkerValue = getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
if(SS.TEST_CASES_END_MARKER.equalsIgnoreCase(newMarkerValue)) {
// normal exit point
- return result;
+ return;
}
if(SS.SKIP_CURRENT_TEST_CASE_MARKER.equalsIgnoreCase(newMarkerValue)) {
// currently disabled test case row
@@ -217,66 +121,66 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
if(newMarkerValue != null) {
currentGroupComment = newMarkerValue;
}
- HSSFCell c = r.getCell(SS.COLUMN_INDEX_EVALUATION);
- if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
+ HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
+ if (evalCell == null || evalCell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
continue;
}
- CellValue actualValue = evaluator.evaluate(c);
- HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
- String rowComment = getRowCommentColumnValue(r);
-
- String msgPrefix = formatTestCaseDetails(this.getFilename(),sheetName, r.getRowNum(), c, currentGroupComment, rowComment);
- try {
- confirmExpectedResult(msgPrefix, expectedValueCell, actualValue);
- _evaluationSuccessCount ++;
- if(result != Result.SOME_EVALUATIONS_FAILED) {
- result = Result.ALL_EVALUATIONS_SUCCEEDED;
- }
- } catch (RuntimeException e) {
- _evaluationFailureCount ++;
- printShortStackTrace(System.err, e);
- result = Result.SOME_EVALUATIONS_FAILED;
- } catch (AssertionFailedError e) {
- _evaluationFailureCount ++;
- printShortStackTrace(System.err, e);
- result = Result.SOME_EVALUATIONS_FAILED;
- }
+ String rowComment = getCellTextValue(r, SS.COLUMN_ROW_COMMENT, "row comment");
+ String testName = (currentGroupComment+'\n'+rowComment).replace("null", "").trim().replace("\n", " - ");
+ if ("".equals(testName)) {
+ testName = evalCell.getCellFormula();
+ }
+
+ data.add(new Object[]{testName, filename, sheet, rowIndex, evaluator});
}
- throw new RuntimeException("Missing end marker '" + SS.TEST_CASES_END_MARKER
- + "' on sheet '" + sheetName + "'");
-
+ fail("Missing end marker '" + SS.TEST_CASES_END_MARKER + "' on sheet '" + sheet.getSheetName() + "'");
}
+ @Test
+ public void processFunctionRow() throws Exception {
+ HSSFRow r = sheet.getRow(formulasRowIdx);
+ HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION);
+ HSSFCell expectedCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
+
+ CellReference cr = new CellReference(sheet.getSheetName(), formulasRowIdx, evalCell.getColumnIndex(), false, false);
+ String msg = String.format(Locale.ROOT, "In %s %s {=%s} '%s'"
+ , filename, cr.formatAsString(), evalCell.getCellFormula(), testName);
- private static String formatTestCaseDetails(String filename, String sheetName, int rowIndex, HSSFCell c, String currentGroupComment,
- String rowComment) {
+ CellValue actualValue = evaluator.evaluate(evalCell);
- StringBuffer sb = new StringBuffer();
+ assertNotNull(msg + " - Bad setup data expected value is null", expectedCell);
+ assertNotNull(msg + " - actual value was null", actualValue);
- sb.append("In ").append(filename).append(" ");
+ if (expectedCell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
+ int expectedErrorCode = expectedCell.getErrorCellValue();
+ assertEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
+ assertEquals(msg, ErrorEval.getText(expectedErrorCode), actualValue.formatAsString());
+ assertEquals(msg, expectedErrorCode, actualValue.getErrorValue());
+ assertEquals(msg, ErrorEval.getText(expectedErrorCode), ErrorEval.getText(actualValue.getErrorValue()));
+ return;
+ }
- CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);
- sb.append(cr.formatAsString());
- sb.append(" {=").append(c.getCellFormula()).append("}");
+ // unexpected error
+ assertNotEquals(msg, HSSFCell.CELL_TYPE_ERROR, actualValue.getCellType());
+ assertNotEquals(msg, formatValue(expectedCell), ErrorEval.getText(actualValue.getErrorValue()));
- if(currentGroupComment != null) {
- sb.append(" '");
- sb.append(currentGroupComment);
- if(rowComment != null) {
- sb.append(" - ");
- sb.append(rowComment);
- }
- sb.append("' ");
- } else {
- if(rowComment != null) {
- sb.append(" '");
- sb.append(rowComment);
- sb.append("' ");
- }
- }
+ // wrong type error
+ assertEquals(msg, expectedCell.getCellType(), actualValue.getCellType());
- return sb.toString();
+ switch (expectedCell.getCellType()) {
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ assertEquals(msg, expectedCell.getBooleanCellValue(), actualValue.getBooleanValue());
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+ fail("Cannot expect formula as result of formula evaluation: " + msg);
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), 0.0);
+ break;
+ case HSSFCell.CELL_TYPE_STRING:
+ assertEquals(msg, expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue());
+ break;
+ }
}
/**
@@ -284,57 +188,13 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
* cells. This back-link is to make it easy to find this class if a reader encounters the
* spreadsheet first.
*/
- private void confirmReadMeSheet(HSSFWorkbook workbook) {
+ private static void confirmReadMeSheet(HSSFWorkbook workbook, Class<? extends BaseTestFunctionsFromSpreadsheet> clazz) {
String firstSheetName = workbook.getSheetName(0);
- if(!firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME)) {
- throw new RuntimeException("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'");
- }
+ assertTrue("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'",
+ firstSheetName.equalsIgnoreCase(SS.README_SHEET_NAME));
HSSFSheet sheet = workbook.getSheetAt(0);
String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
- assertEquals("Test class name in spreadsheet comment", getClass().getName(), specifiedClassName);
- }
-
-
- /**
- * Useful to keep output concise when expecting many failures to be reported by this test case
- */
- private static void printShortStackTrace(PrintStream ps, Throwable e) {
- StackTraceElement[] stes = e.getStackTrace();
-
- int startIx = 0;
- // skip any top frames inside junit.framework.Assert
- while(startIx<stes.length) {
- if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
- break;
- }
- startIx++;
- }
- // skip bottom frames (part of junit framework)
- int endIx = startIx+1;
- while(endIx < stes.length) {
- if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
- break;
- }
- endIx++;
- }
- if(startIx >= endIx) {
- // something went wrong. just print the whole stack trace
- e.printStackTrace(ps);
- }
- endIx -= 4; // skip 4 frames of reflection invocation
- ps.println(e.toString());
- for(int i=startIx; i<endIx; i++) {
- ps.println("\tat " + stes[i].toString());
- }
-
- }
-
- private static String getRowCommentColumnValue(HSSFRow r) {
- return getCellTextValue(r, SS.COLUMN_ROW_COMMENT, "row comment");
- }
-
- private static String getMarkerColumnValue(HSSFRow r) {
- return getCellTextValue(r, SS.COLUMN_INDEX_MARKER, "marker");
+ assertEquals("Test class name in spreadsheet comment", clazz.getName(), specifiedClassName);
}
/**
@@ -355,8 +215,21 @@ public abstract class BaseTestFunctionsFromSpreadsheet extends TestCase {
return cell.getRichStringCellValue().getString();
}
- throw new RuntimeException("Bad cell type for '" + columnName + "' column: ("
+ fail("Bad cell type for '" + columnName + "' column: ("
+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+ return "";
}
+ private static String formatValue(HSSFCell expecedCell) {
+ switch (expecedCell.getCellType()) {
+ case HSSFCell.CELL_TYPE_BLANK: return "<blank>";
+ case HSSFCell.CELL_TYPE_BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue());
+ case HSSFCell.CELL_TYPE_NUMERIC: return Double.toString(expecedCell.getNumericCellValue());
+ case HSSFCell.CELL_TYPE_STRING: return expecedCell.getRichStringCellValue().getString();
+ }
+ fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
+ return "";
+ }
+
+
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
index ade50d9d99..3d78d40da6 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestCodeFunctionsFromSpreadsheet.java
@@ -17,15 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests CODE() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestCodeFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "CodeFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestCodeFunctionsFromSpreadsheet.class, "CodeFunctionTestCaseData.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
index 1d2da8a4f0..748b0cacd1 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestComplexFunctionsFromSpreadsheet.java
@@ -17,15 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests COMPLEX() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestComplexFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "ComplexFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestComplexFunctionsFromSpreadsheet.class, "ComplexFunctionTestCaseData.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
index ebc9f7aaf5..4ac7b9861e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDGetFunctionsFromSpreadsheet.java
@@ -16,12 +16,16 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests DGET() as loaded from a test data spreadsheet.
*/
public class TestDGetFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "DGet.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestDGetFunctionsFromSpreadsheet.class, "DGet.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
index da9375d8cb..0d20d98d5d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDStarFunctionsFromSpreadsheet.java
@@ -16,12 +16,16 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests D*() functions as loaded from a test data spreadsheet.
*/
public class TestDStarFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "DStar.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestDStarFunctionsFromSpreadsheet.class, "DStar.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
index a15cf7cf73..68b281d4bb 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDeltaFunctionsFromSpreadsheet.java
@@ -16,14 +16,16 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
-* Tests DELTA() as loaded from a test data spreadsheet.<p/>
-*
-* @author cedric dot walter @ gmail dot com
-*/
+ * Tests DELTA() as loaded from a test data spreadsheet.<p/>
+ */
public class TestDeltaFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "DeltaFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestDeltaFunctionsFromSpreadsheet.class, "DeltaFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
index d56e14df2c..fb45ac2fa9 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests FactDouble() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestFactDoubleFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "FactDoubleFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestFactDoubleFunctionsFromSpreadsheet.class, "FactDoubleFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
index 70a8a3dbfd..a5efd75e2e 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestFixedFunctionsFromSpreadsheet.java
@@ -17,13 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests FIXED() as loaded from a test data spreadsheet.
*/
public class TestFixedFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "57003-FixedFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestFixedFunctionsFromSpreadsheet.class, "57003-FixedFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
index a64335517c..db98cff93b 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestImRealFunctionsFromSpreadsheet.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests ImReal() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestImRealFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "ImRealFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestImRealFunctionsFromSpreadsheet.class, "ImRealFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
index c5b74ac0c7..9693025516 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestImaginaryFunctionsFromSpreadsheet.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests Imaginary() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestImaginaryFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "ImaginaryFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestImaginaryFunctionsFromSpreadsheet.class, "ImaginaryFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
index 214e01536b..0370b627d6 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndexFunctionFromSpreadsheet.java
@@ -17,13 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests INDEX() as loaded from a test data spreadsheet.<p/>
*/
public final class TestIndexFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "IndexFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestIndexFunctionFromSpreadsheet.class, "IndexFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
index 3d39308c3b..c475ef526d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestIndirectFunctionFromSpreadsheet.java
@@ -17,6 +17,10 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests INDIRECT() as loaded from a test data spreadsheet.<p/>
*
@@ -25,9 +29,8 @@ package org.apache.poi.ss.formula.functions;
* more easily.
*/
public final class TestIndirectFunctionFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "IndirectFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestIndirectFunctionFromSpreadsheet.class, "IndirectFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
index 76386e9b6c..6d95561d50 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLookupFunctionsFromSpreadsheet.java
@@ -17,7 +17,9 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+import org.junit.runners.Parameterized.Parameters;
/**
* Tests lookup functions (VLOOKUP, HLOOKUP, LOOKUP, MATCH) as loaded from a test data spreadsheet.<p/>
@@ -29,9 +31,8 @@ package org.apache.poi.ss.formula.functions;
* more easily.
*/
public final class TestLookupFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "LookupFunctionsTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestLookupFunctionsFromSpreadsheet.class, "LookupFunctionsTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
index 725946a9ed..dce2927337 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestMatchFunctionsFromSpreadsheet.java
@@ -17,7 +17,9 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+import org.junit.runners.Parameterized.Parameters;
/**
* Tests Match functions as loaded from a test data spreadsheet.<p/>
@@ -27,9 +29,8 @@ package org.apache.poi.ss.formula.functions;
* more easily.
*/
public final class TestMatchFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "MatchFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestMatchFunctionsFromSpreadsheet.class, "MatchFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
index 3d68845e50..62c4c10f2d 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestQuotientFunctionsFromSpreadsheet.java
@@ -17,15 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests QUOTIENT() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestQuotientFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "QuotientFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestQuotientFunctionsFromSpreadsheet.class, "QuotientFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
index 3aebcc5050..c0c11eae6a 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestReptFunctionsFromSpreadsheet.java
@@ -17,15 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests REPT() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestReptFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- @Override
- protected String getFilename() {
- return "ReptFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestReptFunctionsFromSpreadsheet.class, "ReptFunctionTestCaseData.xls");
}
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
index a17b9f8974..687c7b8319 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestRomanFunctionsFromSpreadsheet.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests Roman() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestRomanFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "RomanFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestRomanFunctionsFromSpreadsheet.class, "RomanFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
index 77b832ea14..c2e41dd4a4 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java
@@ -17,14 +17,16 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests WeekNum() as loaded from a test data spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestWeekNumFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
- return "WeekNumFunctionTestCaseData.xls";
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
+ return data(TestWeekNumFunctionsFromSpreadsheet.class, "WeekNumFunctionTestCaseData.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
index d7d286468a..b75a419080 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet2013.java
@@ -17,15 +17,17 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Collection;
+
+import org.junit.runners.Parameterized.Parameters;
+
/**
* Tests WeekNum() as loaded from a test data 2013 excel spreadsheet.<p/>
- *
- * @author cedric dot walter @ gmail dot com
*/
public class TestWeekNumFunctionsFromSpreadsheet2013 extends BaseTestFunctionsFromSpreadsheet {
-
- protected String getFilename() {
+ @Parameters(name="{0}")
+ public static Collection<Object[]> data() throws Exception {
//Only open this file with Excel 2013 to keep binary specific to that version
- return "WeekNumFunctionTestCaseData2013.xls";
+ return data(TestWeekNumFunctionsFromSpreadsheet2013.class, "WeekNumFunctionTestCaseData2013.xls");
}
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
index 968d926eef..bb3220743c 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestExternalFunctionFormulas.java
@@ -17,13 +17,7 @@
package org.apache.poi.ss.formula.ptg;
-import org.apache.poi.util.TempFile;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.HSSFFormulaParser;
@@ -32,45 +26,53 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellValue;
+import org.junit.Test;
+
/**
* Tests for functions from external workbooks (e.g. YEARFRAC).
*/
-public final class TestExternalFunctionFormulas extends TestCase {
+public final class TestExternalFunctionFormulas {
/**
* tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that
*/
- public void testReadFormulaContainingExternalFunction() {
+ @Test
+ public void testReadFormulaContainingExternalFunction() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
String expectedFormula = "YEARFRAC(B1,C1)";
HSSFSheet sht = wb.getSheetAt(0);
String cellFormula = sht.getRow(0).getCell(0).getCellFormula();
assertEquals(expectedFormula, cellFormula);
+
+ wb.close();
}
- public void testParse() {
+ @Test
+ public void testParse() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
Ptg[] ptgs = HSSFFormulaParser.parse("YEARFRAC(B1,C1)", wb);
assertEquals(4, ptgs.length);
assertEquals(NameXPtg.class, ptgs[0].getClass());
wb.getSheetAt(0).getRow(0).createCell(6).setCellFormula("YEARFRAC(C1,B1)");
- if (false) {
- // In case you fancy checking in excel
- try {
- File tempFile = TempFile.createTempFile("testExtFunc", ".xls");
- FileOutputStream fout = new FileOutputStream(tempFile);
- wb.write(fout);
- fout.close();
- System.out.println("check out " + tempFile.getAbsolutePath());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+// if (false) {
+// // In case you fancy checking in excel
+// try {
+// File tempFile = TempFile.createTempFile("testExtFunc", ".xls");
+// FileOutputStream fout = new FileOutputStream(tempFile);
+// wb.write(fout);
+// fout.close();
+// System.out.println("check out " + tempFile.getAbsolutePath());
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// }
+ wb.close();
}
- public void testEvaluate() {
+ @Test
+ public void testEvaluate() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
@@ -79,6 +81,7 @@ public final class TestExternalFunctionFormulas extends TestCase {
confirmCellEval(sheet, 2, 0, fe, "YEARFRAC(B3,C3,D3)", 0.0);
confirmCellEval(sheet, 3, 0, fe, "IF(ISEVEN(3),1.2,1.6)", 1.6);
confirmCellEval(sheet, 4, 0, fe, "IF(ISODD(3),1.2,1.6)", 1.2);
+ wb.close();
}
private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
index e73befca43..914b279866 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
@@ -17,8 +17,6 @@
package org.apache.poi.ss.usermodel;
-import junit.framework.TestCase;
-
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.DataValidation.ErrorStyle;
import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType;
@@ -27,13 +25,14 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.junit.Test;
/**
* Class for testing Excel's data validation mechanism
*
* @author Dragos Buleandra ( dragos.buleandra@trade2b.ro )
*/
-public abstract class BaseTestDataValidation extends TestCase {
+public abstract class BaseTestDataValidation {
private final ITestDataProvider _testDataProvider;
private static final POILogger log = POILogFactory.getLogger(BaseTestDataValidation.class);
@@ -465,7 +464,8 @@ public abstract class BaseTestDataValidation extends TestCase {
va.addValidation(OperatorType.LESS_OR_EQUAL, "4", null, ErrorStyle.STOP, "Less than or equal to 4", "-", false, true, false);
}
- public void testDataValidation() {
+ @Test
+ public void testDataValidation() throws Exception {
log("\nTest no. 2 - Test Excel's Data validation mechanism");
Workbook wb = _testDataProvider.createWorkbook();
WorkbookFormatter wf = new WorkbookFormatter(wb);
@@ -491,7 +491,9 @@ public abstract class BaseTestDataValidation extends TestCase {
addCustomValidations(wf);
log("done !");
- wb = _testDataProvider.writeOutAndReadBack(wb);
+ _testDataProvider.writeOutAndReadBack(wb).close();
+
+ wb.close();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
index f9346a67af..0e05490106 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
@@ -17,19 +17,24 @@
package org.apache.poi.ss.usermodel;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+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 org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
+import org.junit.Test;
/**
* Tests of implementations of {@link org.apache.poi.ss.usermodel.Name}.
*
* @author Yegor Kozlov
*/
-public abstract class BaseTestNamedRange extends TestCase {
+public abstract class BaseTestNamedRange {
private final ITestDataProvider _testDataProvider;
@@ -37,11 +42,12 @@ public abstract class BaseTestNamedRange extends TestCase {
_testDataProvider = testDataProvider;
}
- public final void testCreate(){
+ @Test
+ public final void testCreate() throws Exception {
// Create a new workbook
Workbook wb = _testDataProvider.createWorkbook();
- Sheet sheet1 = wb.createSheet("Test1");
- Sheet sheet2 = wb.createSheet("Testing Named Ranges");
+ wb.createSheet("Test1");
+ wb.createSheet("Testing Named Ranges");
Name name1 = wb.createName();
name1.setNameName("testOne");
@@ -101,24 +107,31 @@ public abstract class BaseTestNamedRange extends TestCase {
// expected during successful test
}
}
+
+ wb.close();
}
- public final void testUnicodeNamedRange() {
- Workbook workBook = _testDataProvider.createWorkbook();
- workBook.createSheet("Test");
- Name name = workBook.createName();
+ @Test
+ public final void testUnicodeNamedRange() throws Exception {
+ Workbook wb1 = _testDataProvider.createWorkbook();
+ wb1.createSheet("Test");
+ Name name = wb1.createName();
name.setNameName("\u03B1");
name.setRefersToFormula("Test!$D$3:$E$8");
- Workbook workBook2 = _testDataProvider.writeOutAndReadBack(workBook);
- Name name2 = workBook2.getNameAt(0);
+ Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+ Name name2 = wb2.getNameAt(0);
assertEquals("\u03B1", name2.getNameName());
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
+
+ wb2.close();
+ wb1.close();
}
- public final void testAddRemove() {
+ @Test
+ public final void testAddRemove() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
assertEquals(0, wb.getNumberOfNames());
Name name1 = wb.createName();
@@ -138,9 +151,12 @@ public abstract class BaseTestNamedRange extends TestCase {
wb.removeName(0);
assertEquals(1, wb.getNumberOfNames());
+
+ wb.close();
}
- public final void testScope() {
+ @Test
+ public final void testScope() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet();
wb.createSheet();
@@ -186,6 +202,8 @@ public abstract class BaseTestNamedRange extends TestCase {
if("aaa".equals(wb.getNameAt(i).getNameName())) cnt++;
}
assertEquals(3, cnt);
+
+ wb.close();
}
/**
@@ -193,21 +211,22 @@ public abstract class BaseTestNamedRange extends TestCase {
* <p>
* Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=13775" target="_bug">#13775</a>
*/
- public final void testMultiNamedRange() {
+ @Test
+ public final void testMultiNamedRange() throws Exception {
// Create a new workbook
- Workbook wb = _testDataProvider.createWorkbook();
+ Workbook wb1 = _testDataProvider.createWorkbook();
// Create a worksheet 'sheet1' in the new workbook
- wb.createSheet ();
- wb.setSheetName (0, "sheet1");
+ wb1.createSheet ();
+ wb1.setSheetName (0, "sheet1");
// Create another worksheet 'sheet2' in the new workbook
- wb.createSheet ();
- wb.setSheetName (1, "sheet2");
+ wb1.createSheet ();
+ wb1.setSheetName (1, "sheet2");
// Create a new named range for worksheet 'sheet1'
- Name namedRange1 = wb.createName();
+ Name namedRange1 = wb1.createName();
// Set the name for the named range for worksheet 'sheet1'
namedRange1.setNameName("RangeTest1");
@@ -216,7 +235,7 @@ public abstract class BaseTestNamedRange extends TestCase {
namedRange1.setRefersToFormula("sheet1" + "!$A$1:$L$41");
// Create a new named range for worksheet 'sheet2'
- Name namedRange2 = wb.createName();
+ Name namedRange2 = wb1.createName();
// Set the name for the named range for worksheet 'sheet2'
namedRange2.setNameName("RangeTest2");
@@ -226,20 +245,24 @@ public abstract class BaseTestNamedRange extends TestCase {
// Write the workbook to a file
// Read the Excel file and verify its content
- wb = _testDataProvider.writeOutAndReadBack(wb);
- Name nm1 =wb.getNameAt(wb.getNameIndex("RangeTest1"));
+ Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+ Name nm1 = wb2.getNameAt(wb2.getNameIndex("RangeTest1"));
assertTrue("Name is "+nm1.getNameName(),"RangeTest1".equals(nm1.getNameName()));
- assertTrue("Reference is "+nm1.getRefersToFormula(),(wb.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getRefersToFormula()));
+ assertTrue("Reference is "+nm1.getRefersToFormula(),(wb2.getSheetName(0)+"!$A$1:$L$41").equals(nm1.getRefersToFormula()));
- Name nm2 =wb.getNameAt(wb.getNameIndex("RangeTest2"));
+ Name nm2 = wb2.getNameAt(wb2.getNameIndex("RangeTest2"));
assertTrue("Name is "+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
- assertTrue("Reference is "+nm2.getRefersToFormula(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getRefersToFormula()));
+ assertTrue("Reference is "+nm2.getRefersToFormula(),(wb2.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getRefersToFormula()));
+
+ wb2.close();
+ wb1.close();
}
/**
* Test to see if the print areas can be retrieved/created in memory
*/
- public final void testSinglePrintArea() {
+ @Test
+ public final void testSinglePrintArea() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -251,12 +274,15 @@ public abstract class BaseTestNamedRange extends TestCase {
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+
+ workbook.close();
}
/**
* For Convenience, don't force sheet names to be used
*/
- public final void testSinglePrintAreaWOSheet()
+ @Test
+ public final void testSinglePrintAreaWOSheet() throws Exception
{
Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
@@ -269,80 +295,91 @@ public abstract class BaseTestNamedRange extends TestCase {
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
+
+ workbook.close();
}
/**
* Test to see if the print area made it to the file
*/
- public final void testPrintAreaFile() {
- Workbook workbook = _testDataProvider.createWorkbook();
- workbook.createSheet("Test Print Area");
- String sheetName = workbook.getSheetName(0);
+ @Test
+ public final void testPrintAreaFile() throws Exception {
+ Workbook wb1 = _testDataProvider.createWorkbook();
+ wb1.createSheet("Test Print Area");
+ String sheetName = wb1.getSheetName(0);
String reference = "$A$1:$B$1";
- workbook.setPrintArea(0, reference);
+ wb1.setPrintArea(0, reference);
- workbook = _testDataProvider.writeOutAndReadBack(workbook);
+ Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
- String retrievedPrintArea = workbook.getPrintArea(0);
+ String retrievedPrintArea = wb2.getPrintArea(0);
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+
+ wb2.close();
+ wb1.close();
}
/**
* Test to see if multiple print areas made it to the file
*/
- public final void testMultiplePrintAreaFile() {
- Workbook workbook = _testDataProvider.createWorkbook();
+ @Test
+ public final void testMultiplePrintAreaFile() throws Exception {
+ Workbook wb1 = _testDataProvider.createWorkbook();
- workbook.createSheet("Sheet1");
- workbook.createSheet("Sheet2");
- workbook.createSheet("Sheet3");
+ wb1.createSheet("Sheet1");
+ wb1.createSheet("Sheet2");
+ wb1.createSheet("Sheet3");
String reference1 = "$A$1:$B$1";
String reference2 = "$B$2:$D$5";
String reference3 = "$D$2:$F$5";
- workbook.setPrintArea(0, reference1);
- workbook.setPrintArea(1, reference2);
- workbook.setPrintArea(2, reference3);
+ wb1.setPrintArea(0, reference1);
+ wb1.setPrintArea(1, reference2);
+ wb1.setPrintArea(2, reference3);
//Check created print areas
String retrievedPrintArea;
- retrievedPrintArea = workbook.getPrintArea(0);
+ retrievedPrintArea = wb1.getPrintArea(0);
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
- retrievedPrintArea = workbook.getPrintArea(1);
+ retrievedPrintArea = wb1.getPrintArea(1);
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
- retrievedPrintArea = workbook.getPrintArea(2);
+ retrievedPrintArea = wb1.getPrintArea(2);
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
// Check print areas after re-reading workbook
- workbook = _testDataProvider.writeOutAndReadBack(workbook);
+ Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
- retrievedPrintArea = workbook.getPrintArea(0);
+ retrievedPrintArea = wb2.getPrintArea(0);
assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
assertEquals("Sheet1!" + reference1, retrievedPrintArea);
- retrievedPrintArea = workbook.getPrintArea(1);
+ retrievedPrintArea = wb2.getPrintArea(1);
assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
assertEquals("Sheet2!" + reference2, retrievedPrintArea);
- retrievedPrintArea = workbook.getPrintArea(2);
+ retrievedPrintArea = wb2.getPrintArea(2);
assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
assertEquals("Sheet3!" + reference3, retrievedPrintArea);
+
+ wb2.close();
+ wb1.close();
}
/**
* Tests the setting of print areas with coordinates (Row/Column designations)
*
*/
- public final void testPrintAreaCoords(){
+ @Test
+ public final void testPrintAreaCoords() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
String sheetName = workbook.getSheetName(0);
@@ -353,6 +390,8 @@ public abstract class BaseTestNamedRange extends TestCase {
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+
+ workbook.close();
}
@@ -360,7 +399,8 @@ public abstract class BaseTestNamedRange extends TestCase {
* Tests the parsing of union area expressions, and re-display in the presence of sheet names
* with special characters.
*/
- public final void testPrintAreaUnion(){
+ @Test
+ public final void testPrintAreaUnion() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
@@ -369,13 +409,16 @@ public abstract class BaseTestNamedRange extends TestCase {
String retrievedPrintArea = workbook.getPrintArea(0);
assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
assertEquals("'Test Print Area'!$A$1:$B$1,'Test Print Area'!$D$1:$F$2", retrievedPrintArea);
+
+ workbook.close();
}
/**
* Verifies an existing print area is deleted
*
*/
- public final void testPrintAreaRemove() {
+ @Test
+ public final void testPrintAreaRemove() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
workbook.createSheet("Test Print Area");
workbook.getSheetName(0);
@@ -388,47 +431,53 @@ public abstract class BaseTestNamedRange extends TestCase {
workbook.removePrintArea(0);
assertNull("PrintArea was not removed", workbook.getPrintArea(0));
+ workbook.close();
}
/**
* Test that multiple named ranges can be added written and read
*/
- public final void testMultipleNamedWrite() {
- Workbook wb = _testDataProvider.createWorkbook();
+ @Test
+ public final void testMultipleNamedWrite() throws Exception {
+ Workbook wb1 = _testDataProvider.createWorkbook();
- wb.createSheet("testSheet1");
- String sheetName = wb.getSheetName(0);
+ wb1.createSheet("testSheet1");
+ String sheetName = wb1.getSheetName(0);
assertEquals("testSheet1", sheetName);
//Creating new Named Range
- Name newNamedRange = wb.createName();
+ Name newNamedRange = wb1.createName();
newNamedRange.setNameName("RangeTest");
newNamedRange.setRefersToFormula(sheetName + "!$D$4:$E$8");
//Creating another new Named Range
- Name newNamedRange2 = wb.createName();
+ Name newNamedRange2 = wb1.createName();
newNamedRange2.setNameName("AnotherTest");
newNamedRange2.setRefersToFormula(sheetName + "!$F$1:$G$6");
- wb.getNameAt(0);
+ wb1.getNameAt(0);
- wb = _testDataProvider.writeOutAndReadBack(wb);
- Name nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
+ Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+ Name nm =wb2.getNameAt(wb2.getNameIndex("RangeTest"));
assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
- assertTrue("Reference is "+nm.getRefersToFormula(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getRefersToFormula()));
+ assertTrue("Reference is "+nm.getRefersToFormula(),(wb2.getSheetName(0)+"!$D$4:$E$8").equals(nm.getRefersToFormula()));
- nm = wb.getNameAt(wb.getNameIndex("AnotherTest"));
+ nm = wb2.getNameAt(wb2.getNameIndex("AnotherTest"));
assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
assertTrue("Reference is "+nm.getRefersToFormula(),newNamedRange2.getRefersToFormula().equals(nm.getRefersToFormula()));
+
+ wb2.close();
+ wb1.close();
}
/**
* Verifies correct functioning for "single cell named range" (aka "named cell")
*/
- public final void testNamedCell_1() {
+ @Test
+ public final void testNamedCell_1() throws Exception {
// setup for this testcase
String sheetName = "Test Named Cell";
@@ -451,6 +500,7 @@ public abstract class BaseTestNamedRange extends TestCase {
assertNotNull(aNamedCell);
// retrieve the cell at the named range and test its contents
+ @SuppressWarnings("deprecation")
AreaReference aref = new AreaReference(aNamedCell.getRefersToFormula());
assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
@@ -462,12 +512,15 @@ public abstract class BaseTestNamedRange extends TestCase {
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
+
+ wb.close();
}
/**
* Verifies correct functioning for "single cell named range" (aka "named cell")
*/
- public final void testNamedCell_2() {
+ @Test
+ public final void testNamedCell_2() throws Exception {
// setup for this testcase
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
@@ -491,10 +544,13 @@ public abstract class BaseTestNamedRange extends TestCase {
CellReference cref = new CellReference(aNamedCell.getRefersToFormula());
assertNotNull(cref);
Sheet s = wb.getSheet(cref.getSheetName());
+ assertNotNull(s);
Row r = sheet.getRow(cref.getRow());
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
+
+ wb.close();
}
@@ -511,40 +567,40 @@ public abstract class BaseTestNamedRange extends TestCase {
* could do the same, but that would involve adjusting subsequent name indexes across
* all formulas. <p/>
*
- * For the moment, POI has been made to behave more sensibly with uninitialised name
+ * For the moment, POI has been made to behave more sensibly with uninitialized name
* records.
*/
- public final void testUninitialisedNameGetRefersToFormula_bug46973() {
+ @Test
+ public final void testUninitialisedNameGetRefersToFormula_bug46973() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
n.setNameName("UPSState");
- String formula;
- try {
- formula = n.getRefersToFormula();
- } catch (IllegalArgumentException e) {
- if (e.getMessage().equals("ptgs must not be null")) {
- throw new AssertionFailedError("Identified bug 46973");
- }
- throw e;
- }
+ String formula = n.getRefersToFormula();
+
+ // bug 46973: fails here with IllegalArgumentException
+ // ptgs must not be null
+
assertNull(formula);
- assertFalse(n.isDeleted()); // according to exact definition of isDeleted()
+ // according to exact definition of isDeleted()
+ assertFalse(n.isDeleted());
+ wb.close();
}
- public final void testDeletedCell() {
+ @Test
+ public final void testDeletedCell() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
n.setNameName("MyName");
// contrived example to expose bug:
n.setRefersToFormula("if(A1,\"#REF!\", \"\")");
- if (n.isDeleted()) {
- throw new AssertionFailedError("Identified bug in recoginising formulas referring to deleted cells");
- }
-
+ assertFalse("Identified bug in recoginising formulas referring to deleted cells", n.isDeleted());
+
+ wb.close();
}
- public final void testFunctionNames() {
+ @Test
+ public final void testFunctionNames() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Name n = wb.createName();
assertFalse(n.isFunctionName());
@@ -557,9 +613,12 @@ public abstract class BaseTestNamedRange extends TestCase {
n.setFunction(false);
assertFalse(n.isFunctionName());
+
+ wb.close();
}
- public final void testDefferedSetting() {
+ @Test
+ public final void testDefferedSetting() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Name n1 = wb.createName();
assertNull(n1.getRefersToFormula());
@@ -581,6 +640,7 @@ public abstract class BaseTestNamedRange extends TestCase {
} catch(Exception e){
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
}
-
+
+ wb.close();
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java b/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
index 408028d667..c9146ab784 100644
--- a/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
+++ b/src/testcases/org/apache/poi/ss/util/NumberRenderingSpreadsheetGenerator.java
@@ -128,11 +128,11 @@ public class NumberRenderingSpreadsheetGenerator {
row.createCell(5).setCellFormula(matchExpr);
row.createCell(6).setCellFormula(jmExpr.replaceAll("'", "\""));
- if (false) {
- // for observing arithmetic near numeric range boundaries
- row.createCell(7).setCellFormula(cel0ref + " * 1.0001");
- row.createCell(8).setCellFormula(cel0ref + " / 1.0001");
- }
+// if (false) {
+// // for observing arithmetic near numeric range boundaries
+// row.createCell(7).setCellFormula(cel0ref + " * 1.0001");
+// row.createCell(8).setCellFormula(cel0ref + " / 1.0001");
+// }
}
private static String formatLongAsHex(long l) {
@@ -215,10 +215,10 @@ public class NumberRenderingSpreadsheetGenerator {
bb[i+2] = (byte) (val >> 16);
bb[i+1] = (byte) (val >> 8);
bb[i+0] = (byte) (val >> 0);
- if (false) {
- String newVal = interpretLong(bb, i);
- System.out.println("changed offset " + i + " from " + oldVal + " to " + newVal);
- }
+// if (false) {
+// String newVal = interpretLong(bb, i);
+// System.out.println("changed offset " + i + " from " + oldVal + " to " + newVal);
+// }
}