mirror of https://github.com/apache/poi.git
add test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892075 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
87ea84cf48
commit
f15474f1ba
|
@ -17,12 +17,16 @@
|
|||
|
||||
package org.apache.poi.ss.formula.functions;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.ss.formula.eval.*;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.CellValue;
|
||||
import org.apache.poi.util.LocaleUtil;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -73,6 +77,18 @@ final class TestTimeValue {
|
|||
"Math.E evals to invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimeValueInHSSF() throws IOException {
|
||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
HSSFRow row = sheet.createRow(0);
|
||||
row.createCell(0).setCellValue("8/22/2011 12:00");
|
||||
HSSFCell cell = row.createCell(1);
|
||||
confirmNumericResult(fe, cell, "TIMEVALUE(A1)", 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
private ValueEval invokeTimeValue(ValueEval text) {
|
||||
return new TimeValue().evaluate(0, 0, text);
|
||||
}
|
||||
|
@ -93,4 +109,12 @@ final class TestTimeValue {
|
|||
assertEquals(ErrorEval.class, result.getClass());
|
||||
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), ((ErrorEval) result).getErrorCode());
|
||||
}
|
||||
|
||||
private static void confirmNumericResult(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText, double expectedResult) {
|
||||
cell.setCellFormula(formulaText);
|
||||
fe.notifyUpdateCell(cell);
|
||||
CellValue result = fe.evaluate(cell);
|
||||
assertEquals(result.getCellType(), CellType.NUMERIC);
|
||||
assertEquals(expectedResult, result.getNumberValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue