poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1702773 [2/2] - in /poi/trunk/src: contrib/src/ examples/src/org/apache/poi/ss/examples/ examples/src/org/apache/poi/xssf/eventusermodel/ java/org/apache/poi/hssf/record/ ooxml/java/org/apache/poi/xwpf/usermodel/ ooxml/testcases/org/apache...
Date Sun, 13 Sep 2015 12:36:58 GMT
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java Sun Sep 13 12:36:56 2015
@@ -20,6 +20,9 @@ package org.apache.poi.xssf.usermodel;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeTrue;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,6 +40,8 @@ import org.apache.poi.ss.usermodel.Formu
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 import org.junit.AfterClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -56,6 +61,7 @@ import org.junit.runners.Parameterized.P
  */
 @RunWith(Parameterized.class)
 public final class TestFormulaEvaluatorOnXSSF {
+    private static final POILogger logger = POILogFactory.getLogger(TestFormulaEvaluatorOnXSSF.class);
 
     private static XSSFWorkbook workbook;
     private static Sheet sheet;
@@ -144,12 +150,15 @@ public final class TestFormulaEvaluatorO
     private static void processFunctionGroup(List<Object[]> data, int startRowIndex, String testFocusFunctionName) {
         for (int rowIndex = startRowIndex; true; rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION) {
             Row r = sheet.getRow(rowIndex);
+
+            // only evaluate non empty row
+            if(r == null) continue;
+            
             String targetFunctionName = getTargetFunctionName(r);
-            if(targetFunctionName == null) {
-                fail("Test spreadsheet cell empty on row ("
-                    + (rowIndex+1) + "). Expected function name or '"
-                    + SS.FUNCTION_NAMES_END_SENTINEL + "'");
-            }
+            assertNotNull("Test spreadsheet cell empty on row ("
+                + (rowIndex+1) + "). Expected function name or '"
+                + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName);
+
             if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
                 // found end of functions list
                 break;
@@ -158,11 +167,10 @@ public final class TestFormulaEvaluatorO
                 
                 // expected results are on the row below
                 Row expectedValuesRow = sheet.getRow(rowIndex + 1);
-                if(expectedValuesRow == null) {
-                    int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row
-                    fail("Missing expected values row for function '" 
-                        + targetFunctionName + " (row " + missingRowNum + ")"); 
-                }
+                // +1 for 1-based, +1 for next row
+                assertNotNull("Missing expected values row for function '" 
+                    + targetFunctionName + " (row " + rowIndex + 2 + ")"
+                    , expectedValuesRow);
                 
                 data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1});
             }
@@ -180,12 +188,9 @@ public final class TestFormulaEvaluatorO
 		// iterate across the row for all the evaluation cases
 		for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
 			Cell c = formulasRow.getCell(colnum);
-			if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
-				continue;
-			}
-			if(isIgnoredFormulaTestCase(c.getCellFormula())) {
-				continue;
-			}
+			assumeNotNull(c);
+			assumeTrue(c.getCellType() == Cell.CELL_TYPE_FORMULA);
+			ignoredFormulaTestCase(c.getCellFormula());
 
 			CellValue actValue = evaluator.evaluate(c);
 			Cell expValue = (expectedValuesRow == null) ? null : expectedValuesRow.getCell(colnum);
@@ -230,19 +235,16 @@ public final class TestFormulaEvaluatorO
 	/*
 	 * TODO - these are all formulas which currently (Apr-2008) break on ooxml 
 	 */
