aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/formula/function
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-09-13 12:36:56 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-09-13 12:36:56 +0000
commit118e3ec20a2ecdfb2024088943675b26e5824644 (patch)
tree57437c6c636102b47f42cc07ae745995638addc1 /src/testcases/org/apache/poi/ss/formula/function
parentfbcf869f48e696a28ea364b8ff394476a96cdd21 (diff)
downloadpoi-118e3ec20a2ecdfb2024088943675b26e5824644.tar.gz
poi-118e3ec20a2ecdfb2024088943675b26e5824644.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@1702773 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula/function')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java120
1 files changed, 63 insertions, 57 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
index 9de7e764e7..d28653743c 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
@@ -17,146 +17,152 @@
package org.apache.poi.ss.formula.function;
-import java.lang.reflect.InvocationTargetException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.lang.reflect.InvocationTargetException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
/**
* Tests reading from a sample spreadsheet 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 TestReadMissingBuiltInFuncs extends TestCase {
+public final class TestReadMissingBuiltInFuncs {
/**
* This spreadsheet has examples of calls to the interesting built-in functions in cells A1:A7
*/
private static final String SAMPLE_SPREADSHEET_FILE_NAME = "missingFuncs44675.xls";
+
+ private static HSSFWorkbook wb;
private static HSSFSheet _sheet;
- private static HSSFSheet getSheet() {
- if (_sheet == null) {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_SPREADSHEET_FILE_NAME);
- _sheet = wb.getSheetAt(0);
- }
- return _sheet;
+ @BeforeClass
+ public static void initSheet() {
+ wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_SPREADSHEET_FILE_NAME);
+ try {
+ _sheet = wb.getSheetAt(0);
+ } catch (RecordFormatException e) {
+ if(e.getCause() instanceof InvocationTargetException) {
+ InvocationTargetException ite = (InvocationTargetException) e.getCause();
+ if(ite.getTargetException() instanceof RuntimeException) {
+ RuntimeException re = (RuntimeException) ite.getTargetException();
+ if(re.getMessage().equals("Invalid built-in function index (189)")) {
+ fail("DPRODUCT() registered with wrong index");
+ }
+ }
+ }
+ // some other unexpected error
+ throw e;
+ }
+ }
+
+ @AfterClass
+ public static void closeResources() throws Exception {
+ wb.close();
}
+ @Test
public void testDatedif() {
-
String formula;
try {
formula = getCellFormula(0);
} catch (IllegalStateException e) {
- if(e.getMessage().startsWith("Too few arguments")) {
+ if(e.getMessage().startsWith("Too few arguments")) {
if(e.getMessage().indexOf("AttrPtg") > 0) {
- throw afe("tAttrVolatile not supported in FormulaParser.toFormulaString");
+ fail("tAttrVolatile not supported in FormulaParser.toFormulaString");
}
- throw afe("NOW() registered with 1 arg instead of 0");
+ fail("NOW() registered with 1 arg instead of 0");
}
if(e.getMessage().startsWith("too much stuff")) {
- throw afe("DATEDIF() not registered");
+ fail("DATEDIF() not registered");
}
// some other unexpected error
throw e;
}
assertEquals("DATEDIF(NOW(),NOW(),\"d\")", formula);
}
+
+ @Test
public void testDdb() {
-
String formula = getCellFormula(1);
if("externalflag(1,1,1,1,1)".equals(formula)) {
- throw afe("DDB() not registered");
+ fail("DDB() not registered");
}
assertEquals("DDB(1,1,1,1,1)", formula);
}
+
+ @Test
public void testAtan() {
-
String formula = getCellFormula(2);
- if(formula.equals("ARCTAN(1)")) {
- throw afe("func ix 18 registered as ARCTAN() instead of ATAN()");
+ if("ARCTAN(1)".equals(formula)) {
+ fail("func ix 18 registered as ARCTAN() instead of ATAN()");
}
assertEquals("ATAN(1)", formula);
}
+ @Test
public void testUsdollar() {
-
String formula = getCellFormula(3);
- if(formula.equals("YEN(1)")) {
- throw afe("func ix 204 registered as YEN() instead of USDOLLAR()");
+ if("YEN(1)".equals(formula)) {
+ fail("func ix 204 registered as YEN() instead of USDOLLAR()");
}
assertEquals("USDOLLAR(1)", formula);
}
+ @Test
public void testDBCS() {
-
- String formula;
+ String formula = "";
try {
formula = getCellFormula(4);
} catch (IllegalStateException e) {
if(e.getMessage().startsWith("too much stuff")) {
- throw afe("DBCS() not registered");
+ fail("DBCS() not registered");
}
// some other unexpected error
throw e;
} catch (NegativeArraySizeException e) {
- throw afe("found err- DBCS() registered with -1 args");
+ fail("found err- DBCS() registered with -1 args");
}
- if(formula.equals("JIS(\"abc\")")) {
- throw afe("func ix 215 registered as JIS() instead of DBCS()");
+ if("JIS(\"abc\")".equals(formula)) {
+ fail("func ix 215 registered as JIS() instead of DBCS()");
}
assertEquals("DBCS(\"abc\")", formula);
}
+
+ @Test
public void testIsnontext() {
-
String formula;
try {
formula = getCellFormula(5);
} catch (IllegalStateException e) {
if(e.getMessage().startsWith("too much stuff")) {
- throw afe("ISNONTEXT() registered with wrong index");
+ fail("ISNONTEXT() registered with wrong index");
}
// some other unexpected error
throw e;
}
assertEquals("ISNONTEXT(\"abc\")", formula);
}
+
+ @Test
public void testDproduct() {
-
String formula = getCellFormula(6);
assertEquals("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", formula);
}
private String getCellFormula(int rowIx) {
- HSSFSheet sheet;
- try {
- sheet = getSheet();
- } catch (RecordFormatException e) {
- if(e.getCause() instanceof InvocationTargetException) {
- InvocationTargetException ite = (InvocationTargetException) e.getCause();
- if(ite.getTargetException() instanceof RuntimeException) {
- RuntimeException re = (RuntimeException) ite.getTargetException();
- if(re.getMessage().equals("Invalid built-in function index (189)")) {
- throw afe("DPRODUCT() registered with wrong index");
- }
- }
- }
- // some other unexpected error
- throw e;
- }
- String result = sheet.getRow(rowIx).getCell(0).getCellFormula();
- if (false) {
- System.err.println(result);
- }
+ String result = _sheet.getRow(rowIx).getCell(0).getCellFormula();
+// if (false) {
+// System.err.println(result);
+// }
return result;
}
- private static AssertionFailedError afe(String msg) {
- return new AssertionFailedError(msg);
- }
}