]> source.dussan.org Git - poi.git/commitdiff
Convert the test to using interfaces
authorNick Burch <nick@apache.org>
Wed, 30 Jul 2014 16:56:31 +0000 (16:56 +0000)
committerNick Burch <nick@apache.org>
Wed, 30 Jul 2014 16:56:31 +0000 (16:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614715 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/formula/TestMissingWorkbook.java

index 2fa9fd0fd5ee6c135d0ca4b4feaf091d6bb5529e..50ca5e2988325960e009462f385f3bf57fc48b4d 100644 (file)
 \r
 package org.apache.poi.ss.formula;\r
 \r
+import java.io.IOException;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
 import junit.framework.TestCase;\r
+\r
 import org.apache.poi.hssf.HSSFTestDataSamples;\r
-import org.apache.poi.hssf.usermodel.*;\r
 import org.apache.poi.ss.usermodel.Cell;\r
 import org.apache.poi.ss.usermodel.FormulaEvaluator;\r
-\r
-import java.io.IOException;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
 \r
 public class TestMissingWorkbook extends TestCase {\r
        private static final String MAIN_WORKBOOK_FILENAME = "52575_main.xls";\r
        private static final String SOURCE_DUMMY_WORKBOOK_FILENAME = "source_dummy.xls";\r
        private static final String SOURCE_WORKBOOK_FILENAME = "52575_source.xls";\r
        \r
-       private HSSFWorkbook mainWorkbook;\r
-       private HSSFWorkbook sourceWorkbook;\r
+       private Workbook mainWorkbook;\r
+       private Workbook sourceWorkbook;\r
        \r
        @Override\r
        protected void setUp() throws Exception {\r
@@ -47,9 +52,9 @@ public class TestMissingWorkbook extends TestCase {
        public void testMissingWorkbookMissing() throws IOException {\r
                FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
                \r
-               HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
-               HSSFRow lARow = lSheet.getRow(0);\r
-               HSSFCell lA1Cell = lARow.getCell(0);\r
+               Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+               Row lARow = lSheet.getRow(0);\r
+               Cell lA1Cell = lARow.getCell(0);\r
                \r
                assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
                try {\r
@@ -61,16 +66,16 @@ public class TestMissingWorkbook extends TestCase {
        }\r
        \r
        public void testMissingWorkbookMissingOverride() throws IOException {\r
-               HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
-               HSSFCell lA1Cell = lSheet.getRow(0).getCell(0);\r
-               HSSFCell lB1Cell = lSheet.getRow(1).getCell(0);\r
-               HSSFCell lC1Cell = lSheet.getRow(2).getCell(0);\r
+               Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+               Cell lA1Cell = lSheet.getRow(0).getCell(0);\r
+               Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
+               Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
                \r
                assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
                assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
                assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
                \r
-               HSSFFormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
+               FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
         evaluator.setIgnoreMissingWorkbooks(true);\r
 \r
                assertEquals(Cell.CELL_TYPE_NUMERIC, evaluator.evaluateFormulaCell(lA1Cell));\r
@@ -84,20 +89,21 @@ public class TestMissingWorkbook extends TestCase {
        \r
 \r
        public void testExistingWorkbook() throws IOException {\r
-               HSSFSheet lSheet = mainWorkbook.getSheetAt(0);\r
-               HSSFCell lA1Cell = lSheet.getRow(0).getCell(0);\r
-               HSSFCell lB1Cell = lSheet.getRow(1).getCell(0);\r
-               HSSFCell lC1Cell = lSheet.getRow(2).getCell(0);\r
+               Sheet lSheet = mainWorkbook.getSheetAt(0);\r
+               Cell lA1Cell = lSheet.getRow(0).getCell(0);\r
+               Cell lB1Cell = lSheet.getRow(1).getCell(0);\r
+               Cell lC1Cell = lSheet.getRow(2).getCell(0);\r
                \r
                assertEquals(Cell.CELL_TYPE_FORMULA, lA1Cell.getCellType());\r
                assertEquals(Cell.CELL_TYPE_FORMULA, lB1Cell.getCellType());\r
                assertEquals(Cell.CELL_TYPE_FORMULA, lC1Cell.getCellType());\r
 \r
-               HSSFFormulaEvaluator lMainWorkbookEvaluator = new HSSFFormulaEvaluator(mainWorkbook);\r
-               HSSFFormulaEvaluator lSourceEvaluator = new HSSFFormulaEvaluator(sourceWorkbook);\r
-               HSSFFormulaEvaluator.setupEnvironment(\r
-                               new String[]{MAIN_WORKBOOK_FILENAME, SOURCE_DUMMY_WORKBOOK_FILENAME}, \r
-                               new HSSFFormulaEvaluator[] {lMainWorkbookEvaluator, lSourceEvaluator});\r
+               FormulaEvaluator lMainWorkbookEvaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();\r
+               FormulaEvaluator lSourceEvaluator = sourceWorkbook.getCreationHelper().createFormulaEvaluator();\r
+               Map<String,FormulaEvaluator> workbooks = new HashMap<String, FormulaEvaluator>();\r
+               workbooks.put(MAIN_WORKBOOK_FILENAME, lMainWorkbookEvaluator);\r
+               workbooks.put(SOURCE_DUMMY_WORKBOOK_FILENAME, lSourceEvaluator);\r
+               lMainWorkbookEvaluator.setupReferencedWorkbooks(workbooks);\r
                \r
                assertEquals(Cell.CELL_TYPE_NUMERIC, lMainWorkbookEvaluator.evaluateFormulaCell(lA1Cell));\r
                assertEquals(Cell.CELL_TYPE_STRING, lMainWorkbookEvaluator.evaluateFormulaCell(lB1Cell));\r
@@ -107,5 +113,4 @@ public class TestMissingWorkbook extends TestCase {
                assertEquals("Apache rocks!", lB1Cell.getStringCellValue());\r
                assertEquals(false, lC1Cell.getBooleanCellValue());\r
        }\r
-\r
 }\r