-	private static boolean isIgnoredFormulaTestCase(String cellFormula) {
-		if ("COLUMN(1:2)".equals(cellFormula) || "ROW(2:3)".equals(cellFormula)) {
-			// full row ranges are not parsed properly yet.
-			// These cases currently work in svn trunk because of another bug which causes the 
-			// formula to get rendered as COLUMN($A$1:$IV$2) or ROW($A$2:$IV$3) 
-			return true;
-		}
-		if ("ISREF(currentcell())".equals(cellFormula)) {
-			// currently throws NPE because unknown function "currentcell" causes name lookup 
-			// Name lookup requires some equivalent object of the Workbook within xSSFWorkbook.
-			return true;
-		}
-		return false;
+	private static void ignoredFormulaTestCase(String cellFormula) {
+        // full row ranges are not parsed properly yet.
+        // These cases currently work in svn trunk because of another bug which causes the 
+        // formula to get rendered as COLUMN($A$1:$IV$2) or ROW($A$2:$IV$3) 
+	    assumeFalse("COLUMN(1:2)".equals(cellFormula));
+	    assumeFalse("ROW(2:3)".equals(cellFormula));
+
+        // currently throws NPE because unknown function "currentcell" causes name lookup 
+        // Name lookup requires some equivalent object of the Workbook within xSSFWorkbook.
+	    assumeFalse("ISREF(currentcell())".equals(cellFormula));
 	}
 
 	/**
@@ -250,12 +252,12 @@ public final class TestFormulaEvaluatorO
 	 */
 	private static String getTargetFunctionName(Row r) {
 		if(r == null) {
-			System.err.println("Warning - given null row, can't figure out function name");
+            logger.log(POILogger.WARN, "Warning - given null row, can't figure out function name");
 			return null;
 		}
 		Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME);
 		if(cell == null) {
-			System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name");
+            logger.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name");
 			return null;
 		}
 		if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java Sun Sep 13 12:36:56 2015
@@ -17,15 +17,20 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.util.Collection;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeTrue;
 
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.ss.formula.eval.TestFormulasFromSpreadsheet;
 import org.apache.poi.ss.formula.functions.TestMathX;
 import org.apache.poi.ss.usermodel.Cell;
@@ -33,268 +38,193 @@ import org.apache.poi.ss.usermodel.CellV
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Tests formulas for multi sheet reference (i.e. SUM(Sheet1:Sheet5!A1))
  */
-public final class TestMultiSheetFormulaEvaluatorOnXSSF extends TestCase {
+@RunWith(Parameterized.class)
+public final class TestMultiSheetFormulaEvaluatorOnXSSF {
     private static final POILogger logger = POILogFactory.getLogger(TestFormulasFromSpreadsheet.class);
 
-	private static final class Result {
-		public static final int SOME_EVALUATIONS_FAILED = -1;
-		public static final int ALL_EVALUATIONS_SUCCEEDED = +1;
-		public static final int NO_EVALUATIONS_FOUND = 0;
-	}
+    private static XSSFWorkbook workbook;
+    private static Sheet sheet;
+    private static FormulaEvaluator evaluator;
 
 	/**
 	 * This class defines constants for navigating around the test data spreadsheet used for these tests.
 	 */
-	private static final class SS {
+	interface SS {
 
 		/**
 		 * Name of the test spreadsheet (found in the standard test data folder)
 		 */
-		public final static String FILENAME = "FormulaSheetRange.xlsx";
+		String FILENAME = "FormulaSheetRange.xlsx";
 		/**
 		 * Row (zero-based) in the test spreadsheet where the function examples start.
 		 */
-		public static final int START_FUNCTIONS_ROW_INDEX = 10; // Row '11'
+		int START_FUNCTIONS_ROW_INDEX = 10; // Row '11'
 		/**
 		 * Index of the column that contains the function names
 		 */
-		public static final int COLUMN_INDEX_FUNCTION_NAME = 0; // Column 'A'
+		int COLUMN_INDEX_FUNCTION_NAME = 0; // Column 'A'
 		/**
 		 * Index of the column that contains the test names
 		 */
-		public static final int COLUMN_INDEX_TEST_NAME = 1; // Column 'B'
+		int COLUMN_INDEX_TEST_NAME = 1; // Column 'B'
 		/**
 		 * Used to indicate when there are no more functions left
 		 */
-		public static final String FUNCTION_NAMES_END_SENTINEL = "<END>";
+		String FUNCTION_NAMES_END_SENTINEL = "<END>";
 
 		/**
 		 * Index of the column where the test expected value is present
 		 */
-		public static final short COLUMN_INDEX_EXPECTED_VALUE = 2; // Column 'C'
+		short COLUMN_INDEX_EXPECTED_VALUE = 2; // Column 'C'
 		/**
 		 * Index of the column where the test actual value is present
 		 */
-		public static final short COLUMN_INDEX_ACTUAL_VALUE = 3; // Column 'D'
+		short COLUMN_INDEX_ACTUAL_VALUE = 3; // Column 'D'
 		/**
 		 * Test sheet name (sheet with all test formulae)
 		 */
-		public static final String TEST_SHEET_NAME = "test";
-	}
-
-	private XSSFWorkbook workbook;
-	private Sheet sheet;
-	// Note - multiple failures are aggregated before ending.
-	// If one or more functions fail, a single AssertionFailedError is thrown at the end
-	private int _functionFailureCount;
-	private int _functionSuccessCount;
-	private int _evaluationFailureCount;
-	private int _evaluationSuccessCount;
-
-	private static void confirmExpectedResult(String msg, Cell expected, CellValue actual) {
-		if (expected == null) {
-			throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
-		}
-		if(actual == null) {
-			throw new AssertionFailedError(msg + " - actual value was null");
-		}
-		
-		switch (expected.getCellType()) {
-			case Cell.CELL_TYPE_BLANK:
-				assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
-				break;
-			case Cell.CELL_TYPE_BOOLEAN:
-				assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actual.getCellType());
-				assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
-				break;
-			case Cell.CELL_TYPE_ERROR:
-				assertEquals(msg, Cell.CELL_TYPE_ERROR, actual.getCellType());
-				if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
-					assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue());
-				}
-				break;
-			case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
-				throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg);
-			case Cell.CELL_TYPE_NUMERIC:
-				assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actual.getCellType());
-				TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
-//				double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
-//				double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
-//				assertTrue(msg, delta <= pctExpected);
-				break;
-			case Cell.CELL_TYPE_STRING:
-				assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
-				assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
-				break;
-		}
+		String TEST_SHEET_NAME = "test";
 	}
 
+    @Parameter(value = 0)
+	public String targetTestName;
+	@Parameter(value = 1)
+    public String targetFunctionName;
+    @Parameter(value = 2)
+    public int formulasRowIdx;
+
+    @AfterClass
+    public static void closeResource() throws Exception {
+        workbook.close();
+    }
+
+    @Parameters(name="{0}")
+    public static Collection<Object[]> data() throws Exception {
+        workbook = new XSSFWorkbook( OPCPackage.open(HSSFTestDataSamples.getSampleFile(SS.FILENAME), PackageAccess.READ) );
+        sheet = workbook.getSheet( SS.TEST_SHEET_NAME );
+        evaluator = new XSSFFormulaEvaluator(workbook);
+
+        List<Object[]> data = new ArrayList<Object[]>();
+
+        processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, null);
+
+        return data;
+    }
+
+    /**
+     * @param startRowIndex row index in the spreadsheet where the first function/operator is found
+     * @param testFocusFunctionName name of a single function/operator to test alone.
+     * Typically pass <code>null</code> to test all functions
+     */
+    private static void processFunctionGroup(List<Object[]> data, int startRowIndex, String testFocusFunctionName) {
+        for (int rowIndex = startRowIndex; true; rowIndex++) {
+            Row r = sheet.getRow(rowIndex);
+
+            // only evaluate non empty row
+            if(r == null) continue;
+
+            String targetFunctionName = getTargetFunctionName(r);
+            assertNotNull("Test spreadsheet cell empty on row ("
+                + (rowIndex+1) + "). Expected function name or '"
+                + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName);
+
+            if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
+                // found end of functions list
+                break;
+            }
+
+            String targetTestName = getTargetTestName(r);
+            if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
+
+                // expected results are on the row below
+                Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE);
+                assertNotNull("Missing expected values cell for function '"
+                    + targetFunctionName + ", test" + targetTestName + " (row " +
+                    rowIndex + 1 + ")", expectedValueCell);
+
+                data.add(new Object[]{targetTestName, targetFunctionName, rowIndex});
+            }
+        }
+    }
+
+    /**
+    *
+    * @return a constant from the local Result class denoting whether there were any evaluation
+    * cases, and whether they all succeeded.
+    */
+    @Test
+    public void processFunctionRow() {
+        Row r = sheet.getRow(formulasRowIdx);
+
+        Cell expValue = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE);
+        assertNotNull("Missing expected values cell for function '"
+            + targetFunctionName + ", test" + targetTestName + " (row " +
+            formulasRowIdx + 1 + ")", expValue);
+
+        Cell c = r.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE);
+        assumeNotNull(c);
+        assumeTrue(c.getCellType() == Cell.CELL_TYPE_FORMULA);
+
+        CellValue actValue = evaluator.evaluate(c);
+
+        String msg = String.format(Locale.ROOT, "Function '%s': Test: '%s': Formula: %s @ %d:%d",
+            targetFunctionName, targetTestName, c.getCellFormula(), formulasRowIdx, SS.COLUMN_INDEX_ACTUAL_VALUE);
+
+        assertNotNull(msg + " - actual value was null", actValue);
+
+        switch (expValue.getCellType()) {
+            case Cell.CELL_TYPE_BLANK:
+                assertEquals(msg, Cell.CELL_TYPE_BLANK, actValue.getCellType());
+                break;
+            case Cell.CELL_TYPE_BOOLEAN:
+                assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actValue.getCellType());
+                assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
+                break;
+            case Cell.CELL_TYPE_ERROR:
+                assertEquals(msg, Cell.CELL_TYPE_ERROR, actValue.getCellType());
+//              if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
+//                  assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue());
+//              }
+                break;
+            case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+                fail("Cannot expect formula as result of formula evaluation: " + msg);
+            case Cell.CELL_TYPE_NUMERIC:
+                assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actValue.getCellType());
+                TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
+//              double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
+//              double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
+//              assertTrue(msg, delta <= pctExpected);
+                break;
+            case Cell.CELL_TYPE_STRING:
+                assertEquals(msg, Cell.CELL_TYPE_STRING, actValue.getCellType());
+                assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
+                break;
+        }
+    }
 
