]> source.dussan.org Git - poi.git/commitdiff
Eclipse warnings, comment out dead code, close resources, enhance unit tests, javadoc...
authorDominik Stadler <centic@apache.org>
Sun, 13 Sep 2015 19:05:55 +0000 (19:05 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 13 Sep 2015 19:05:55 +0000 (19:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1702802 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java

index 33a5ce6aafdb6c5df0afaf9ddf638fb149e8ad9d..d36347549b019b61fc6e35a2cca3aca6986ee6b0 100644 (file)
@@ -413,7 +413,7 @@ public class HSSFCell implements Cell {
                 errRec.setColumn(col);
                 if (setValue)
                 {
-                    errRec.setValue((byte)HSSFErrorConstants.ERROR_VALUE);
+                    errRec.setValue(FormulaError.VALUE.getCode());
                 }
                 errRec.setXFIndex(styleIndex);
                 errRec.setRow(row);
@@ -821,7 +821,7 @@ public class HSSFCell implements Cell {
             case CELL_TYPE_NUMERIC:
                 return NumberToTextConverter.toText(((NumberRecord)_record).getValue());
             case CELL_TYPE_ERROR:
-                   return HSSFErrorConstants.getText(((BoolErrRecord) _record).getErrorValue());
+                   return FormulaError.forInt(((BoolErrRecord)_record).getErrorValue()).getString();
             case CELL_TYPE_FORMULA:
                 // should really evaluate, but HSSFCell can't call HSSFFormulaEvaluator
                 // just use cached formula result instead
@@ -839,7 +839,7 @@ public class HSSFCell implements Cell {
             case CELL_TYPE_NUMERIC:
                 return NumberToTextConverter.toText(fr.getValue());
             case CELL_TYPE_ERROR:
-                   return HSSFErrorConstants.getText(fr.getCachedErrorValue());
+                   return FormulaError.forInt(fr.getCachedErrorValue()).getString();
         }
         throw new IllegalStateException("Unexpected formula result type (" + _cellType + ")");
     }
@@ -964,7 +964,7 @@ public class HSSFCell implements Cell {
      * Returns a string representation of the cell
      *
      * This method returns a simple representation,
-     * anthing more complex should be in user code, with
+     * anything more complex should be in user code, with
      * knowledge of the semantics of the sheet being processed.
      *
      * Formula cells return the formula string,
index 43140dcdd3c7001e5be2c16770cdb3e2eaf395bc..4156433bd44622a1fa8a66fd684a0a6ad8cfc856 100644 (file)
@@ -593,6 +593,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
     /**
      * Create a new row within the sheet and return the high level representation
      *
+     * Note: If a row already exists at this position, it is removed/overwritten and
+     *      any existing cell is removed!
+     *
      * @param rownum  row number
      * @return High level {@link XSSFRow} object representing a row in the sheet
      * @see #removeRow(org.apache.poi.ss.usermodel.Row)
index efe4f01ecb59468cf38815ae187e7057d2bdb4fe..a2306d72363c275fd365b44cdea3497e6e152872 100644 (file)
 
 package org.apache.poi.hssf.usermodel;
 
+import static org.apache.poi.POITestCase.assertContains;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.apache.poi.POITestCase.assertContains;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
-import junit.framework.AssertionFailedError;
-
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.ddf.EscherBSERecord;
 import org.apache.poi.hpsf.ClassID;
@@ -64,6 +61,8 @@ import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.TempFile;
 import org.junit.Test;
 
+import junit.framework.AssertionFailedError;
+
 /**
  * Tests for {@link HSSFWorkbook}
  */
@@ -80,7 +79,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
     }
 
     @Test
-    public void windowOneDefaults() {
+    public void windowOneDefaults() throws IOException {
         HSSFWorkbook b = new HSSFWorkbook( );
         try {
             assertEquals(b.getActiveSheetIndex(), 0);
@@ -88,13 +87,16 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         } catch (NullPointerException npe) {
             fail("WindowOneRecord in Workbook is probably not initialized");
         }
+        
+        b.close();
     }
 
     /**
      * Tests for {@link HSSFWorkbook#isHidden()} etc
+     * @throws IOException 
      */
     @Test
-    public void hidden() {
+    public void hidden() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
 
         WindowOneRecord w1 = wb.getWorkbook().getWindowOne();
@@ -106,20 +108,23 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         assertEquals(true, wb.isHidden());
         assertEquals(true, w1.getHidden());
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        w1 = wb.getWorkbook().getWindowOne();
+        HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        w1 = wbBack.getWorkbook().getWindowOne();
 
-        wb.setHidden(true);
-        assertEquals(true, wb.isHidden());
+        wbBack.setHidden(true);
+        assertEquals(true, wbBack.isHidden());
         assertEquals(true, w1.getHidden());
 
-        wb.setHidden(false);
-        assertEquals(false, wb.isHidden());
+        wbBack.setHidden(false);
+        assertEquals(false, wbBack.isHidden());
         assertEquals(false, w1.getHidden());
+        
+        wbBack.close();
+        wb.close();
     }
 
     @Test
-    public void sheetClone() {
+    public void sheetClone() throws IOException {
         // First up, try a simple file
         HSSFWorkbook b = new HSSFWorkbook();
         assertEquals(0, b.getNumberOfSheets());
@@ -131,10 +136,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         assertEquals(3, b.getNumberOfSheets());
 
         // Now try a problem one with drawing records in it
-        b = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls");
-        assertEquals(1, b.getNumberOfSheets());
-        b.cloneSheet(0);
-        assertEquals(2, b.getNumberOfSheets());
+        HSSFWorkbook bBack = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls");
+        assertEquals(1, bBack.getNumberOfSheets());
+        bBack.cloneSheet(0);
+        assertEquals(2, bBack.getNumberOfSheets());
+        
+        bBack.close();
+        b.close();
     }
 
     @Test
@@ -204,7 +212,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
     @SuppressWarnings("deprecation")
     @Test
-    public void selectedSheet_bug44523() {
+    public void selectedSheet_bug44523() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
         HSSFSheet sheet2 = wb.createSheet("Sheet2");
@@ -223,23 +231,21 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
         // Demonstrate bug 44525:
         // Well... not quite, since isActive + isSelected were also added in the same bug fix
-        if (sheet1.isSelected()) {
-            throw new AssertionFailedError("Identified bug 44523 a");
-        }
+        assertFalse("Identified bug 44523 a", sheet1.isSelected());
         wb.setActiveSheet(1);
-        if (sheet1.isActive()) {
-            throw new AssertionFailedError("Identified bug 44523 b");
-        }
+        assertFalse("Identified bug 44523 b", sheet1.isActive());
 
         confirmActiveSelected(sheet1, false);
         confirmActiveSelected(sheet2, true);
         confirmActiveSelected(sheet3, false);
         confirmActiveSelected(sheet4, false);
+        
+        wb.close();
     }
 
     @SuppressWarnings("unused")
     @Test
-    public void selectMultiple() {
+    public void selectMultiple() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
         HSSFSheet sheet2 = wb.createSheet("Sheet2");
@@ -291,11 +297,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
                 throw new RuntimeException(e);
             }
         }
+        
+        wb.close();
     }
 
 
     @Test
-    public void activeSheetAfterDelete_bug40414() {
+    public void activeSheetAfterDelete_bug40414() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         HSSFSheet sheet0 = wb.createSheet("Sheet0");
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
@@ -321,12 +329,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
         wb.removeSheetAt(3);
         // after removing the only active/selected sheet, another should be active/selected in its place
-        if (!sheet4.isSelected()) {
-            throw new AssertionFailedError("identified bug 40414 a");
-        }
-        if (!sheet4.isActive()) {
-            throw new AssertionFailedError("identified bug 40414 b");
-        }
+        assertTrue("identified bug 40414 a", sheet4.isSelected());
+        assertTrue("identified bug 40414 b", sheet4.isActive());
 
         confirmActiveSelected(sheet0, false);
         confirmActiveSelected(sheet1, false);
@@ -359,6 +363,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         // The last remaining sheet should always be active+selected
         wb.removeSheetAt(1);
         confirmActiveSelected(sheet0, true,  true);
+        
+        wb.close();
     }
 
     private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
@@ -377,9 +383,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
      * records to be written with invalid offset indexes.  Excel does not like this, and such
      * errors are particularly hard to track down.  This test ensures that HSSFWorkbook throws
      * a specific exception as soon as the situation is detected. See bugzilla 45066
+     * @throws IOException 
      */
     @Test
-    public void sheetSerializeSizeMismatch_bug45066() {
+    public void sheetSerializeSizeMismatch_bug45066() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
         List<RecordBase> sheetRecords = sheet.getRecords();
@@ -388,11 +395,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
         try {
             wb.getBytes();
-            throw new AssertionFailedError("Identified bug 45066 a");
+            fail("Identified bug 45066 a");
         } catch (IllegalStateException e) {
             // Expected badly behaved sheet record to cause exception
             assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
         }
+        
+        wb.close();
     }
 
     /**
@@ -563,6 +572,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         ClassID clsid2 = fs2.getRoot().getStorageClsid();
 
         assertTrue(clsid1.equals(clsid2));
+        
+        fs2.close();
+        wb.close();
     }
     
     /**
@@ -573,7 +585,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
     public void helpfulExceptionOnOldFiles() throws Exception {
         InputStream excel4 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_4.xls");
         try {
-            new HSSFWorkbook(excel4);
+            new HSSFWorkbook(excel4).close();
             fail("Shouldn't be able to load an Excel 4 file");
         } catch (OldExcelFormatException e) {
             assertContains(e.getMessage(), "BIFF4");
@@ -582,7 +594,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         
         InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls");
         try {
-            new HSSFWorkbook(excel5);
+            new HSSFWorkbook(excel5).close();
             fail("Shouldn't be able to load an Excel 5 file");
         } catch (OldExcelFormatException e) {
             assertContains(e.getMessage(), "BIFF5");
@@ -591,7 +603,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         
         InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls");
         try {
-            new HSSFWorkbook(excel95);
+            new HSSFWorkbook(excel95).close();
             fail("Shouldn't be able to load an Excel 95 file");
         } catch (OldExcelFormatException e) {
             assertContains(e.getMessage(), "BIFF5");
@@ -607,28 +619,37 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
     public void differentPOIFS() throws Exception {
        // Open the two filesystems
        DirectoryNode[] files = new DirectoryNode[2];
-       files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
-       NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"));
+       POIFSFileSystem poifsFileSystem = new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"));
        try {
-           files[1] = npoifsFileSystem.getRoot();
-           
-           // Open without preserving nodes 
-           for(DirectoryNode dir : files) {
-              HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
-              HSSFSheet sheet = workbook.getSheetAt(0);
-              HSSFCell cell = sheet.getRow(0).getCell(0);
-              assertEquals("replaceMe", cell .getRichStringCellValue().getString());
-           }
-    
-           // Now re-check with preserving
-           for(DirectoryNode dir : files) {
-              HSSFWorkbook workbook = new HSSFWorkbook(dir, true);
-              HSSFSheet sheet = workbook.getSheetAt(0);
-              HSSFCell cell = sheet.getRow(0).getCell(0);
-              assertEquals("replaceMe", cell .getRichStringCellValue().getString());
+           files[0] = poifsFileSystem.getRoot();
+           NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"));
+           try {
+               files[1] = npoifsFileSystem.getRoot();
+               
+               // Open without preserving nodes 
+               for(DirectoryNode dir : files) {
+                  HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
+                  HSSFSheet sheet = workbook.getSheetAt(0);
+                  HSSFCell cell = sheet.getRow(0).getCell(0);
+                  assertEquals("replaceMe", cell .getRichStringCellValue().getString());
+                  
+                  workbook.close();
+               }
+        
+               // Now re-check with preserving
+               for(DirectoryNode dir : files) {
+                  HSSFWorkbook workbook = new HSSFWorkbook(dir, true);
+                  HSSFSheet sheet = workbook.getSheetAt(0);
+                  HSSFCell cell = sheet.getRow(0).getCell(0);
+                  assertEquals("replaceMe", cell .getRichStringCellValue().getString());
+                  
+                  workbook.close();
+               }
+           } finally {
+               npoifsFileSystem.close();
            }
        } finally {
-           npoifsFileSystem.close();
+           poifsFileSystem.close();
        }
     }
 
@@ -636,32 +657,39 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
     public void wordDocEmbeddedInXls() throws IOException {
        // Open the two filesystems
        DirectoryNode[] files = new DirectoryNode[2];
-       files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot();
-       NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"));
+       POIFSFileSystem poifsFileSystem = new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"));
        try {
-           files[1] = npoifsFileSystem.getRoot();
-           
-           // Check the embedded parts
-           for(DirectoryNode root : files) {
-              HSSFWorkbook hw = new HSSFWorkbook(root, true);
-              List<HSSFObjectData> objects = hw.getAllEmbeddedObjects();
-              boolean found = false;
-              for (int i = 0; i < objects.size(); i++) {
-                 HSSFObjectData embeddedObject = objects.get(i);
-                 if (embeddedObject.hasDirectoryEntry()) {
-                    DirectoryEntry dir = embeddedObject.getDirectory();
-                    if (dir instanceof DirectoryNode) {
-                       DirectoryNode dNode = (DirectoryNode)dir;
-                       if (hasEntry(dNode,"WordDocument")) {
-                          found = true;
-                       }
-                    }
-                 }
-              }
-              assertTrue(found);
+           files[0] = poifsFileSystem.getRoot();
+           NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"));
+           try {
+               files[1] = npoifsFileSystem.getRoot();
+               
+               // Check the embedded parts
+               for(DirectoryNode root : files) {
+                  HSSFWorkbook hw = new HSSFWorkbook(root, true);
+                  List<HSSFObjectData> objects = hw.getAllEmbeddedObjects();
+                  boolean found = false;
+                  for (int i = 0; i < objects.size(); i++) {
+                     HSSFObjectData embeddedObject = objects.get(i);
+                     if (embeddedObject.hasDirectoryEntry()) {
+                        DirectoryEntry dir = embeddedObject.getDirectory();
+                        if (dir instanceof DirectoryNode) {
+                           DirectoryNode dNode = (DirectoryNode)dir;
+                           if (hasEntry(dNode,"WordDocument")) {
+                              found = true;
+                           }
+                        }
+                     }
+                  }
+                  assertTrue(found);
+                  
+                  hw.close();
+               }
+           } finally {
+               npoifsFileSystem.close();
            }
        } finally {
-           npoifsFileSystem.close();
+           poifsFileSystem.close();
        }
     }
 
@@ -682,9 +710,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
                assertEquals("Root xls", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
 
                // Will switch to POIFS
-               wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-               assertEquals(3, wb.getNumberOfSheets());
-               assertEquals("Root xls", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+               HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+               assertEquals(3, wbBack.getNumberOfSheets());
+               assertEquals("Root xls", wbBack.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+               wbBack.close();
+               
+               wb.close();
            } finally {
                   fs.close();
            }
@@ -694,7 +725,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
     }
 
     @Test
-    public void cellStylesLimit() {
+    public void cellStylesLimit() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         int numBuiltInStyles = wb.getNumCellStyles();
         int MAX_STYLES = 4030;
@@ -712,10 +743,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
                     "You can define up to 4000 styles in a .xls workbook", e.getMessage());
         }
         assertEquals(MAX_STYLES, wb.getNumCellStyles());
+        
+        wb.close();
     }
 
     @Test
-    public void setSheetOrderHSSF(){
+    public void setSheetOrderHSSF() throws IOException{
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s1 = wb.createSheet("first sheet");
         HSSFSheet s2 = wb.createSheet("other sheet");
@@ -769,6 +802,8 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         HSSFConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
         assertEquals("'first sheet'!D1", cf.getRule(0).getFormula1());
         assertEquals("'other sheet'!D1", cf.getRule(0).getFormula2());
+        
+        wb.close();
     }
 
     private boolean hasEntry(DirectoryNode dirNode, String entryName) {
@@ -821,8 +856,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
     @SuppressWarnings("deprecation")
     @Test
-    public void selectedSheetShort() {
+    public void selectedSheetShort() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
+        
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
         HSSFSheet sheet2 = wb.createSheet("Sheet2");
         HSSFSheet sheet3 = wb.createSheet("Sheet3");
@@ -840,13 +876,9 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
         // Demonstrate bug 44525:
         // Well... not quite, since isActive + isSelected were also added in the same bug fix
-        if (sheet1.isSelected()) {
-            throw new AssertionFailedError("Identified bug 44523 a");
-        }
+        assertFalse("Identified bug 44523 a", sheet1.isSelected());
         wb.setActiveSheet(1);
-        if (sheet1.isActive()) {
-            throw new AssertionFailedError("Identified bug 44523 b");
-        }
+        assertFalse("Identified bug 44523 b", sheet1.isActive());
 
         confirmActiveSelected(sheet1, false);
         confirmActiveSelected(sheet2, true);
@@ -857,10 +889,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         wb.setDisplayedTab((short)2);
         assertEquals(2, wb.getFirstVisibleTab());
         assertEquals(2, wb.getDisplayedTab());
+
+        wb.close();
     }
 
     @Test
-    public void addSheetTwice() {
+    public void addSheetTwice() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
         assertNotNull(sheet1);
@@ -870,10 +904,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         } catch (IllegalArgumentException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("already contains a sheet of this name"));
         }
+        
+        wb.close();
     }
 
     @Test
-    public void getSheetIndex() {
+    public void getSheetIndex() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         HSSFSheet sheet1 = wb.createSheet("Sheet1");
         HSSFSheet sheet2 = wb.createSheet("Sheet2");
@@ -894,11 +930,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         assertEquals(0, wb.getSheetIndex(sheet2));
         assertEquals(1, wb.getSheetIndex(sheet3));
         assertEquals(-1, wb.getSheetIndex(sheet4));
+        
+        wb.close();
     }
 
     @SuppressWarnings("deprecation")
     @Test
-    public void getExternSheetIndex() {
+    public void getExternSheetIndex() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         wb.createSheet("Sheet1");
         wb.createSheet("Sheet2");
@@ -914,20 +952,24 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         assertEquals(1, wb.getSheetIndexFromExternSheetIndex(1));
         assertEquals(-1, wb.getSheetIndexFromExternSheetIndex(2));
         assertEquals(-1, wb.getSheetIndexFromExternSheetIndex(100));
+        
+        wb.close();
     }
 
     @SuppressWarnings("deprecation")
     @Test
-    public void sstString() {
+    public void sstString() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
 
         int sst = wb.addSSTString("somestring");
         assertEquals("somestring", wb.getSSTString(sst));
         //assertNull(wb.getSSTString(sst+1));
+        
+        wb.close();
     }
 
     @Test
-    public void names() {
+    public void names() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
 
         try {
@@ -961,27 +1003,40 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         } catch (IllegalArgumentException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("outside the allowable range"));
         }
+        
+        wb.close();
     }
 
     @Test
-    public void testMethods() {
+    public void testMethods() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
         wb.insertChartRecord();
         //wb.dumpDrawingGroupRecords(true);
         //wb.dumpDrawingGroupRecords(false);
+        
+        wb.close();
     }
 
     @Test
-    public void writeProtection() {
+    public void writeProtection() throws IOException {
         HSSFWorkbook wb=new HSSFWorkbook();
 
         assertFalse(wb.isWriteProtected());
 
         wb.writeProtectWorkbook("mypassword", "myuser");
         assertTrue(wb.isWriteProtected());
+        
+//        OutputStream os = new FileOutputStream("/tmp/protected.xls");
+//        try {
+//            wb.write(os);
+//        } finally {
+//            os.close();
+//        }
 
         wb.unwriteProtectWorkbook();
         assertFalse(wb.isWriteProtected());
+
+        wb.close();
     }
 
     @Test
index 5117787d6f8716df5f2a2f58651fa874ee4147c7..95f5ea09ed26a62dca5f4736f85b4cf048d41ab5 100644 (file)
@@ -62,14 +62,18 @@ public class TestDateParser {
     public void testShouldParseValidDate() throws EvaluationException {
         Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
         Calendar actDate = DateParser.parseDate("1984/10/20");
-        assertEquals(expDate, actDate);
+        assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" + 
+                expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms", 
+                expDate, actDate);
     }
 
     @Test
     public void testShouldIgnoreTimestamp() throws EvaluationException {
         Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
         Calendar actDate = DateParser.parseDate("1984/10/20 12:34:56");
-        assertEquals(expDate, actDate);
+        assertEquals("Had: " + expDate.getTime() + " and " + actDate.getTime() + "/" + 
+                expDate.getTimeInMillis() + "ms and " + actDate.getTimeInMillis() + "ms", 
+                expDate, actDate);
     }
 
 }