]> source.dussan.org Git - poi.git/commitdiff
minor improvements to junits
authorJosh Micich <josh@apache.org>
Wed, 17 Sep 2008 19:05:39 +0000 (19:05 +0000)
committerJosh Micich <josh@apache.org>
Wed, 17 Sep 2008 19:05:39 +0000 (19:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696401 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java

index 3f84b2ba3548cc576fd9e3e08ab18c15303f1cdc..90c75c5a07795501002113e39a9fe9544a4d0588 100644 (file)
 
 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());
                }
-               
        }
 
        /**
index a0ae950f79b4fd16615a845dbed7c216ca968161..34db8b57c4be10d6aec43d2a7dfc365aab82fde8 100644 (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,7 +186,14 @@ public class TestColumnHelper extends TestCase {
         col9.setMax(27);
         helper.addCleanColIntoCols(cols1, col9);
 
-        System.err.println(cols1);
+        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() {
@@ -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
@@ -250,10 +261,10 @@ public class TestColumnHelper extends TestCase {
     }
     
     public void testGetSetColDefaultStyle() {
-       XSSFWorkbook workbook = new XSSFWorkbook();
-       CTSheet ctSheet = CTSheet.Factory.newInstance();
-       CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
-       XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        CTSheet ctSheet = CTSheet.Factory.newInstance();
+        CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
+        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;
     }
-
 }