-	protected void setUp() throws Exception {
-		if (workbook == null) {
-			InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
-			OPCPackage pkg = OPCPackage.open(is);
-			workbook = new XSSFWorkbook( pkg );
-			sheet = workbook.getSheet( SS.TEST_SHEET_NAME );
-		}
-		_functionFailureCount = 0;
-		_functionSuccessCount = 0;
-		_evaluationFailureCount = 0;
-		_evaluationSuccessCount = 0;
-	}
-
-	public void testFunctionsFromTestSpreadsheet() {
-
-		processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, null);
-
-		// confirm results
-		String successMsg = "There were "
-				+ _evaluationSuccessCount + " successful evaluation(s) and "
-				+ _functionSuccessCount + " function(s) without error";
-		if(_functionFailureCount > 0) {
-			String msg = _functionFailureCount + " function(s) failed in "
-			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
-			throw new AssertionFailedError(msg);
-		}
-        logger.log(POILogger.INFO, getClass().getName() + ": " + successMsg);
-	}
-
-	/**
-	 * @param startRowIndex row index in the spreadsheet where the first function/operator is found
-	 * @param testFocusFunctionName name of a single function/operator to test alone.
-	 * Typically pass <code>null</code> to test all functions
-	 */
-	private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
-		FormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook);
-
-		int rowIndex = startRowIndex;
-		while (true) {
-			Row r = sheet.getRow(rowIndex);
-			
-			// only evaluate non empty row
-			if( r != null )
-			{
-				String targetFunctionName = getTargetFunctionName(r);
-				String targetTestName = getTargetTestName(r);
-				if(targetFunctionName == null) {
-					throw new AssertionFailedError("Test spreadsheet cell empty on row ("
-							+ (rowIndex+1) + "). Expected function name or '"
-							+ SS.FUNCTION_NAMES_END_SENTINEL + "'");
-				}
-				if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
-					// found end of functions list
-					break;
-				}
-				if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
-
-					// expected results are on the row below
-					Cell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_VALUE);
-					if(expectedValueCell == null) {
-						int missingRowNum = rowIndex + 1;
-						throw new AssertionFailedError("Missing expected values cell for function '"
-								+ targetFunctionName + ", test" + targetTestName + " (row " + 
-								missingRowNum + ")");
-					}
-					
-					switch(processFunctionRow(evaluator, targetFunctionName, targetTestName, r, expectedValueCell)) {
-						case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break;
-						case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break;
-						default:
-							throw new RuntimeException("unexpected result");
-						case Result.NO_EVALUATIONS_FOUND: // do nothing
-							break;
-					}
-				}
-			}
-			rowIndex ++;
-		}
-	}
-
-	/**
-	 *
-	 * @return a constant from the local Result class denoting whether there were any evaluation
-	 * cases, and whether they all succeeded.
-	 */
-	private int processFunctionRow(FormulaEvaluator evaluator, String targetFunctionName, 
-			String targetTestName, Row formulasRow, Cell expectedValueCell) {
-
-		int result = Result.NO_EVALUATIONS_FOUND; // so far
-
-		Cell c = formulasRow.getCell(SS.COLUMN_INDEX_ACTUAL_VALUE);
-		if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
-			return result;
-		}
-
-		CellValue actualValue = evaluator.evaluate(c);
-
-		try {
-			confirmExpectedResult("Function '" + targetFunctionName + "': Test: '" + targetTestName + "' Formula: " + c.getCellFormula() 
-			+ " @ " + formulasRow.getRowNum() + ":" + SS.COLUMN_INDEX_ACTUAL_VALUE,
-					expectedValueCell, actualValue);
-			_evaluationSuccessCount ++;
-			if(result != Result.SOME_EVALUATIONS_FAILED) {
-				result = Result.ALL_EVALUATIONS_SUCCEEDED;
-			}
-		} catch (AssertionFailedError e) {
-			_evaluationFailureCount ++;
-			printShortStackTrace(System.err, e);
-			result = Result.SOME_EVALUATIONS_FAILED;
-		}
-	
-		return result;
-	}
-
-	/**
-	 * Useful to keep output concise when expecting many failures to be reported by this test case
-	 */
-	private static void printShortStackTrace(PrintStream ps, AssertionFailedError e) {
-		StackTraceElement[] stes = e.getStackTrace();
-
-		int startIx = 0;
-		// skip any top frames inside junit.framework.Assert
-		while(startIx<stes.length) {
-			if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
-				break;
-			}
-			startIx++;
-		}
-		// skip bottom frames (part of junit framework)
-		int endIx = startIx+1;
-		while(endIx < stes.length) {
-			if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
-				break;
-			}
-			endIx++;
-		}
-		if(startIx >= endIx) {
-			// something went wrong. just print the whole stack trace
-			e.printStackTrace(ps);
-		}
-		endIx -= 4; // skip 4 frames of reflection invocation
-		ps.println(e.toString());
-		for(int i=startIx; i<endIx; i++) {
-			ps.println("\tat " + stes[i].toString());
-		}
-	}
-
-	/**
+    /**
 	 * @return <code>null</code> if cell is missing, empty or blank
 	 */
 	private static String getTargetFunctionName(Row r) {
 		if(r == null) {
-			System.err.println("Warning - given null row, can't figure out function name");
+		    logger.log(POILogger.WARN, "Warning - given null row, can't figure out function name");
 			return null;
 		}
 		Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME);
 		if(cell == null) {
-			System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name");
+            logger.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name");
 			return null;
 		}
 		if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {
@@ -304,20 +234,21 @@ public final class TestMultiSheetFormula
 			return cell.getRichStringCellValue().getString();
 		}
 
