]> source.dussan.org Git - poi.git/commitdiff
Eclipse warnings, code formatting, simplify ExcelAntWorkbookUtilFactory, always close...
authorDominik Stadler <centic@apache.org>
Mon, 14 Sep 2015 18:40:23 +0000 (18:40 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 14 Sep 2015 18:40:23 +0000 (18:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1703028 13f79535-47bb-0310-9956-ffa450edef68

src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntEvaluationResult.java
src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java
src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java
src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntEvaluationResult.java
src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
src/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
src/testcases/org/apache/poi/hssf/usermodel/TestText.java

index ae946dd8cdcce910496fba5bdfabc7bfc6d8cad6..4eecd4faeb7823146e1d81be2db48b62d0321c70 100644 (file)
@@ -21,8 +21,8 @@ package org.apache.poi.ss.excelant.util;
  * A simple class that encapsulates information about a cell evaluation
  * from POI.
  * 
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
+ * @author Jon Svede (jon [at] loquatic [dot] com)
+ * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)
  *
  */
 public class ExcelAntEvaluationResult {
@@ -62,12 +62,12 @@ public class ExcelAntEvaluationResult {
        
        
 
-       public ExcelAntEvaluationResult( boolean completedWithError,
+       public ExcelAntEvaluationResult(boolean completedWithError,
                                         boolean passed, 
                                         double retValue, 
                                         String errMessage, 
                                         double delta,
-                                        String cellId ) {
+                                        String cellId) {
 
                evaluationCompletedWithError = completedWithError;
                didPass = passed;
index c4f6969eddac1c620944a8955c57b4df0ff393d6..7d2fbe4fc38f0c72b3cb4bd1225c91aeed2b4ace 100644 (file)
 
 package org.apache.poi.ss.excelant.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.functions.FreeRefFunction;
 import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
 import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
 import org.apache.poi.ss.formula.udf.UDFFinder;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.FormulaError;
+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.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -31,19 +46,12 @@ import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Typedef;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-
 /**
  * A general utility class that abstracts the POI details of loading the
  * workbook, accessing and updating cells.
  *
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
+ * @author Jon Svede (jon [at] loquatic [dot] com)
+ * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)
  *
  */
 public class ExcelAntWorkbookUtil extends Typedef {
@@ -52,7 +60,7 @@ public class ExcelAntWorkbookUtil extends Typedef {
 
     private Workbook workbook;
 
-    private final HashMap<String, FreeRefFunction> xlsMacroList = new HashMap<String, FreeRefFunction>();
+    private final Map<String, FreeRefFunction> xlsMacroList = new HashMap<String, FreeRefFunction>();
 
     /**
      * Constructs an instance using a String that contains the fully qualified
@@ -95,7 +103,7 @@ public class ExcelAntWorkbookUtil extends Typedef {
                     + ". Make sure the path and file permissions are correct.", e);
         }
 
-        return workbook ;
+        return workbook;
     }
 
     /**
@@ -106,11 +114,11 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @throws InstantiationException
      * @throws IllegalAccessException
      */
-    public void addFunction( String name, String clazzName ) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
-        Class<?> clazzInst = Class.forName( clazzName ) ;
-        Object newInst = clazzInst.newInstance() ;
-        if( newInst instanceof FreeRefFunction ) {
-            addFunction( name, (FreeRefFunction)newInst ) ;
+    public void addFunction(String name, String clazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+        Class<?> clazzInst = Class.forName(clazzName);
+        Object newInst = clazzInst.newInstance();
+        if(newInst instanceof FreeRefFunction) {
+            addFunction(name, (FreeRefFunction)newInst);
         }
 
     }
@@ -136,13 +144,10 @@ public class ExcelAntWorkbookUtil extends Typedef {
         String[] names = new String[xlsMacroList.size()];
         FreeRefFunction[] functions = new FreeRefFunction[xlsMacroList.size()];
 
-        Iterator<String> keysIt = xlsMacroList.keySet().iterator();
         int x = 0;
-        while (keysIt.hasNext()) {
-            String name = keysIt.next();
-            FreeRefFunction function = xlsMacroList.get(name);
-            names[x] = name;
-            functions[x] = function;
+        for(Map.Entry<String, FreeRefFunction> entry : xlsMacroList.entrySet()) {
+            names[x] = entry.getKey();
+            functions[x] = entry.getValue();
         }
 
         UDFFinder udff1 = new DefaultUDFFinder(names, functions);
@@ -159,26 +164,26 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param fileName
      * @return
      */
-    protected FormulaEvaluator getEvaluator( String fileName ) {
-        FormulaEvaluator evaluator ;
+    protected FormulaEvaluator getEvaluator(String fileName) {
+        FormulaEvaluator evaluator;
         if (fileName.endsWith(".xlsx")) {
-            if( xlsMacroList.size() > 0 ) {
-                evaluator = XSSFFormulaEvaluator.create( (XSSFWorkbook) workbook,
+            if(xlsMacroList.size() > 0) {
+                evaluator = XSSFFormulaEvaluator.create((XSSFWorkbook) workbook,
                                                          null,
-                                                         getFunctions() ) ;
+                                                         getFunctions());
             }
             evaluator = new XSSFFormulaEvaluator((XSSFWorkbook) workbook);
         } else {
-            if( xlsMacroList.size() > 0 ) {
-                evaluator = HSSFFormulaEvaluator.create( (HSSFWorkbook)workbook,
+            if(xlsMacroList.size() > 0) {
+                evaluator = HSSFFormulaEvaluator.create((HSSFWorkbook)workbook,
                                                          null,
-                                                         getFunctions() ) ;
+                                                         getFunctions());
             }
 
             evaluator = new HSSFFormulaEvaluator((HSSFWorkbook) workbook);
         }
 
-        return evaluator ;
+        return evaluator;
 
     }
 
@@ -206,16 +211,16 @@ public class ExcelAntWorkbookUtil extends Typedef {
      *
      * @return
      */
-    public ArrayList<String> getSheets() {
-       ArrayList<String> sheets = new ArrayList<String>() ;
+    public List<String> getSheets() {
+       ArrayList<String> sheets = new ArrayList<String>();
 
-       int sheetCount = workbook.getNumberOfSheets() ;
+       int sheetCount = workbook.getNumberOfSheets();
 
-       for( int x=0; x<sheetCount; x++ ) {
-               sheets.add( workbook.getSheetName( x ) ) ;
+       for(int x=0; x<sheetCount; x++) {
+               sheets.add(workbook.getSheetName(x));
        }
 
-       return sheets ;
+       return sheets;
     }
 
     /**
@@ -241,7 +246,7 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param cellName
      * @param value
      */
-    public void setStringValue( String cellName, String value ) {
+    public void setStringValue(String cellName, String value) {
         Cell cell = getCell(cellName);
         cell.setCellValue(value);
     }
@@ -252,9 +257,9 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param cellName
      * @param formula
      */
-    public void setFormulaValue( String cellName, String formula ) {
+    public void setFormulaValue(String cellName, String formula) {
         Cell cell = getCell(cellName);
-        cell.setCellFormula( formula );
+        cell.setCellFormula(formula);
     }
 
     /**
@@ -262,9 +267,9 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param cellName
      * @param date
      */
-    public void setDateValue( String cellName, Date date  ) {
+    public void setDateValue(String cellName, Date date) {
         Cell cell = getCell(cellName);
-        cell.setCellValue( date ) ;
+        cell.setCellValue(date);
     }
     /**
      * Uses a String in standard Excel format (SheetName!CellId) to locate a
@@ -281,7 +286,7 @@ public class ExcelAntWorkbookUtil extends Typedef {
 
         Cell cell = getCell(cellName);
 
-        FormulaEvaluator evaluator = getEvaluator( excelFileName );
+        FormulaEvaluator evaluator = getEvaluator(excelFileName);
 
 
         CellValue resultOfEval = evaluator.evaluate(cell);
@@ -294,20 +299,19 @@ public class ExcelAntWorkbookUtil extends Typedef {
                 evalResults = new ExcelAntEvaluationResult(false, false,
                         resultOfEval.getNumberValue(),
                         "Results was out of range based on precision " + " of "
-                                + precision + ".  Delta was actually " + delta, delta, cellName );
+                                + precision + ".  Delta was actually " + delta, delta, cellName);
             } else {
                 evalResults = new ExcelAntEvaluationResult(false, true,
                         resultOfEval.getNumberValue(),
-                        "Evaluation passed without error within in range.", delta, cellName );
+                        "Evaluation passed without error within in range.", delta, cellName);
             }
         } else {
-            String errorMeaning = null ;
+            String errorMeaning = null;
             try {
-                errorMeaning = ErrorConstants.getText( resultOfEval
-                        .getErrorValue() ) ;
-            } catch( IllegalArgumentException iae ) {
+                errorMeaning = FormulaError.forInt(resultOfEval.getErrorValue()).getString();
+            } catch(IllegalArgumentException iae) {
                 errorMeaning =  "unknown error code: " +
-                                Byte.toString( resultOfEval.getErrorValue() ) ;
+                                Byte.toString(resultOfEval.getErrorValue());
             }
 
             evalResults = new ExcelAntEvaluationResult(true, false,
@@ -315,7 +319,7 @@ public class ExcelAntWorkbookUtil extends Typedef {
                     "Evaluation failed due to an evaluation error of "
                             + resultOfEval.getErrorValue()
                             + " which is "
-                            + errorMeaning, 0, cellName );
+                            + errorMeaning, 0, cellName);
         }
 
         return evalResults;
@@ -327,9 +331,9 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param cellName
      * @return
      */
-    public String getCellAsString( String cellName ) {
-       Cell cell = getCell( cellName ) ;
-               return cell.getStringCellValue() ;
+    public String getCellAsString(String cellName) {
+       Cell cell = getCell(cellName);
+               return cell.getStringCellValue();
     }
 
 
@@ -339,9 +343,9 @@ public class ExcelAntWorkbookUtil extends Typedef {
      * @param cellName
      * @return
      */
-    public double getCellAsDouble( String cellName ) {
-       Cell cell = getCell( cellName ) ;
-               return cell.getNumericCellValue() ;
+    public double getCellAsDouble(String cellName) {
+       Cell cell = getCell(cellName);
+               return cell.getNumericCellValue();
     }
     /**
      * Returns a cell reference based on a String in standard Excel format
@@ -363,14 +367,14 @@ public class ExcelAntWorkbookUtil extends Typedef {
         int colIdx = cellRef.getCol();
         Row row = sheet.getRow(rowIdx);
 
-        if( row == null ) {
-               row = sheet.createRow( rowIdx ) ;
+        if(row == null) {
+               row = sheet.createRow(rowIdx);
         }
 
         Cell cell = row.getCell(colIdx);
 
-        if( cell == null ) {
-               cell = row.createCell( colIdx ) ;
+        if(cell == null) {
+               cell = row.createCell(colIdx);
         }
 
         return cell;
index 634c4e3c0f5cf6f1856e85e603052b4cdd790644..e9d385146a8e72938a349da40a52f47602957074 100644 (file)
 package org.apache.poi.ss.excelant.util;\r
 \r
 import java.util.HashMap;\r
+import java.util.Map;\r
 \r
 \r
 /**\r
  * This is a factory class maps file names to WorkbookUtil instances.  This\r
  * helps ExcelAnt be more efficient when being run many times in an Ant build.\r
  *\r
- * @author Jon Svede ( jon [at] loquatic [dot] com )\r
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )\r
+ * @author Jon Svede (jon [at] loquatic [dot] com)\r
+ * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)\r
  *\r
  */\r
-public class ExcelAntWorkbookUtilFactory {\r
+public final class ExcelAntWorkbookUtilFactory {\r
 \r
-    private static HashMap<String, ExcelAntWorkbookUtil> workbookUtilMap ;\r
-\r
-    private static ExcelAntWorkbookUtilFactory factory ;\r
+    private static Map<String, ExcelAntWorkbookUtil> workbookUtilMap;\r
 \r
     private ExcelAntWorkbookUtilFactory() {\r
-        workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>() ;\r
     }\r
 \r
     /**\r
@@ -45,19 +43,17 @@ public class ExcelAntWorkbookUtilFactory {
      * @param fileName\r
      * @return\r
      */\r
-    public static ExcelAntWorkbookUtil getInstance( String fileName ) {\r
-\r
-        if( factory == null ) {\r
-            factory = new ExcelAntWorkbookUtilFactory() ;\r
+    public static ExcelAntWorkbookUtil getInstance(String fileName) {\r
+        if(workbookUtilMap == null) {\r
+            workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>();\r
         }\r
-        if( workbookUtilMap != null &&\r
-                workbookUtilMap.containsKey( fileName ) ) {\r
-            return workbookUtilMap.get( fileName ) ;\r
+        if(workbookUtilMap != null &&\r
+                workbookUtilMap.containsKey(fileName)) {\r
+            return workbookUtilMap.get(fileName);\r
         }\r
 \r
-        ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil( fileName ) ;\r
-        workbookUtilMap.put( fileName, wbu ) ;\r
-        return wbu ;\r
+        ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName);\r
+        workbookUtilMap.put(fileName, wbu);\r
+        return wbu;\r
     }\r
-\r
 }\r
index 833dea67a69ca584c4e6311c36be98f2c2df2b80..9c9213e520e97926ebb38aa7519f71a128a87a7e 100644 (file)
 ==================================================================== */
 package org.apache.poi.ss.excelant.util;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
-public class TestExcelAntEvaluationResult extends TestCase {
-       
-       private ExcelAntEvaluationResult fixture ;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestExcelAntEvaluationResult {
+       private ExcelAntEvaluationResult fixture;
        
-       private boolean completedWithError = false ;
-    private boolean passed = false ;
-    private double retValue  = 1.1 
-    private String errMessage = "error message" ;  
-    private double delta = 2.2 
-    private String cellId = "testCell!$F$1" ;
+       private boolean completedWithError = false;
+    private boolean passed = false;
+    private double retValue  = 1.1; 
+    private String errMessage = "error message";  
+    private double delta = 2.2; 
+    private String cellId = "testCell!$F$1";
     
+    @Before
        public void setUp() {
-               fixture = new ExcelAntEvaluationResult( completedWithError,
+               fixture = new ExcelAntEvaluationResult(completedWithError,
                                                                passed, 
                                                                retValue,
                                                                errMessage, 
                                                                delta,
-                                                               cellId ) ;
+                                                               cellId);
        }
        
+    @After
        public void tearDown() {
-               fixture = null ;
+               fixture = null;
        }
        
+    @Test
        public void testCompletedWithErrorMessage() {
-               String errMsg = fixture.getErrorMessage() ;
-               assertNotNull( errMsg ) ;
-               assertEquals( errMsg, errMessage ) ;
+               String errMsg = fixture.getErrorMessage();
+               assertNotNull(errMsg);
+               assertEquals(errMsg, errMessage);
        }
        
+    @Test
        public void testPassed() {
-               boolean passedValue = fixture.didTestPass() ;
-               assertEquals( passedValue, passed ) ;
+               boolean passedValue = fixture.didTestPass();
+               assertEquals(passedValue, passed);
        }
        
+    @Test
        public void testDelta() {
-               double deltaValue = fixture.getDelta() ;
-               assertEquals(deltaValue, delta, 0.0 ) ;
+               double deltaValue = fixture.getDelta();
+               assertEquals(deltaValue, delta, 0.0);
        }
        
+    @Test
        public void testCellId() {
-               String cellIdValue = fixture.getCellName() ;
-               assertNotNull( cellIdValue ) ;
-               assertEquals( cellIdValue, cellId ) ;
+               String cellIdValue = fixture.getCellName();
+               assertNotNull(cellIdValue);
+               assertEquals(cellIdValue, cellId);
        }
-
 }
index afc330b9f86ee6e8e3f1306c2764cc2d2581d87e..bf68c2481724b3474257e4a5220bca076b60ee7c 100644 (file)
@@ -19,10 +19,8 @@ package org.apache.poi.ss.excelant.util;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Date;
-
-import junit.framework.TestCase;
+import java.util.List;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
@@ -34,6 +32,8 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.tools.ant.BuildException;
 
+import junit.framework.TestCase;
+
 public class TestExcelAntWorkbookUtil extends TestCase {
        
     private static final String mortgageCalculatorFileName =
@@ -198,9 +198,10 @@ public class TestExcelAntWorkbookUtil extends TestCase {
                                                                                precision);
 
                //System.out.println(result);
-               assertTrue(result.toString().contains("evaluationCompletedWithError=false"));
-               assertTrue(result.toString().contains("returnValue=790.79"));
-               assertTrue(result.toString().contains("cellName='MortgageCalculator'!B4"));
+               assertTrue("Had:" + result.toString(), result.toString().contains("evaluationCompletedWithError=false"));
+               assertTrue("Had:" + result.toString(), result.toString().contains("returnValue=790.79"));
+               assertTrue("Had:" + result.toString(), result.toString().contains("cellName='MortgageCalculator'!B4"));
+        assertFalse(result.toString().contains("#N/A"));
 
                assertFalse(result.evaluationCompleteWithError());
                assertTrue(result.didTestPass());
@@ -219,9 +220,10 @@ public class TestExcelAntWorkbookUtil extends TestCase {
                                                                 precision);
 
         //System.out.println(result);
-        assertTrue(result.toString().contains("evaluationCompletedWithError=false"));
-        assertTrue(result.toString().contains("returnValue=790.79"));
-        assertTrue(result.toString().contains("cellName='MortgageCalculator'!B4"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("evaluationCompletedWithError=false"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("returnValue=790.79"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("cellName='MortgageCalculator'!B4"));
+        assertFalse("Should not see an error, but had:" + result.toString(), result.toString().contains("#"));
 
         assertFalse(result.evaluationCompleteWithError());
         assertFalse(result.didTestPass());
@@ -240,9 +242,10 @@ public class TestExcelAntWorkbookUtil extends TestCase {
                                                                 precision);
 
         System.out.println(result);
-        assertTrue(result.toString().contains("evaluationCompletedWithError=true"));
-        assertTrue(result.toString().contains("returnValue=0.0"));
-        assertTrue(result.toString().contains("cellName='ErrorCell'!A1"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("evaluationCompletedWithError=true"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("returnValue=0.0"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("cellName='ErrorCell'!A1"));
+        assertTrue("Had:" + result.toString(), result.toString().contains("#N/A"));
 
         assertTrue(result.evaluationCompleteWithError());
         assertFalse(result.didTestPass());
@@ -252,7 +255,7 @@ public class TestExcelAntWorkbookUtil extends TestCase {
                fixture = new ExcelAntWorkbookUtilTestHelper(
                 mortgageCalculatorFileName);
                
-               ArrayList<String> sheets = fixture.getSheets();
+               List<String> sheets = fixture.getSheets();
                
                assertNotNull(sheets);
                assertEquals(sheets.size(), 3); 
index 0d4e7c31123c55cc190fea551071bb69a1772c8c..b69449a5f74e7fda286eb18f520ae7c88ee2147e 100644 (file)
 ==================================================================== */
 package org.apache.poi.ss.excelant.util;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import org.apache.poi.ss.excelant.BuildFileTest;
+import org.junit.Test;
 
 
 /**
  * Tests for the ExcelAntWorbookUtilFactory.
  * 
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
+ * @author Jon Svede (jon [at] loquatic [dot] com)
+ * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)
  *
  */
-public class TestExcelAntWorkbookUtilFactory extends TestCase{
+public class TestExcelAntWorkbookUtilFactory {
 
     private static final String mortgageCalculatorWorkbookFile =
         BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
@@ -38,13 +40,12 @@ public class TestExcelAntWorkbookUtilFactory extends TestCase{
         * Simple test to determine if the factory properly returns an non-null
         * instance of the ExcelAntWorkbookUtil class.
         */
+    @Test
        public void testGetNewWorkbookUtilInstance() {
-               
                ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
-                                                             mortgageCalculatorWorkbookFile ) ;
-               
-               assertNotNull( util ) ;
+                                                             mortgageCalculatorWorkbookFile) ;
                
+               assertNotNull(util) ;
        }
        
        
@@ -53,19 +54,19 @@ public class TestExcelAntWorkbookUtilFactory extends TestCase{
         * to an ExcelAnt WorkbookUtil when two different Strings, that point to
         * the same resource, are passed in. 
         */
+    @Test
        public void testVerifyEquivalence() {
                String sameFileName = BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
                
                ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
-                mortgageCalculatorWorkbookFile ) ;
+                mortgageCalculatorWorkbookFile) ;
 
                ExcelAntWorkbookUtil util2 = ExcelAntWorkbookUtilFactory.getInstance(
-                                                      sameFileName ) ;
+                                                      sameFileName) ;
                
-               assertNotNull( util ) ;
-               assertNotNull( util2 ) ;
+               assertNotNull(util) ;
+               assertNotNull(util2) ;
                
-               assertEquals( util, util2 ) ;
+               assertEquals(util, util2) ;
        }
-       
 }
index aeca27ea11352d8d19cc6d8d00f0e6a96e9fce3c..02a9267df1a0cffca7d77cd43038efd8c7e78401 100644 (file)
@@ -53,40 +53,48 @@ final class FunctionMetadataReader {
        private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet<String>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES));
 
        public static FunctionMetadataRegistry createRegistry() {
-               InputStream is = FunctionMetadataReader.class.getResourceAsStream(METADATA_FILE_NAME);
-               if (is == null) {
-                       throw new RuntimeException("resource '" + METADATA_FILE_NAME + "' not found");
-               }
-
-               BufferedReader br;
-               try {
-                       br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
-               } catch(UnsupportedEncodingException e) {
-                       throw new RuntimeException(e);
-               }
-               FunctionDataBuilder fdb = new FunctionDataBuilder(400);
-
-               try {
-                       while (true) {
-                               String line = br.readLine();
-                               if (line == null) {
-                                       break;
-                               }
-                               if (line.length() < 1 || line.charAt(0) == '#') {
-                                       continue;
-                               }
-                               String trimLine = line.trim();
-                               if (trimLine.length() < 1) {
-                                       continue;
-                               }
-                               processLine(fdb, line);
-                       }
-                       br.close();
-               } catch (IOException e) {
-                       throw new RuntimeException(e);
-               }
-
-               return fdb.build();
+           try {
+               InputStream is = FunctionMetadataReader.class.getResourceAsStream(METADATA_FILE_NAME);
+               if (is == null) {
+                       throw new RuntimeException("resource '" + METADATA_FILE_NAME + "' not found");
+               }
+    
+               try {
+                       BufferedReader br;
+                       try {
+                               br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
+                       } catch(UnsupportedEncodingException e) {
+                               throw new RuntimeException(e);
+                       }
+                       
+                       try {
+                           FunctionDataBuilder fdb = new FunctionDataBuilder(400);
+        
+                               while (true) {
+                                       String line = br.readLine();
+                                       if (line == null) {
+                                               break;
+                                       }
+                                       if (line.length() < 1 || line.charAt(0) == '#') {
+                                               continue;
+                                       }
+                                       String trimLine = line.trim();
+                                       if (trimLine.length() < 1) {
+                                               continue;
+                                       }
+                                       processLine(fdb, line);
+                               }
+
+                               return fdb.build();
+                       } finally {
+                           br.close();
+                       }
+               } finally {
+                   is.close();
+               }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+           } 
        }
 
        private static void processLine(FunctionDataBuilder fdb, String line) {
index 42a30ec8e796380e4903f4ce64c2d7bb2bb42c7a..51eede08f0f8f26160bb696aaae4274e3082c935 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.Test;
  * @author Evgeniy Berlog\r
  * @date 25.06.12\r
  */\r
+@SuppressWarnings("deprecation")\r
 public class TestText {\r
 \r
     @Test\r