]> source.dussan.org Git - poi.git/commitdiff
Some Eclipse warnings
authorDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 09:16:16 +0000 (09:16 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 09:16:16 +0000 (09:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647269 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
src/testcases/org/apache/poi/ss/format/TestCellFormat.java

index d85b6feae5fe529a81139ee80a9f3496ccd121a6..31b86b1fd98196e9703d7abff6edad46aa83608a 100644 (file)
@@ -96,7 +96,7 @@ final class OperationEvaluatorFactory {
        private static void put(Map<OperationPtg, Function> m, OperationPtg ptgKey,
                        Function instance) {
                // make sure ptg has single private constructor because map lookups assume singleton keys
-               Constructor[] cc = ptgKey.getClass().getDeclaredConstructors();
+               Constructor<?>[] cc = ptgKey.getClass().getDeclaredConstructors();
                if (cc.length > 1 || !Modifier.isPrivate(cc[0].getModifiers())) {
                        throw new RuntimeException("Failed to verify instance ("
                                        + ptgKey.getClass().getName() + ") is a singleton.");
index 967214380f25680e3124182d00fd8780e1264bf8..4dcaf63bf84c83ebaae9252b6c3aafdcdcccd2cd 100644 (file)
@@ -118,38 +118,42 @@ public final class TestXSSFCell extends BaseTestCell {
         assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_1.getCellType());
     }
 
-    public void testFormulaString() {
+    public void testFormulaString() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFCell cell = wb.createSheet().createRow(0).createCell(0);
-        CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml
-
-        cell.setCellFormula("A2");
-        assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
-        assertEquals("A2", cell.getCellFormula());
-        //the value is not set and cell's type='N' which means blank
-        assertEquals(STCellType.N, ctCell.getT());
-
-        //set cached formula value
-        cell.setCellValue("t='str'");
-        //we are still of 'formula' type
-        assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
-        assertEquals("A2", cell.getCellFormula());
-        //cached formula value is set and cell's type='STR'
-        assertEquals(STCellType.STR, ctCell.getT());
-        assertEquals("t='str'", cell.getStringCellValue());
-
-        //now remove the formula, the cached formula result remains
-        cell.setCellFormula(null);
-        assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType());
-        assertEquals(STCellType.STR, ctCell.getT());
-        //the line below failed prior to fix of Bug #47889
-        assertEquals("t='str'", cell.getStringCellValue());
-
-        //revert to a blank cell
-        cell.setCellValue((String)null);
-        assertEquals(XSSFCell.CELL_TYPE_BLANK, cell.getCellType());
-        assertEquals(STCellType.N, ctCell.getT());
-        assertEquals("", cell.getStringCellValue());
+        try {
+            XSSFCell cell = wb.createSheet().createRow(0).createCell(0);
+            CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml
+    
+            cell.setCellFormula("A2");
+            assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
+            assertEquals("A2", cell.getCellFormula());
+            //the value is not set and cell's type='N' which means blank
+            assertEquals(STCellType.N, ctCell.getT());
+    
+            //set cached formula value
+            cell.setCellValue("t='str'");
+            //we are still of 'formula' type
+            assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
+            assertEquals("A2", cell.getCellFormula());
+            //cached formula value is set and cell's type='STR'
+            assertEquals(STCellType.STR, ctCell.getT());
+            assertEquals("t='str'", cell.getStringCellValue());
+    
+            //now remove the formula, the cached formula result remains
+            cell.setCellFormula(null);
+            assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType());
+            assertEquals(STCellType.STR, ctCell.getT());
+            //the line below failed prior to fix of Bug #47889
+            assertEquals("t='str'", cell.getStringCellValue());
+    
+            //revert to a blank cell
+            cell.setCellValue((String)null);
+            assertEquals(XSSFCell.CELL_TYPE_BLANK, cell.getCellType());
+            assertEquals(STCellType.N, ctCell.getT());
+            assertEquals("", cell.getStringCellValue());
+        } finally {
+            wb.close();
+        }
     }
 
     /**
@@ -183,15 +187,20 @@ public final class TestXSSFCell extends BaseTestCell {
     /**
      * Cell with the formula that returns error must return error code(There was
      * an problem that cell could not return error value form formula cell).
+     * @throws IOException 
      */
-    public void testGetErrorCellValueFromFormulaCell() {
+    public void testGetErrorCellValueFromFormulaCell() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sheet = wb.createSheet();
-        XSSFRow row = sheet.createRow(0);
-        XSSFCell cell = row.createCell(0);
-        cell.setCellFormula("SQRT(-1)");
-        wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell);
-        assertEquals(36, cell.getErrorCellValue());
+        try {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFRow row = sheet.createRow(0);
+            XSSFCell cell = row.createCell(0);
+            cell.setCellFormula("SQRT(-1)");
+            wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell);
+            assertEquals(36, cell.getErrorCellValue());
+        } finally {
+            wb.close();
+        }
     }
 
     public void testMissingRAttribute() {
@@ -214,8 +223,8 @@ public final class TestXSSFCell extends BaseTestCell {
 
         assertCellsWithMissingR(row);
 
-        wb = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(wb);
-        row = wb.getSheetAt(0).getRow(0);
+        XSSFWorkbook wbNew = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(wb);
+        row = wbNew.getSheetAt(0).getRow(0);
         assertCellsWithMissingR(row);
     }
 
@@ -335,33 +344,37 @@ public final class TestXSSFCell extends BaseTestCell {
     
     public void test56170Reproduce() throws IOException {
         final Workbook wb = new XSSFWorkbook();
-        final Sheet sheet = wb.createSheet();
-        Row row = sheet.createRow(0);
-        
-        // by creating Cells out of order we trigger the handling in onDocumentWrite()
-        Cell cell1 = row.createCell(1);
-        Cell cell2 = row.createCell(0);
-
-        validateRow(row);
-        
-        validateRow(row);
-
-        // once again with removing one cell
-        row.removeCell(cell1);
-
-        validateRow(row);
-
-        // once again with removing one cell
-        row.removeCell(cell1);
-
-        // now check again
-        validateRow(row);
-
-        // once again with removing one cell
-        row.removeCell(cell2);
-
-        // now check again
-        validateRow(row);
+        try {
+            final Sheet sheet = wb.createSheet();
+            Row row = sheet.createRow(0);
+            
+            // by creating Cells out of order we trigger the handling in onDocumentWrite()
+            Cell cell1 = row.createCell(1);
+            Cell cell2 = row.createCell(0);
+    
+            validateRow(row);
+            
+            validateRow(row);
+    
+            // once again with removing one cell
+            row.removeCell(cell1);
+    
+            validateRow(row);
+    
+            // once again with removing one cell
+            row.removeCell(cell1);
+    
+            // now check again
+            validateRow(row);
+    
+            // once again with removing one cell
+            row.removeCell(cell2);
+    
+            // now check again
+            validateRow(row);
+        } finally {
+            wb.close();
+        }
     }
 
     private void validateRow(Row row) {
index 42adda983b3d1ba6c9ae5151f513b61681415207..9d2d7580c30f35be1be7d54330c3b8b4cf5b8cee 100644 (file)
 ==================================================================== */
 package org.apache.poi.ss.format;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-import javax.swing.*;
+import javax.swing.JLabel;
+
+import junit.framework.TestCase;
 
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
@@ -29,8 +32,6 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 
-import junit.framework.TestCase;
-
 public class TestCellFormat extends TestCase {
     
     private static final String _255_POUND_SIGNS;
@@ -825,15 +826,19 @@ public class TestCellFormat extends TestCase {
         
     }
     
-    public void testSimpleFractionFormat() {
+    public void testSimpleFractionFormat() throws IOException {
         CellFormat cf1 = CellFormat.getInstance("# ?/?");
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
-        Sheet sheet = wb.createSheet();
-        Row row = sheet.createRow(0);
-        Cell cell = row.createCell(0);
-        cell.setCellValue(123456.6);
-        System.out.println(cf1.apply(cell).text);
-        assertEquals("123456 3/5", cf1.apply(cell).text);
+        try {
+            Sheet sheet = wb.createSheet();
+            Row row = sheet.createRow(0);
+            Cell cell = row.createCell(0);
+            cell.setCellValue(123456.6);
+            System.out.println(cf1.apply(cell).text);
+            assertEquals("123456 3/5", cf1.apply(cell).text);
+        } finally {
+            wb.close();
+        }
     }
 }
\ No newline at end of file