-		throw new AssertionFailedError("Bad cell type for 'function name' column: ("
-				+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+		fail("Bad cell type for 'function name' column: ("
+			+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+		return "";
 	}
 	/**
 	 * @return <code>null</code> if cell is missing, empty or blank
 	 */
 	private static String getTargetTestName(Row r) {
 		if(r == null) {
-			System.err.println("Warning - given null row, can't figure out test name");
+            logger.log(POILogger.WARN, "Warning - given null row, can't figure out test name");
 			return null;
 		}
 		Cell cell = r.getCell(SS.COLUMN_INDEX_TEST_NAME);
 		if(cell == null) {
-			System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name");
+		    logger.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name");
 			return null;
 		}
 		if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {
@@ -327,8 +258,9 @@ public final class TestMultiSheetFormula
 			return cell.getRichStringCellValue().getString();
 		}
 
-		throw new AssertionFailedError("Bad cell type for 'test name' column: ("
-				+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+		fail("Bad cell type for 'test name' column: ("
+			+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+		return "";
 	}
-	
+
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java Sun Sep 13 12:36:56 2015
@@ -17,7 +17,8 @@
 
 package org.apache.poi.xwpf.usermodel;
 
-import java.io.FileOutputStream;
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
@@ -34,12 +35,12 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.apache.xmlbeans.XmlCursor;
+import org.junit.Test;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 
-import junit.framework.TestCase;
-
-public final class TestXWPFDocument extends TestCase {
+public final class TestXWPFDocument {
 
+    @Test
     public void testContainsMainContentType() throws Exception {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         OPCPackage pack = doc.getPackage();
@@ -49,31 +50,36 @@ public final class TestXWPFDocument exte
             if (part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
                 found = true;
             }
-            if (false) {
-                // successful tests should be silent
-                System.out.println(part);
-            }
+//            if (false) {
+//                // successful tests should be silent
+//                System.out.println(part);
+//            }
         }
         assertTrue(found);
+        
+        pack.close();
+        doc.close();
     }
 
+    @Test
     public void testOpen() throws Exception {
-        XWPFDocument xml;
-
         // Simple file
-        xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        XWPFDocument xml1 = XWPFTestDataSamples.openSampleDocument("sample.docx");
         // Check it has key parts
-        assertNotNull(xml.getDocument());
-        assertNotNull(xml.getDocument().getBody());
-        assertNotNull(xml.getStyle());
+        assertNotNull(xml1.getDocument());
+        assertNotNull(xml1.getDocument().getBody());
+        assertNotNull(xml1.getStyle());
+        xml1.close();
 
         // Complex file
-        xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
-        assertNotNull(xml.getDocument());
-        assertNotNull(xml.getDocument().getBody());
-        assertNotNull(xml.getStyle());
+        XWPFDocument xml2 = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
+        assertNotNull(xml2.getDocument());
+        assertNotNull(xml2.getDocument().getBody());
+        assertNotNull(xml2.getStyle());
+        xml2.close();
     }
 
+    @Test
     public void testMetadataBasics() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
         assertNotNull(xml.getProperties().getCoreProperties());
@@ -85,8 +91,10 @@ public final class TestXWPFDocument exte
 
         assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
         assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+        xml.close();
     }
 
+    @Test
     public void testMetadataComplex() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
         assertNotNull(xml.getProperties().getCoreProperties());
@@ -98,15 +106,19 @@ public final class TestXWPFDocument exte
 
         assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
         assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+        xml.close();
     }
 
-    public void testWorkbookProperties() {
+    @Test
+    public void testWorkbookProperties() throws Exception {
         XWPFDocument doc = new XWPFDocument();
         POIXMLProperties props = doc.getProperties();
         assertNotNull(props);
         assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
+        doc.close();
     }
 
+    @Test
     public void testAddParagraph() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         assertEquals(3, doc.getParagraphs().size());
@@ -125,8 +137,10 @@ public final class TestXWPFDocument exte
         XWPFParagraph cP = doc.insertNewParagraph(cursor);
         assertSame(cP, doc.getParagraphs().get(0));
         assertEquals(5, doc.getParagraphs().size());
+        doc.close();
     }
 
+    @Test
     public void testAddPicture() throws IOException, InvalidFormatException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
@@ -137,8 +151,10 @@ public final class TestXWPFDocument exte
         for (int i = 0; i < jpeg.length; i++) {
             assertEquals(newJpeg[i], jpeg[i]);
         }
+        doc.close();
     }
 
+    @Test
     public void testAllPictureFormats() throws IOException, InvalidFormatException {
         XWPFDocument doc = new XWPFDocument();
 
@@ -156,11 +172,13 @@ public final class TestXWPFDocument exte
 
         assertEquals(11, doc.getAllPictures().size());
 
-        doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
-        assertEquals(11, doc.getAllPictures().size());
-
+        XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        assertEquals(11, doc2.getAllPictures().size());
+        doc2.close();
+        doc.close();
     }
 
+    @Test
     public void testRemoveBodyElement() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         assertEquals(3, doc.getParagraphs().size());
@@ -220,8 +238,10 @@ public final class TestXWPFDocument exte
 
         assertEquals(p3, doc.getBodyElements().get(0));
         assertEquals(p3, doc.getParagraphs().get(0));
+        doc.close();
     }
 
+    @Test
     public void testRegisterPackagePictureData() throws IOException, InvalidFormatException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
 
@@ -250,8 +270,11 @@ public final class TestXWPFDocument exte
         assertTrue(doc.getAllPackagePictures().contains(newPicData));
 
         doc.getPackage().revert();
+        opcPckg.close();
+        doc.close();
     }
 
+    @Test
     public void testFindPackagePictureData() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
         byte[] nature1 = XWPFTestDataSamples.getImage("nature1.gif");
@@ -260,8 +283,10 @@ public final class TestXWPFDocument exte
         assertTrue(doc.getAllPictures().contains(part));
         assertTrue(doc.getAllPackagePictures().contains(part));
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testGetAllPictures() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
         List<XWPFPictureData> allPictures = doc.getAllPictures();
@@ -281,8 +306,10 @@ public final class TestXWPFDocument exte
         }
 
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testGetAllPackagePictures() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
         List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
@@ -298,8 +325,10 @@ public final class TestXWPFDocument exte
         }
 
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testPictureHandlingSimpleFile() throws IOException, InvalidFormatException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
         assertEquals(1, doc.getAllPackagePictures().size());
@@ -311,16 +340,20 @@ public final class TestXWPFDocument exte
         String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
         assertEquals(id1, id2);
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testPictureHandlingHeaderDocumentImages() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_2.docx");
         assertEquals(1, doc.getAllPictures().size());
         assertEquals(1, doc.getAllPackagePictures().size());
         assertEquals(1, doc.getHeaderArray(0).getAllPictures().size());
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
         XWPFHeader xwpfHeader = doc.getHeaderArray(0);
