minor improvements to junits

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-09-17 19:05:39 +00:00
parent 4ec0dadc6b
commit 162d9bd11d
2 changed files with 25 additions and 24 deletions

View File

@ -17,12 +17,14 @@
package org.apache.poi.xssf.usermodel;
import java.io.InputStream;
import java.io.PrintStream;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.formula.eval.TestFormulasFromSpreadsheet;
import org.apache.poi.hssf.record.formula.functions.TestMathX;
import org.apache.poi.ss.usermodel.Cell;
@ -113,15 +115,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
throw new AssertionFailedError(msg + " - actual value was null");
}
if (expected.getCellType() == Cell.CELL_TYPE_STRING) {
String value = expected.getRichStringCellValue().getString();
if (value.startsWith("#")) {
// TODO - this code never called
expected.setCellType(Cell.CELL_TYPE_ERROR);
// expected.setCellErrorValue(...?);
}
}
switch (expected.getCellType()) {
case Cell.CELL_TYPE_BLANK:
assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
@ -147,7 +140,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
break;
case Cell.CELL_TYPE_STRING:
assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getRichTextStringValue().getString());
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
break;
}
}
@ -155,8 +148,8 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
protected void setUp() throws Exception {
if (workbook == null) {
String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
Package pkg = Package.open(filePath);
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
Package pkg = Package.open(is);
workbook = new XSSFWorkbook( pkg );
sheet = workbook.getSheetAt( 0 );
}
@ -206,7 +199,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
*/
private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, workbook);
FormulaEvaluator evaluator = new FormulaEvaluator(workbook);
int rowIndex = startRowIndex;
while (true) {
@ -252,7 +245,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
int result = Result.NO_EVALUATIONS_FOUND; // so far
short endcolnum = formulasRow.getLastCellNum();
evaluator.setCurrentRow(formulasRow);
// iterate across the row for all the evaluation cases
for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
@ -341,7 +333,6 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
for(int i=startIx; i<endIx; i++) {
ps.println("\tat " + stes[i].toString());
}
}
/**

View File

@ -29,7 +29,11 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
public class TestColumnHelper extends TestCase {
/**
* Tests for {@link ColumnHelper}
*
*/
public final class TestColumnHelper extends TestCase {
public void testCleanColumns() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
@ -182,8 +186,15 @@ public class TestColumnHelper extends TestCase {
col9.setMax(27);
helper.addCleanColIntoCols(cols1, col9);
if (false) {
System.err.println(cols1);
}
// TODO - assert something interesting
CTCol[] colArray = cols1.getColArray();
assertEquals(12, colArray.length);
assertEquals(1, colArray[0].getMin());
assertEquals(16750, colArray[11].getMax());
}
public void testGetColumn() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
@ -230,7 +241,7 @@ public class TestColumnHelper extends TestCase {
public void testGetOrCreateColumn() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
XSSFSheet sheet = workbook.createSheet("Sheet 1");
ColumnHelper columnHelper = sheet.getColumnHelper();
// Check POI 0 based, OOXML 1 based
@ -253,7 +264,7 @@ public class TestColumnHelper extends TestCase {
XSSFWorkbook workbook = new XSSFWorkbook();
CTSheet ctSheet = CTSheet.Factory.newInstance();
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
ColumnHelper columnHelper = sheet.getColumnHelper();
// POI column 3, OOXML column 4
@ -283,7 +294,7 @@ public class TestColumnHelper extends TestCase {
assertEquals(1, columnHelper.getColDefaultStyle(10));
}
private int countColumns(CTWorksheet worksheet) {
private static int countColumns(CTWorksheet worksheet) {
int count;
count = 0;
for (int i = 0; i < worksheet.sizeOfColsArray(); i++) {
@ -296,5 +307,4 @@ public class TestColumnHelper extends TestCase {
}
return count;
}
}