@@ -336,8 +369,10 @@ public final class TestXWPFDocument exte
         assertSame(part1, part2);
 
         doc.getPackage().revert();
+        doc.close();
     }
 
+    @Test
     public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
         POIXMLProperties properties = doc.getProperties();
@@ -352,8 +387,10 @@ public final class TestXWPFDocument exte
         POIXMLProperties.ExtendedProperties extendedProperties = properties.getExtendedProperties();
         assertNotNull(extendedProperties);
         assertEquals(0, extendedProperties.getUnderlyingProperties().getCharacters());
+        doc.close();
     }
 
+    @Test
     public void testSettings() throws IOException {
         XWPFSettings settings = new XWPFSettings();
         assertEquals(100, settings.getZoomPercent());

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java Sun Sep 13 12:36:56 2015
@@ -85,15 +85,15 @@ public final class TestRangeInsertion ex
 
 		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
-		if (false) { // TODO - delete or resurrect this code
-			Range range = daDoc.getRange();
-			Section section = range.getSection(0);
-			Paragraph para = section.getParagraph(2);
-			String text = para.getCharacterRun(0).text() + para.getCharacterRun(1).text() +
-			para.getCharacterRun(2).text();
-
-			System.out.println(text);
-		}
+//		if (false) { // TODO - delete or resurrect this code
+//			Range range = daDoc.getRange();
+//			Section section = range.getSection(0);
+//			Paragraph para = section.getParagraph(2);
+//			String text = para.getCharacterRun(0).text() + para.getCharacterRun(1).text() +
+//			para.getCharacterRun(2).text();
+//
+//			System.out.println(text);
+//		}
 
 		Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
 		range.insertBefore(textToInsert);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRVA.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRVA.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRVA.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestRVA.java Sun Sep 13 12:36:56 2015
@@ -17,72 +17,83 @@
 
 package org.apache.poi.hssf.model;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.formula.ptg.AttrPtg;
-import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.hssf.usermodel.FormulaExtractor;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.ss.formula.ptg.AttrPtg;
+import org.apache.poi.ss.formula.ptg.Ptg;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Tests 'operand class' transformation performed by
  * <tt>OperandClassTransformer</tt> by comparing its results with those
  * directly produced by Excel (in a sample spreadsheet).
- * 
- * @author Josh Micich
  */
-public final class TestRVA extends TestCase {
+@RunWith(Parameterized.class)
+public final class TestRVA {
 
 	private static final String NEW_LINE = System.getProperty("line.separator");
-
-	public void testFormulas() {
-		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRVA.xls");
-		HSSFSheet sheet = wb.getSheetAt(0);
-
-		int countFailures = 0;
-		int countErrors = 0;
-
-		int rowIx = 0;
-		while (rowIx < 65535) {
-			HSSFRow row = sheet.getRow(rowIx);
-			if (row == null) {
-				break;
-			}
-			HSSFCell cell = row.getCell(0);
-			if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
-				break;
-			}
-			String formula = cell.getCellFormula();
-			try {
-				confirmCell(cell, formula, wb);
-			} catch (AssertionFailedError e) {
-				System.out.flush();
-				System.err.println("Problem with row[" + rowIx + "] formula '" + formula + "'");
-				System.err.println(e.getMessage());
-				System.err.flush();
-				countFailures++;
-			} catch (RuntimeException e) {
-				System.err.println("Problem with row[" + rowIx + "] formula '" + formula + "'");
-				countErrors++;
-				e.printStackTrace();
-			}
-			rowIx++;
-		}
-		if (countErrors + countFailures > 0) {
-			String msg = "One or more RVA tests failed: countFailures=" + countFailures
-					+ " countFailures=" + countErrors + ". See stderr for details.";
-			throw new AssertionFailedError(msg);
-		}
-	}
-
-	private void confirmCell(HSSFCell formulaCell, String formula, HSSFWorkbook wb) {
+	private static NPOIFSFileSystem poifs;
+    private static HSSFWorkbook workbook;
+    private static HSSFSheet sheet;
+
+	
+    @Parameter(value = 0)
+    public HSSFCell formulaCell;
+    @Parameter(value = 1)
+    public String formula;
+
+    @AfterClass
+    public static void closeResource() throws Exception {
+        workbook.close();
+        poifs.close();
+    }
+
+    @Parameters(name="{1}")
+    public static Collection<Object[]> data() throws Exception {
+        poifs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("testRVA.xls"), true);
+        workbook = new HSSFWorkbook(poifs);
+        sheet = workbook.getSheetAt(0);
+
+        List<Object[]> data = new ArrayList<Object[]>(); 
+        
+        for (int rowIdx = 0; true; rowIdx++) {
+            HSSFRow row = sheet.getRow(rowIdx);
+            if (row == null) {
+                break;
+            }
+            HSSFCell cell = row.getCell(0);
+            if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
+                break;
+            }
+
+            String formula = cell.getCellFormula();
+            data.add(new Object[]{cell,formula});
+        }
+        
+        return data;
+    }
+	
+    @Test
+	public void confirmCell() {
 		Ptg[] excelPtgs = FormulaExtractor.getPtgs(formulaCell);
-		Ptg[] poiPtgs = HSSFFormulaParser.parse(formula, wb);
+		Ptg[] poiPtgs = HSSFFormulaParser.parse(formula, workbook);
 		int nExcelTokens = excelPtgs.length;
 		int nPoiTokens = poiPtgs.length;
 		if (nExcelTokens != nPoiTokens) {
@@ -94,8 +105,7 @@ public final class TestRVA extends TestC
 				System.arraycopy(poiPtgs, 0, temp, 1, nPoiTokens);
 				poiPtgs = temp;
 			} else {
-				throw new RuntimeException("Expected " + nExcelTokens + " tokens but got "
-						+ nPoiTokens);
+				fail("Expected " + nExcelTokens + " tokens but got " + nPoiTokens);
 			}
 		}
 		boolean hasMismatch = false;
@@ -123,13 +133,11 @@ public final class TestRVA extends TestC
 			}
 			sb.append(NEW_LINE);
 		}
-		if (false) { // set 'true' to see trace of RVA values
-			System.out.println(formulaCell.getRowIndex() + " " + formula);
-			System.out.println(sb.toString());
-		}
-		if (hasMismatch) {
-			throw new AssertionFailedError(sb.toString());
-		}
+//		if (false) { // set 'true' to see trace of RVA values
+//			System.out.println(formulaCell.getRowIndex() + " " + formula);
+//			System.out.println(sb.toString());
+//		}
+		assertFalse(hasMismatch);
 	}
 
 	private String getShortClassName(Object o) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java Sun Sep 13 12:36:56 2015
@@ -17,14 +17,17 @@
 
 package org.apache.poi.hssf.model;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
 import org.apache.poi.ddf.EscherDggRecord;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.BOFRecord;
@@ -62,13 +65,14 @@ import org.apache.poi.hssf.usermodel.Rec
 import org.apache.poi.ss.formula.FormulaShifter;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.HexRead;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
 
 /**
  * Unit test for the {@link InternalSheet} class.
- *
- * @author Glen Stampoultzis (glens at apache.org)
  */
-public final class TestSheet extends TestCase {
+public final class TestSheet {
 	private static InternalSheet createSheet(List<Record> inRecs) {
 		return InternalSheet.createSheet(new RecordStream(inRecs, 0));
 	}
@@ -79,6 +83,7 @@ public final class TestSheet extends Tes
 		return rc.getRecords();
 	}
 
+	@Test
 	public void testCreateSheet() {
 		// Check we're adding row and cell aggregates
 		List<Record> records = new ArrayList<Record>();
@@ -124,6 +129,7 @@ public final class TestSheet extends Tes
 		}
 	}
 
+    @Test
 	public void testAddMergedRegion() {
 		InternalSheet sheet = InternalSheet.createSheet();
 		int regionsToAdd = 4096;
@@ -164,6 +170,7 @@ public final class TestSheet extends Tes
 		}
 	}
 
+    @Test
 	public void testRemoveMergedRegion() {
 		InternalSheet sheet = InternalSheet.createSheet();
 		int regionsToAdd = 4096;
@@ -194,6 +201,7 @@ public final class TestSheet extends Tes
 	 * fills up the records.
 	 *
 	 */
+    @Test
 	public void testMovingMergedRegion() {
 		List<Record> records = new ArrayList<Record>();
 
@@ -218,10 +226,12 @@ public final class TestSheet extends Tes
 		assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
 	}
 
+    @Test
 	public void testGetMergedRegionAt() {
 		//TODO
 	}
 
+    @Test
 	public void testGetNumMergedRegions() {
 		//TODO
 	}
@@ -230,6 +240,7 @@ public final class TestSheet extends Tes
 	 * Makes sure all rows registered for this sheet are aggregated, they were being skipped
 	 *
 	 */
+    @Test
 	public void testRowAggregation() {
 		List<Record> records = new ArrayList<Record>();
 
@@ -253,6 +264,7 @@ public final class TestSheet extends Tes
 	 * Make sure page break functionality works (in memory)
 	 *
 	 */
+    @Test
 	public void testRowPageBreaks() {
 		short colFrom = 0;
 		short colTo = 255;
@@ -309,6 +321,7 @@ public final class TestSheet extends Tes
 	 * Make sure column pag breaks works properly (in-memory)
 	 *
 	 */
+    @Test
 	public void testColPageBreaks() {
 		short rowFrom = 0;
 		short rowTo = (short)65535;
@@ -370,6 +383,7 @@ public final class TestSheet extends Tes
 	 * test newly added method Sheet.getXFIndexForColAt(..)
 	 * works as designed.
 	 */
+    @Test
 	public void testXFIndexForColumn() {
 		final short TEST_IDX = 10;
 		final short DEFAULT_IDX = 0xF; // 15
@@ -461,6 +475,7 @@ public final class TestSheet extends Tes
 	 * Prior to bug 45066, POI would get the estimated sheet size wrong
 	 * when an <tt>UncalcedRecord</tt> was present.<p/>
 	 */
+    @Test
 	public void testUncalcSize_bug45066() {
 
 		List<Record> records = new ArrayList<Record>();
@@ -486,6 +501,7 @@ public final class TestSheet extends Tes
 	 *
 	 * The code here represents a normal POI use case where a spreadsheet is created from scratch.
 	 */
+    @Test
 	public void testRowValueAggregatesOrder_bug45145() {
 
 		InternalSheet sheet = InternalSheet.createSheet();
@@ -506,12 +522,12 @@ public final class TestSheet extends Tes
 			throw new AssertionFailedError("Identified  bug 45145");
 		}
 
-		if (false) {
-			// make sure that RRA and VRA are in the right place
-			// (Aug 2008) since the VRA is now part of the RRA, there is much less chance that
-			// they could get out of order. Still, one could write serialize the sheet here,
-			// and read back with EventRecordFactory to make sure...
-		}
+//		if (false) {
+//			// make sure that RRA and VRA are in the right place
+//			// (Aug 2008) since the VRA is now part of the RRA, there is much less chance that
+//			// they could get out of order. Still, one could write serialize the sheet here,
+//			// and read back with EventRecordFactory to make sure...
+//		}
 		assertEquals(242, dbCellRecordPos);
 	}
 
@@ -551,6 +567,7 @@ public final class TestSheet extends Tes
 	 * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
 	 * which in turn got the dimensions record out of alignment
 	 */
+    @Test
 	public void testGutsRecord_bug45640() {
 
 		InternalSheet sheet = InternalSheet.createSheet();
@@ -571,21 +588,25 @@ public final class TestSheet extends Tes
 		assertEquals(1, count);
 	}
 
-	public void testMisplacedMergedCellsRecords_bug45699() {
+    @Test
+	public void testMisplacedMergedCellsRecords_bug45699() throws Exception {
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
 
 		HSSFSheet sheet = wb.getSheetAt(0);
 		HSSFRow row = sheet.getRow(3);
 		HSSFCell cell = row.getCell(4);
 		if (cell == null) {
-			throw new AssertionFailedError("Identified bug 45699");
+			fail("Identified bug 45699");
 		}
 		assertEquals("Informations", cell.getRichStringCellValue().getString());
+		
+		wb.close();
 	}
 	/**
 	 * In 3.1, setting margins between creating first row and first cell caused an exception.
 	 */
-	public void testSetMargins_bug45717() {
+    @Test
+	public void testSetMargins_bug45717() throws Exception {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Vorschauliste");
 		HSSFRow row = sheet.createRow(0);
@@ -595,9 +616,11 @@ public final class TestSheet extends Tes
 			row.createCell(0);
 		} catch (IllegalStateException e) {
 			if (e.getMessage().equals("Cannot create value records before row records exist")) {
-				throw new AssertionFailedError("Identified bug 45717");
+				fail("Identified bug 45717");
 			}
 			throw e;
+		} finally {
+		    workbook.close();
 		}
 	}
 
@@ -605,6 +628,7 @@ public final class TestSheet extends Tes
 	 * Some apps seem to write files with missing DIMENSION records.
 	 * Excel(2007) tolerates this, so POI should too.
 	 */
+    @Test
 	public void testMissingDims() {
 
 		int rowIx = 5;
@@ -648,6 +672,7 @@ public final class TestSheet extends Tes
 	 * aggregates. However, since this unnecessary creation helped expose bug 46547b,
 	 * and since there is a slight performance hit the fix was made to avoid it.
 	 */
+    @Test
 	public void testShiftFormulasAddCondFormat_bug46547() {
 		// Create a sheet with data validity (similar to bugzilla attachment id=23131).
 		InternalSheet sheet = InternalSheet.createSheet();
@@ -666,6 +691,7 @@ public final class TestSheet extends Tes
 	 * Bug 46547 happened when attempting to add conditional formatting to a sheet
 	 * which already had data validity constraints.
 	 */
+    @Test
 	public void testAddCondFormatAfterDataValidation_bug46547() {
 		// Create a sheet with data validity (similar to bugzilla attachment id=23131).
 		InternalSheet sheet = InternalSheet.createSheet();
@@ -682,6 +708,7 @@ public final class TestSheet extends Tes
 		assertNotNull(cft);
 	}
 
+    @Test
 	public void testCloneMulBlank_bug46776() {
 		Record[]  recs = {
 				InternalSheet.createBOF(),
@@ -711,6 +738,7 @@ public final class TestSheet extends Tes
 		assertEquals(recs.length+2, clonedRecs.length); // +2 for INDEX and DBCELL
 	}
 
+    @Test
     public void testCreateAggregate() {
         String msoDrawingRecord1 =
                 "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
@@ -798,6 +826,7 @@ public final class TestSheet extends Tes
         assertEquals(EOFRecord.sid, ((Record)sheetRecords.get(3)).getSid());
     }
 
+    @Test
     public void testSheetDimensions() throws IOException{
         InternalSheet sheet = InternalSheet.createSheet();
         DimensionsRecord dimensions = (DimensionsRecord)sheet.findFirstRecordBySid(DimensionsRecord.sid);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java Sun Sep 13 12:36:56 2015
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.aggregates;
 
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -25,9 +25,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.zip.CRC32;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.model.RowBlocksReader;
@@ -39,15 +36,17 @@ import org.apache.poi.hssf.record.Record
 import org.apache.poi.hssf.record.SharedFormulaRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
-import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.util.HexRead;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
 
 /**
  * Tests for {@link ValueRecordsAggregate}
  */
-public final class TestValueRecordsAggregate extends TestCase {
+public final class TestValueRecordsAggregate {
 	private static final String ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE = "AbnormalSharedFormulaFlag.xls";
 	private final ValueRecordsAggregate valueRecord = new ValueRecordsAggregate();
 
@@ -56,6 +55,7 @@ public final class TestValueRecordsAggre
 	 * as part of the value records
 	 */
     @SuppressWarnings("deprecation") // uses deprecated {@link ValueRecordsAggregate#getValueRecords()}
+    @Test
 	public void testSharedFormula() {
 		List<Record> records = new ArrayList<Record>();
 		records.add(new FormulaRecord());
@@ -97,6 +97,7 @@ public final class TestValueRecordsAggre
 	}
 
     @SuppressWarnings("deprecation") // uses deprecated {@link ValueRecordsAggregate#getValueRecords()}
+    @Test
 	public void testInsertCell() {
 		CellValueRecordInterface[] cvrs = valueRecord.getValueRecords();
 		assertEquals(0, cvrs.length);
@@ -108,7 +109,8 @@ public final class TestValueRecordsAggre
 	}
 
     @SuppressWarnings("deprecation") // uses deprecated {@link ValueRecordsAggregate#getValueRecords()}
-	public void testRemoveCell() {
+    @Test
+    public void testRemoveCell() {
 		BlankRecord blankRecord1 = newBlankRecord();
 		valueRecord.insertCell( blankRecord1 );
 		BlankRecord blankRecord2 = newBlankRecord();
@@ -120,6 +122,7 @@ public final class TestValueRecordsAggre
 		valueRecord.removeCell( blankRecord2 );
 	}
 
+    @Test
 	public void testGetPhysicalNumberOfCells() {
 		assertEquals(0, valueRecord.getPhysicalNumberOfCells());
 		BlankRecord blankRecord1 = newBlankRecord();
@@ -129,6 +132,7 @@ public final class TestValueRecordsAggre
 		assertEquals(0, valueRecord.getPhysicalNumberOfCells());
 	}
 
+    @Test
 	public void testGetFirstCellNum() {
 		assertEquals( -1, valueRecord.getFirstCellNum() );
 		valueRecord.insertCell( newBlankRecord( 2, 2 ) );
@@ -141,6 +145,7 @@ public final class TestValueRecordsAggre
 		assertEquals( 2, valueRecord.getFirstCellNum() );
 	}
 
+    @Test
 	public void testGetLastCellNum() {
 		assertEquals( -1, valueRecord.getLastCellNum() );
 		valueRecord.insertCell( newBlankRecord( 2, 2 ) );
@@ -172,6 +177,7 @@ public final class TestValueRecordsAggre
 		}
 	}
 
+    @Test
 	public void testSerialize() {
 		byte[] expectedArray = HexRead.readFromString(""
 				+ "06 00 16 00 " // Formula
@@ -230,7 +236,8 @@ public final class TestValueRecordsAggre
 	 * There are other variations on this theme to create the same effect.
 	 *
 	 */
-	public void testSpuriousSharedFormulaFlag() {
+    @Test
+	public void testSpuriousSharedFormulaFlag() throws Exception {
 
 		long actualCRC = getFileCRC(HSSFTestDataSamples.openSampleFileStream(ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE));
 		long expectedCRC = 2277445406L;
@@ -245,18 +252,15 @@ public final class TestValueRecordsAggre
 		String cellFormula;
 		cellFormula = getFormulaFromFirstCell(s, 0); // row "1"
 		// the problem is not observable in the first row of the shared formula
-		if(!cellFormula.equals("\"first formula\"")) {
-			throw new RuntimeException("Something else wrong with this test case");
-		}
+		assertEquals("Something else wrong with this test case", "\"first formula\"", cellFormula);
 
 		// but the problem is observable in rows 2,3,4
 		cellFormula = getFormulaFromFirstCell(s, 1); // row "2"
-		if(cellFormula.equals("\"second formula\"")) {
-			throw new AssertionFailedError("found bug 44449 (Wrong SharedFormulaRecord was used).");
-		}
-		if(!cellFormula.equals("\"first formula\"")) {
-			throw new RuntimeException("Something else wrong with this test case");
-		}
+		assertNotEquals("found bug 44449 (Wrong SharedFormulaRecord was used).", "\"second formula\"", cellFormula);
+
+		assertEquals("Something else wrong with this test case", "\"first formula\"", cellFormula);
+		
+		wb.close();
 	}
 	private static String getFormulaFromFirstCell(HSSFSheet s, int rowIx) {
 		return s.getRow(rowIx).getCell(0).getCellFormula();
@@ -302,6 +306,8 @@ public final class TestValueRecordsAggre
 
 		return crc.getValue();
 	}
+	
+    @Test
 	public void testRemoveNewRow_bug46312() {
 		// To make bug occur, rowIndex needs to be >= ValueRecordsAggregate.records.length
 		int rowIndex = 30;
@@ -316,26 +322,27 @@ public final class TestValueRecordsAggre
 			throw e;
 		}
 
-		if (false) { // same bug as demonstrated through usermodel API
-
-			HSSFWorkbook wb = new HSSFWorkbook();
-			HSSFSheet sheet = wb.createSheet();
-			HSSFRow row = sheet.createRow(rowIndex);
-			if (false) { // must not add any cells to the new row if we want to see the bug
-				row.createCell(0); // this causes ValueRecordsAggregate.records to auto-extend
-			}
-			try {
-				sheet.createRow(rowIndex);
-			} catch (IllegalArgumentException e) {
-				throw new AssertionFailedError("Identified bug 46312");
-			}
-		}
+//		if (false) { // same bug as demonstrated through usermodel API
+//
+//			HSSFWorkbook wb = new HSSFWorkbook();
+//			HSSFSheet sheet = wb.createSheet();
+//			HSSFRow row = sheet.createRow(rowIndex);
+//			if (false) { // must not add any cells to the new row if we want to see the bug
+//				row.createCell(0); // this causes ValueRecordsAggregate.records to auto-extend
+//			}
+//			try {
+//				sheet.createRow(rowIndex);
+//			} catch (IllegalArgumentException e) {
+//				throw new AssertionFailedError("Identified bug 46312");
+//			}
+//		}
 	}
 
 	/**
 	 * Tests various manipulations of blank cells, to make sure that {@link MulBlankRecord}s
 	 * are use appropriately
 	 */
+    @Test
 	public void testMultipleBlanks() {
 		BlankRecord brA2 = newBlankRecord(0, 1);
 		BlankRecord brB2 = newBlankRecord(1, 1);

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/function/TestReadMissingBuiltInFuncs.java Sun Sep 13 12:36:56 2015
@@ -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);
-	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java?rev=1702773&r1=1702772&r2=1702773&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestIndirect.java Sun Sep 13 12:36:56 2015
@@ -17,23 +17,27 @@
 
 package org.apache.poi.ss.formula.functions;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFName;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.eval.ErrorEval;
-import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellValue;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.junit.Test;
 
 /**
  * Tests for the INDIRECT() function.</p>
- *
- * @author Josh Micich
  */
-public final class TestIndirect extends TestCase {
+public final class TestIndirect {
 	// convenient access to namespace
-	private static final ErrorEval EE = null;
+	// private static final ErrorEval EE = null;
 
 	private static void createDataRow(HSSFSheet sheet, int rowIndex, double... vals) {
 		HSSFRow row = sheet.createRow(rowIndex);
@@ -91,7 +95,8 @@ public final class TestIndirect extends
 		return wb;
 	}
 
-	public void testBasic() {
+	@Test
+	public void testBasic() throws Exception {
 
 		HSSFWorkbook wbA = createWBA();
 		HSSFCell c = wbA.getSheetAt(0).createRow(5).createCell(2);
@@ -138,14 +143,17 @@ public final class TestIndirect extends
 		confirm(feA, c, "SUM(INDIRECT(\"'John's sales'!A1:C1\"))", ErrorEval.REF_INVALID); // bad quote escaping
 		confirm(feA, c, "INDIRECT(\"[Book1]Sheet1!A1\")", ErrorEval.REF_INVALID); // unknown external workbook
 		confirm(feA, c, "INDIRECT(\"Sheet3!A1\")", ErrorEval.REF_INVALID); // unknown sheet
-		if (false) { // TODO - support evaluation of defined names
-			confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", ErrorEval.REF_INVALID); // bad column
-			confirm(feA, c, "INDIRECT(\"Sheet1!A65537\")", ErrorEval.REF_INVALID); // bad row
-		}
+//		if (false) { // TODO - support evaluation of defined names
+//			confirm(feA, c, "INDIRECT(\"Sheet1!IW1\")", ErrorEval.REF_INVALID); // bad column
+//			confirm(feA, c, "INDIRECT(\"Sheet1!A65537\")", ErrorEval.REF_INVALID); // bad row
+//		}
 		confirm(feA, c, "INDIRECT(\"Sheet1!A 1\")", ErrorEval.REF_INVALID); // space in cell ref
+		
+		wbA.close();
 	}
 
-	public void testMultipleWorkbooks() {
+	@Test
+	public void testMultipleWorkbooks() throws Exception {
 		HSSFWorkbook wbA = createWBA();
 		HSSFCell cellA = wbA.getSheetAt(0).createRow(10).createCell(0);
 		HSSFFormulaEvaluator feA = new HSSFFormulaEvaluator(wbA);
@@ -164,6 +172,9 @@ public final class TestIndirect extends
 		// 2 level recursion
 		confirm(feB, cellB, "INDIRECT(\"[MyBook]Sheet2!A1\")", 50); // set up (and check) first level
 		confirm(feA, cellA, "INDIRECT(\"'[Figures for January]Sheet1'!A11\")", 50); // points to cellB
+		
+		wbB.close();
+		wbA.close();
 	}
 
 	private static void confirm(FormulaEvaluator fe, Cell cell, String formula,
@@ -172,21 +183,22 @@ public final class TestIndirect extends
 		cell.setCellFormula(formula);
 		CellValue cv = fe.evaluate(cell);
 		if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
-			throw new AssertionFailedError("expected numeric cell type but got " + cv.formatAsString());
+			fail("expected numeric cell type but got " + cv.formatAsString());
 		}
 		assertEquals(expectedResult, cv.getNumberValue(), 0.0);
 	}
+	
 	private static void confirm(FormulaEvaluator fe, Cell cell, String formula,
 			ErrorEval expectedResult) {
 		fe.clearAllCachedResultValues();
 		cell.setCellFormula(formula);
 		CellValue cv = fe.evaluate(cell);
 		if (cv.getCellType() != Cell.CELL_TYPE_ERROR) {
-			throw new AssertionFailedError("expected error cell type but got " + cv.formatAsString());
+			fail("expected error cell type but got " + cv.formatAsString());
 		}
 		int expCode = expectedResult.getErrorCode();
 		if (cv.getErrorValue() != expCode) {
-			throw new AssertionFailedError("Expected error '" + ErrorEval.getText(expCode)
+			fail("Expected error '" + ErrorEval.getText(expCode)
 					+ "' but got '" + cv.formatAsString() + "'.");
 		}
 	}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message