poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1706742 [2/2] - in /poi/trunk/src: java/org/apache/poi/hpsf/ java/org/apache/poi/poifs/dev/ java/org/apache/poi/sl/usermodel/ ooxml/testcases/org/apache/poi/xssf/streaming/ ooxml/testcases/org/apache/poi/xssf/usermodel/ scratchpad/src/org/...
Date Mon, 05 Oct 2015 00:28:55 GMT
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=1706742&r1=1706741&r2=1706742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Mon Oct  5 00:28:54 2015
@@ -19,15 +19,14 @@ package org.apache.poi.hssf.usermodel;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.poi.ddf.EscherDgRecord;
@@ -70,7 +69,6 @@ import org.apache.poi.ss.usermodel.Sheet
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.util.TempFile;
 import org.junit.Test;
 
 /**
@@ -86,8 +84,8 @@ public final class TestHSSFSheet extends
         super(HSSFITestDataProvider.instance);
     }
     
-    @Test
-    public void createRowAfterLastRow() {
+    @Test(expected=IllegalArgumentException.class)
+    public void createRowAfterLastRow() throws IOException {
         createRowAfterLastRow(SpreadsheetVersion.EXCEL97);
     }
 
@@ -96,7 +94,7 @@ public final class TestHSSFSheet extends
      * Moved from TestHSSFWorkbook#testSetRepeatingRowsAndColumns().
      */
     @Test
-    public void setRepeatingRowsAndColumnsBug29747() {
+    public void setRepeatingRowsAndColumnsBug29747() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         wb.createSheet();
         wb.createSheet();
@@ -104,11 +102,12 @@ public final class TestHSSFSheet extends
         sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:2"));
         NameRecord nameRecord = wb.getWorkbook().getNameRecord(0);
         assertEquals(3, nameRecord.getSheetNumber());
+        wb.close();
     }
 
 
     @Test
-    public void getSetMargin() {
+    public void getSetMargin() throws IOException {
         baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3});
     }
 
@@ -116,13 +115,14 @@ public final class TestHSSFSheet extends
      * Test the gridset field gets set as expected.
      */
     @Test
-    public void backupRecord() {
+    public void backupRecord() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
         GridsetRecord gridsetRec = s.getSheet().getGridsetRecord();
 		assertTrue(gridsetRec.getGridset());
         s.setGridsPrinted(true);
         assertFalse(gridsetRec.getGridset());
+        wb.close();
     }
 
     /**
@@ -130,7 +130,7 @@ public final class TestHSSFSheet extends
      */
     @SuppressWarnings("deprecation")
     @Test
-    public void verticallyCenter() {
+    public void verticallyCenter() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
         VCenterRecord record = s.getSheet().getPageSettings().getVCenter();
@@ -143,14 +143,14 @@ public final class TestHSSFSheet extends
         assertTrue(s.getVerticallyCenter(true));
         assertTrue(s.getVerticallyCenter(false));
 
-        // wb.write(new FileOutputStream("c:\\test.xls"));
+        wb.close();
     }
 
     /**
      * Test horizontally centered output.
      */
     @Test
-    public void horizontallyCenter() {
+    public void horizontallyCenter() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
         HCenterRecord record = s.getSheet().getPageSettings().getHCenter();
@@ -158,6 +158,7 @@ public final class TestHSSFSheet extends
         assertFalse(record.getHCenter());
         s.setHorizontallyCenter(true);
         assertTrue(record.getHCenter());
+        wb.close();
     }
 
 
@@ -165,7 +166,7 @@ public final class TestHSSFSheet extends
      * Test WSBboolRecord fields get set in the user model.
      */
     @Test
-    public void wsBool() {
+    public void wsBool() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
         WSBoolRecord record =
@@ -208,20 +209,22 @@ public final class TestHSSFSheet extends
         assertFalse(s.getFitToPage());
         assertTrue(s.getRowSumsBelow());
         assertTrue(s.getRowSumsRight());
+        
+        wb.close();
     }
 
     /**
      * Setting landscape and portrait stuff on existing sheets
      */
     @Test
-    public void printSetupLandscapeExisting() {
-        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
+    public void printSetupLandscapeExisting() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
 
-        assertEquals(3, workbook.getNumberOfSheets());
+        assertEquals(3, wb1.getNumberOfSheets());
 
-        HSSFSheet sheetL = workbook.getSheetAt(0);
-        HSSFSheet sheetPM = workbook.getSheetAt(1);
-        HSSFSheet sheetLS = workbook.getSheetAt(2);
+        HSSFSheet sheetL = wb1.getSheetAt(0);
+        HSSFSheet sheetPM = wb1.getSheetAt(1);
+        HSSFSheet sheetLS = wb1.getSheetAt(2);
 
         // Check two aspects of the print setup
         assertFalse(sheetL.getPrintSetup().getLandscape());
@@ -245,20 +248,27 @@ public final class TestHSSFSheet extends
         assertEquals(1, sheetLS.getPrintSetup().getCopies());
 
         // Save and re-load, and check still there
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+        Workbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
 
+        sheetL = wb1.getSheetAt(0);
+        sheetPM = wb1.getSheetAt(1);
+        sheetLS = wb1.getSheetAt(2);
+        
         assertTrue(sheetL.getPrintSetup().getLandscape());
         assertFalse(sheetPM.getPrintSetup().getLandscape());
         assertTrue(sheetLS.getPrintSetup().getLandscape());
         assertEquals(1, sheetL.getPrintSetup().getCopies());
         assertEquals(3, sheetPM.getPrintSetup().getCopies());
         assertEquals(1, sheetLS.getPrintSetup().getCopies());
+        
+        wb2.close();
     }
 
     @Test
-    public void groupRows() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet s = workbook.createSheet();
+    public void groupRows() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet s = wb1.createSheet();
         HSSFRow r1 = s.createRow(0);
         HSSFRow r2 = s.createRow(1);
         HSSFRow r3 = s.createRow(2);
@@ -280,9 +290,10 @@ public final class TestHSSFSheet extends
         assertEquals(0, r5.getOutlineLevel());
 
         // Save and re-open
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
 
-        s = workbook.getSheetAt(0);
+        s = wb2.getSheetAt(0);
         r1 = s.getRow(0);
         r2 = s.getRow(1);
         r3 = s.getRow(2);
@@ -294,13 +305,14 @@ public final class TestHSSFSheet extends
         assertEquals(1, r3.getOutlineLevel());
         assertEquals(1, r4.getOutlineLevel());
         assertEquals(0, r5.getOutlineLevel());
+        wb2.close();
     }
 
     @Test
-    public void groupRowsExisting() {
-        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls");
+    public void groupRowsExisting() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls");
 
-        HSSFSheet s = workbook.getSheetAt(0);
+        HSSFSheet s = wb1.getSheetAt(0);
         HSSFRow r1 = s.getRow(0);
         HSSFRow r2 = s.getRow(1);
         HSSFRow r3 = s.getRow(2);
@@ -326,13 +338,14 @@ public final class TestHSSFSheet extends
         assertEquals(0, r6.getOutlineLevel());
 
         // Save and re-open
+        HSSFWorkbook wb2 = null;
         try {
-            workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+            wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
         } catch (OutOfMemoryError e) {
             fail("Identified bug 39903");
         }
 
-        s = workbook.getSheetAt(0);
+        s = wb2.getSheetAt(0);
         r1 = s.getRow(0);
         r2 = s.getRow(1);
         r3 = s.getRow(2);
@@ -346,19 +359,23 @@ public final class TestHSSFSheet extends
         assertEquals(1, r4.getOutlineLevel());
         assertEquals(1, r5.getOutlineLevel());
         assertEquals(0, r6.getOutlineLevel());
+
+        wb2.close();
+        wb1.close();
     }
 
     @Test
-    public void createDrawings() {
+    public void createDrawings() throws IOException {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
         HSSFPatriarch p1 = sheet.createDrawingPatriarch();
         HSSFPatriarch p2 = sheet.createDrawingPatriarch();
         assertSame(p1, p2);
+        workbook.close();
     }
 
     @Test
-    public void getDrawings() {
+    public void getDrawings() throws IOException {
         HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls");
         HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls");
 
@@ -377,13 +394,15 @@ public final class TestHSSFSheet extends
         assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart());
         assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart());
         assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart());
+        wb2c.close();
+        wb1c.close();
     }
 
     /**
      * Test that the ProtectRecord is included when creating or cloning a sheet
      */
     @Test
-    public void cloneWithProtect() {
+    public void cloneWithProtect() throws IOException {
         String passwordA = "secrect";
         int expectedHashA = -6810;
         String passwordB = "admin";
@@ -409,10 +428,11 @@ public final class TestHSSFSheet extends
         assertEquals(expectedHashB, hssfSheet.getPassword());
         // but the cloned sheet's password should remain unchanged
         assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash());
+        workbook.close();
     }
 
     @Test
-    public void protectSheetA() {
+    public void protectSheetA() throws IOException {
         int expectedHash = (short)0xfef1;
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
@@ -422,6 +442,7 @@ public final class TestHSSFSheet extends
         assertTrue("object protection should be on",pb.isObjectProtected());
         assertTrue("scenario protection should be on",pb.isScenarioProtected());
         assertEquals("well known value for top secret hash should be "+Integer.toHexString(expectedHash).substring(4), expectedHash, pb.getPasswordHash());
+        wb.close();
     }
 
     /**
@@ -429,7 +450,7 @@ public final class TestHSSFSheet extends
      * (which should be before {@link DimensionsRecord}).
      */
     @Test
-    public void protectSheetRecordOrder_bug47363a() {
+    public void protectSheetRecordOrder_bug47363a() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
         s.protectSheet("secret");
@@ -446,6 +467,8 @@ public final class TestHSSFSheet extends
         confirmRecordClass(recs, nRecs-8, ObjectProtectRecord.class);
         confirmRecordClass(recs, nRecs-7, ScenarioProtectRecord.class);
         confirmRecordClass(recs, nRecs-6, PasswordRecord.class);
+        
+        wb.close();
     }
 
     private static void confirmRecordClass(Record[] recs, int index, Class<? extends Record> cls) {
@@ -460,7 +483,7 @@ public final class TestHSSFSheet extends
      * There should be no problem with adding data validations after sheet protection
      */
     @Test
-    public void dvProtectionOrder_bug47363b() {
+    public void dvProtectionOrder_bug47363b() throws IOException {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet("Sheet1");
         sheet.protectSheet("secret");
@@ -476,6 +499,7 @@ public final class TestHSSFSheet extends
             if (expMsg.equals(e.getMessage())) {
                 fail("Identified bug 47363b");
             }
+            workbook.close();
             throw e;
         }
         RecordCollector rc;
@@ -489,10 +513,12 @@ public final class TestHSSFSheet extends
         int nRecsWithoutProtection = rc.getRecords().length;
 
         assertEquals(4, nRecsWithProtection - nRecsWithoutProtection);
+        
+        workbook.close();
     }
 
     @Test
-    public void zoom() {
+    public void zoom() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet();
         assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid));
@@ -531,6 +557,8 @@ public final class TestHSSFSheet extends
         } catch (IllegalArgumentException e) {
         	assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
         }
+        
+        wb.close();
     }
 
 
@@ -539,10 +567,10 @@ public final class TestHSSFSheet extends
      * Make sure the excel file loads work
      */
     @Test
-    public void pageBreakFiles() {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
+    public void pageBreakFiles() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
 
-        HSSFSheet sheet = wb.getSheetAt(0);
+        HSSFSheet sheet = wb1.getSheetAt(0);
         assertNotNull(sheet);
 
         assertEquals("1 row page break", 1, sheet.getRowBreaks().length);
@@ -557,22 +585,26 @@ public final class TestHSSFSheet extends
         assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
         assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
 
         assertTrue("No row page break", sheet.isRowBroken(22));
         assertTrue("No column page break", sheet.isColumnBroken((short)4));
 
         assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
         assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
+        
+        wb2.close();
     }
 
     @Test
-    public void dbcsName () {
+    public void dbcsName () throws IOException {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls");
         wb.getSheetAt(1);
         assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
         assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
+        wb.close();
     }
 
     /**
@@ -581,7 +613,7 @@ public final class TestHSSFSheet extends
      * of the sheet when it is first opened.
      */
     @Test
-    public void topRow() {
+    public void topRow() throws IOException {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls");
 
         HSSFSheet sheet = wb.getSheetAt(0);
@@ -592,34 +624,38 @@ public final class TestHSSFSheet extends
         sheet.showInPane(toprow,leftcol);
         assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow());
         assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol());
+        
+        wb.close();
     }
 
     @Test
-    public void addEmptyRow() {
+    public void addEmptyRow() throws IOException {
         //try to add 5 empty rows to a new sheet
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet sheet = wb1.createSheet();
         for (int i = 0; i < 5; i++) {
             sheet.createRow(i);
         }
 
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+        HSSFTestDataSamples.writeOutAndReadBack(wb1).close();
+        wb1.close();
 
         //try adding empty rows in an existing worksheet
-        workbook = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
+        HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
 
-        sheet = workbook.getSheetAt(0);
+        sheet = wb2.getSheetAt(0);
         for (int i = 3; i < 10; i++) sheet.createRow(i);
 
-        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+        HSSFTestDataSamples.writeOutAndReadBack(wb2).close();
+        wb2.close();
     }
 
     @SuppressWarnings("deprecation")
     @Test
-	public void autoSizeColumn() {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls");
+	public void autoSizeColumn() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("43902.xls");
         String sheetName = "my sheet";
-        HSSFSheet sheet = wb.getSheet(sheetName);
+        HSSFSheet sheet = wb1.getSheet(sheetName);
 
         // Can't use literal numbers for column sizes, as
         //  will come out with different values on different
@@ -641,7 +677,7 @@ public final class TestHSSFSheet extends
         sheet.addMergedRegion(new CellRangeAddress(1,1,0,1));
         assertNotNull(sheet.getMergedRegionAt(0));
         sheet.autoSizeColumn((short)0);
-        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
 
         // check that the autoSized column width has ignored the 2nd row
         // because it is included in a merged region (Excel like behavior)
@@ -656,17 +692,22 @@ public final class TestHSSFSheet extends
         HSSFSheet sheet3 = wb3.getSheet(sheetName);
         assertTrue(sheet3.getColumnWidth(0) >= minWithRow1And2);
         assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2);
+        
+        wb3.close();
+        wb2.close();
+        wb1.close();
     }
 
     @Test
-    public void testNoMergedRegionsIsEmptyList() {
+    public void testNoMergedRegionsIsEmptyList() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet("Sheet1");
         assertTrue(s.getMergedRegions().isEmpty());
+        wb.close();
     }
     
     @Test
-    public void autoSizeDate() throws Exception {
+    public void autoSizeDate() throws IOException {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet("Sheet1");
        HSSFRow r = s.createRow(0);
@@ -700,18 +741,20 @@ public final class TestHSSFSheet extends
        assertTrue("Date column too small: " + s.getColumnWidth(0), s.getColumnWidth(0) > 4750); 
        assertTrue("Date column too small: " + s.getColumnWidth(1), s.getColumnWidth(1) > 4750); 
        assertTrue("Date column too big: " + s.getColumnWidth(0), s.getColumnWidth(0) < 6500); 
-       assertTrue("Date column too big: " + s.getColumnWidth(0), s.getColumnWidth(0) < 6500); 
+       assertTrue("Date column too big: " + s.getColumnWidth(0), s.getColumnWidth(0) < 6500);
+       
+       wb.close();
     }
 
     /**
      * Setting ForceFormulaRecalculation on sheets
      */
     @Test
-    public void forceRecalculation() throws Exception {
-        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls");
+    public void forceRecalculation() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls");
 
-        HSSFSheet sheet = workbook.getSheetAt(0);
-        HSSFSheet sheet2 = workbook.getSheetAt(0);
+        HSSFSheet sheet = wb1.getSheetAt(0);
+        HSSFSheet sheet2 = wb1.getSheetAt(0);
         HSSFRow row = sheet.getRow(0);
         row.createCell(0).setCellValue(5);
         row.createCell(1).setCellValue(8);
@@ -719,22 +762,14 @@ public final class TestHSSFSheet extends
         assertFalse(sheet2.getForceFormulaRecalculation());
 
         // Save and manually verify that on column C we have 0, value in template
-        File tempFile = TempFile.createTempFile("uncalced_err", ".xls" );
-        FileOutputStream fout = new FileOutputStream( tempFile );
-        workbook.write( fout );
-        fout.close();
+        HSSFTestDataSamples.writeOutAndReadBack(wb1).close();
         sheet.setForceFormulaRecalculation(true);
         assertTrue(sheet.getForceFormulaRecalculation());
 
         // Save and manually verify that on column C we have now 13, calculated value
-        tempFile = TempFile.createTempFile("uncalced_succ", ".xls");
-        tempFile.delete();
-        fout = new FileOutputStream( tempFile );
-        workbook.write( fout );
-        fout.close();
-
         // Try it can be opened
-        HSSFWorkbook wb2 = new HSSFWorkbook(new FileInputStream(tempFile));
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
 
         // And check correct sheet settings found
         sheet = wb2.getSheetAt(0);
@@ -745,44 +780,41 @@ public final class TestHSSFSheet extends
         // Now turn if back off again
         sheet.setForceFormulaRecalculation(false);
 
-        fout = new FileOutputStream( tempFile );
-        wb2.write( fout );
-        fout.close();
-        wb2 = new HSSFWorkbook(new FileInputStream(tempFile));
-
-        assertFalse(wb2.getSheetAt(0).getForceFormulaRecalculation());
-        assertFalse(wb2.getSheetAt(1).getForceFormulaRecalculation());
-        assertFalse(wb2.getSheetAt(2).getForceFormulaRecalculation());
+        HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+        wb2.close();
+
+        assertFalse(wb3.getSheetAt(0).getForceFormulaRecalculation());
+        assertFalse(wb3.getSheetAt(1).getForceFormulaRecalculation());
+        assertFalse(wb3.getSheetAt(2).getForceFormulaRecalculation());
 
         // Now add a new sheet, and check things work
         //  with old ones unset, new one set
-        HSSFSheet s4 = wb2.createSheet();
+        HSSFSheet s4 = wb3.createSheet();
         s4.setForceFormulaRecalculation(true);
 
         assertFalse(sheet.getForceFormulaRecalculation());
         assertFalse(sheet2.getForceFormulaRecalculation());
         assertTrue(s4.getForceFormulaRecalculation());
 
-        fout = new FileOutputStream( tempFile );
-        wb2.write( fout );
-        fout.close();
-
-        HSSFWorkbook wb3 = new HSSFWorkbook(new FileInputStream(tempFile));
-        assertFalse(wb3.getSheetAt(0).getForceFormulaRecalculation());
-        assertFalse(wb3.getSheetAt(1).getForceFormulaRecalculation());
-        assertFalse(wb3.getSheetAt(2).getForceFormulaRecalculation());
-        assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
+        HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3);
+        wb3.close();
+        
+        assertFalse(wb4.getSheetAt(0).getForceFormulaRecalculation());
+        assertFalse(wb4.getSheetAt(1).getForceFormulaRecalculation());
+        assertFalse(wb4.getSheetAt(2).getForceFormulaRecalculation());
+        assertTrue(wb4.getSheetAt(3).getForceFormulaRecalculation());
+        wb4.close();
     }
 
     @Test
-    public void columnWidthA() {
+    public void columnWidthA() throws IOException {
         //check we can correctly read column widths from a reference workbook
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls");
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls");
 
         //reference values
         int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657};
 
-        HSSFSheet sh = wb.getSheetAt(0);
+        HSSFSheet sh = wb1.getSheetAt(0);
         for (char i = 'A'; i <= 'S'; i++) {
             int idx = i - 'A';
             int w = sh.getColumnWidth(idx);
@@ -790,7 +822,7 @@ public final class TestHSSFSheet extends
         }
 
         //the second sheet doesn't have overridden column widths
-        sh = wb.getSheetAt(1);
+        sh = wb1.getSheetAt(1);
         int def_width = sh.getDefaultColumnWidth();
         for (char i = 'A'; i <= 'S'; i++) {
             int idx = i - 'A';
@@ -799,10 +831,11 @@ public final class TestHSSFSheet extends
             //getColumnWidth returns width measured in 1/256th units
             assertEquals(def_width*256, w);
         }
+        wb1.close();
 
         //test new workbook
-        wb = new HSSFWorkbook();
-        sh = wb.createSheet();
+        HSSFWorkbook wb2 = new HSSFWorkbook();
+        sh = wb2.createSheet();
         sh.setDefaultColumnWidth(10);
         assertEquals(10, sh.getDefaultColumnWidth());
         assertEquals(256*10, sh.getColumnWidth(0));
@@ -815,9 +848,10 @@ public final class TestHSSFSheet extends
         }
 
         //serialize and read again
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+        wb2.close();
 
-        sh = wb.getSheetAt(0);
+        sh = wb3.getSheetAt(0);
         assertEquals(10, sh.getDefaultColumnWidth());
         //columns A-C have default width
         assertEquals(256*10, sh.getColumnWidth(0));
@@ -832,29 +866,33 @@ public final class TestHSSFSheet extends
         // check for 16-bit signed/unsigned error:
         sh.setColumnWidth(0, 40000);
         assertEquals(40000, sh.getColumnWidth(0));
+        wb3.close();
     }
 
 
     @Test
-    public void defaultColumnWidth() {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" );
-        HSSFSheet sheet = wb.getSheetAt( 7 );
+    public void defaultColumnWidth() throws IOException {
+        HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" );
+        HSSFSheet sheet = wb1.getSheetAt( 7 );
         // shall not be NPE
         assertEquals(8, sheet.getDefaultColumnWidth());
         assertEquals(8*256, sheet.getColumnWidth(0));
 
         assertEquals(0xFF, sheet.getDefaultRowHeight());
+        
+        wb1.close();
 
-        wb = HSSFTestDataSamples.openSampleWorkbook( "34775.xls" );
+        HSSFWorkbook wb2 = HSSFTestDataSamples.openSampleWorkbook( "34775.xls" );
         // second and third sheets miss DefaultColWidthRecord
         for(int i = 1; i <= 2; i++){
-            int dw = wb.getSheetAt( i ).getDefaultColumnWidth();
+            int dw = wb2.getSheetAt( i ).getDefaultColumnWidth();
             assertEquals(8, dw);
-            int cw = wb.getSheetAt( i ).getColumnWidth(0);
+            int cw = wb2.getSheetAt( i ).getColumnWidth(0);
             assertEquals(8*256, cw);
 
             assertEquals(0xFF, sheet.getDefaultRowHeight());
         }
+        wb2.close();
     }
 
     /**
@@ -863,22 +901,22 @@ public final class TestHSSFSheet extends
      * Now POI is too.
      */
     @Test
-    public void missingRowRecords_bug41187() {
+    public void missingRowRecords_bug41187() throws IOException {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls");
 
         HSSFSheet sheet = wb.getSheetAt(0);
         HSSFRow row = sheet.getRow(0);
-        if(row == null) {
-            fail("Identified bug 41187 a");
-        }
-        if (row.getHeight() == 0) {
-            fail("Identified bug 41187 b");
-        }
+        assertNotNull("Identified bug 41187 a", row);
+
+        assertNotEquals("Identified bug 41187 b", (short)0, row.getHeight());
+
         assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString());
         // check row height for 'default' flag
         assertEquals((short)0xFF, row.getHeight());
 
-        HSSFTestDataSamples.writeOutAndReadBack(wb);
+        HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+        
+        wb.close();
     }
 
     /**
@@ -888,7 +926,7 @@ public final class TestHSSFSheet extends
      * See bug #45720.
      */
     @Test
-    public void cloneSheetWithDrawings() {
+    public void cloneSheetWithDrawings() throws IOException {
         HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls");
 
         HSSFSheet sheet1 = wb1.getSheetAt(0);
@@ -899,6 +937,8 @@ public final class TestHSSFSheet extends
         wb1.cloneSheet(0);
 
         HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        
         wb2.getWorkbook().findDrawingGroup();
         DrawingManager2 dm2 = wb2.getWorkbook().getDrawingManager();
 
@@ -915,6 +955,7 @@ public final class TestHSSFSheet extends
         assertEquals(dg_id_1 + 1, dg_id_2);
 
         //TODO: check shapeId in the cloned sheet
+        wb2.close();
     }
 
     /**
@@ -923,7 +964,7 @@ public final class TestHSSFSheet extends
      * 31 chars.
      */
     @Test
-    public void longSheetNames() {
+    public void longSheetNames() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars
 
@@ -935,13 +976,14 @@ public final class TestHSSFSheet extends
             assertEquals("The workbook already contains a sheet of this name", e.getMessage());
         }
         wb.createSheet(SAME_PREFIX + "Exxxx"); // OK - differs in the 31st char
+        wb.close();
     }
 
     /**
      * Tests that we can read existing column styles
      */
     @Test
-    public void readColumnStyles() {
+    public void readColumnStyles() throws IOException {
         HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls");
         HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls");
         HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls");
@@ -975,26 +1017,31 @@ public final class TestHSSFSheet extends
         assertEquals(10, cs.getFont(wbComplex).getColor());
         assertFalse(cs.getFont(wbComplex).getItalic());
         assertEquals(HSSFFont.BOLDWEIGHT_BOLD, cs.getFont(wbComplex).getBoldweight());
+        
+        wbComplex.close();
+        wbSimple.close();
+        wbNone.close();
     }
 
     /**
      * Tests the arabic setting
      */
     @Test
-    public void arabic() {
+    public void arabic() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet s = wb.createSheet();
 
         assertFalse(s.isRightToLeft());
         s.setRightToLeft(true);
         assertTrue(s.isRightToLeft());
+        wb.close();
     }
 
     @Test
-    public void autoFilter(){
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sh = wb.createSheet();
-        InternalWorkbook iwb = wb.getWorkbook();
+    public void autoFilter() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet sh = wb1.createSheet();
+        InternalWorkbook iwb = wb1.getWorkbook();
         InternalSheet ish = sh.getSheet();
 
         assertNull( iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1) );
@@ -1029,8 +1076,9 @@ public final class TestHSSFSheet extends
 
         assertNull( ish.findFirstRecordBySid(ObjRecord.sid) ); // ObjRecord will appear after serializetion
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sh = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sh = wb2.getSheetAt(0);
         ish = sh.getSheet();
         ObjRecord objRecord = (ObjRecord)ish.findFirstRecordBySid(ObjRecord.sid);
         List<SubRecord> subRecords = objRecord.getSubRecords();
@@ -1038,20 +1086,22 @@ public final class TestHSSFSheet extends
         assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord );
         assertTrue(subRecords.get(1) instanceof FtCblsSubRecord ); // must be present, see Bug 51481
         assertTrue(subRecords.get(2) instanceof LbsDataSubRecord );
+        wb2.close();
     }
 
     @Test
-    public void getSetColumnHiddenShort() {
+    public void getSetColumnHiddenShort() throws IOException {
         Workbook workbook = new HSSFWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         sheet.setColumnHidden((short)2, true);
         assertTrue(sheet.isColumnHidden((short)2));
+        workbook.close();
     }
 
     @Test
-    public void columnWidthShort() {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        Sheet sheet = wb.createSheet();
+    public void columnWidthShort() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         //default column width measured in characters
         sheet.setDefaultColumnWidth((short)10);
@@ -1092,9 +1142,10 @@ public final class TestHSSFSheet extends
         }
 
         //serialize and read again
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
 
-        sheet = wb.getSheetAt(0);
+        sheet = wb2.getSheetAt(0);
         assertEquals(20, sheet.getDefaultColumnWidth());
         //columns A-C have default width
         assertEquals(256*20, sheet.getColumnWidth((short)0));
@@ -1106,10 +1157,12 @@ public final class TestHSSFSheet extends
             assertEquals(w, sheet.getColumnWidth((short)i));
         }
         assertEquals(40000, sheet.getColumnWidth((short)10));
+        
+        wb2.close();
     }
 
     @Test
-    public void showInPane() {
+    public void showInPane() throws IOException {
         Workbook wb = new HSSFWorkbook();
         Sheet sheet = wb.createSheet();
         sheet.showInPane(2, 3);
@@ -1117,10 +1170,11 @@ public final class TestHSSFSheet extends
         thrown.expect(IllegalArgumentException.class);
         thrown.expectMessage("Maximum row number is 65535");
     	sheet.showInPane(Integer.MAX_VALUE, 3);
+    	wb.close();
     }
     
     @Test
-    public void drawingRecords() {
+    public void drawingRecords() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet();
 
@@ -1128,10 +1182,11 @@ public final class TestHSSFSheet extends
         sheet.dumpDrawingRecords(false);
         sheet.dumpDrawingRecords(true);*/
         assertNull(sheet.getDrawingEscherAggregate());
+        wb.close();
     }
 
     @Test
-    public void bug55723b() {
+    public void bug55723b() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -1145,5 +1200,6 @@ public final class TestHSSFSheet extends
         // stored with a special name
         NameRecord record = wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1);
         assertNotNull(record);
+        wb.close();
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java?rev=1706742&r1=1706741&r2=1706742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java Mon Oct  5 00:28:54 2015
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.FileOutputStream;
 import java.io.IOException;
 
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -45,7 +44,7 @@ public abstract class BaseTestCellCommen
     }
 
     @Test
-    public final void find() {
+    public final void find() throws IOException {
         Workbook book = _testDataProvider.createWorkbook();
         Sheet sheet = book.createSheet();
         assertNull(sheet.getCellComment(0, 0));
@@ -54,20 +53,21 @@ public abstract class BaseTestCellCommen
         Cell cell = row.createCell(0);
         assertNull(sheet.getCellComment(0, 0));
         assertNull(cell.getCellComment());
+        book.close();
     }
 
     @Test
-    public final void create() {
+    public final void create() throws IOException {
         String cellText = "Hello, World";
         String commentText = "We can set comments in POI";
         String commentAuthor = "Apache Software Foundation";
         int cellRow = 3;
         int cellColumn = 1;
 
-        Workbook wb = _testDataProvider.createWorkbook();
-        CreationHelper factory = wb.getCreationHelper();
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        CreationHelper factory = wb1.getCreationHelper();
 
-        Sheet sheet = wb.createSheet();
+        Sheet sheet = wb1.createSheet();
         assertNull(sheet.getCellComment(cellRow, cellColumn));
 
         Cell cell = sheet.createRow(cellRow).createCell(cellColumn);
@@ -98,8 +98,10 @@ public abstract class BaseTestCellCommen
         assertEquals(cellRow, comment.getRow());
         assertEquals(cellColumn, comment.getColumn());
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        
+        sheet = wb2.getSheetAt(0);
         cell = sheet.getRow(cellRow).getCell(cellColumn);
         comment = cell.getCellComment();
 
@@ -114,9 +116,10 @@ public abstract class BaseTestCellCommen
         comment.setString(factory.createRichTextString("New Comment Text"));
         comment.setVisible(false);
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
+        Workbook wb3 = _testDataProvider.writeOutAndReadBack(wb2);
+        wb2.close();
 
-        sheet = wb.getSheetAt(0);
+        sheet = wb3.getSheetAt(0);
         cell = sheet.getRow(cellRow).getCell(cellColumn);
         comment = cell.getCellComment();
 
@@ -126,13 +129,15 @@ public abstract class BaseTestCellCommen
         assertEquals(cellRow, comment.getRow());
         assertEquals(cellColumn, comment.getColumn());
         assertFalse(comment.isVisible());
+        
+        wb3.close();
     }
 
     /**
      * test that we can read cell comments from an existing workbook.
      */
     @Test
-    public final void readComments() {
+    public final void readComments() throws IOException {
 
         Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
 
@@ -163,18 +168,20 @@ public abstract class BaseTestCellCommen
             assertEquals(rownum, comment.getRow());
             assertEquals(cell.getColumnIndex(), comment.getColumn());
         }
+        
+        wb.close();
     }
 
     /**
      * test that we can modify existing cell comments
      */
     @Test
-    public final void modifyComments() {
+    public final void modifyComments() throws IOException {
 
-        Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
-        CreationHelper factory = wb.getCreationHelper();
+        Workbook wb1 = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
+        CreationHelper factory = wb1.getCreationHelper();
 
-        Sheet sheet = wb.getSheetAt(0);
+        Sheet sheet = wb1.getSheetAt(0);
 
         Cell cell;
         Row row;
@@ -188,8 +195,9 @@ public abstract class BaseTestCellCommen
             comment.setString(factory.createRichTextString("Modified comment at row " + rownum));
         }
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
 
         for (int rownum = 0; rownum < 3; rownum++) {
             row = sheet.getRow(rownum);
@@ -199,12 +207,14 @@ public abstract class BaseTestCellCommen
             assertEquals("Mofified[" + rownum + "] by Yegor", comment.getAuthor());
             assertEquals("Modified comment at row " + rownum, comment.getString().getString());
         }
+        
+        wb2.close();
     }
 
     @Test
-    public final void deleteComments() {
-        Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
-        Sheet sheet = wb.getSheetAt(0);
+    public final void deleteComments() throws IOException {
+        Workbook wb1 = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
+        Sheet sheet = wb1.getSheetAt(0);
 
         // Zap from rows 1 and 3
         assertNotNull(sheet.getRow(0).getCell(1).getCellComment());
@@ -220,24 +230,27 @@ public abstract class BaseTestCellCommen
         assertNull(sheet.getRow(2).getCell(1).getCellComment());
 
         // Save and re-load
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         // Check
         assertNull(sheet.getRow(0).getCell(1).getCellComment());
         assertNotNull(sheet.getRow(1).getCell(1).getCellComment());
         assertNull(sheet.getRow(2).getCell(1).getCellComment());
+        
+        wb2.close();
     }
 
     /**
      * code from the quick guide
      */
     @Test
-    public void quickGuide(){
-        Workbook wb = _testDataProvider.createWorkbook();
+    public void quickGuide() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
 
-        CreationHelper factory = wb.getCreationHelper();
+        CreationHelper factory = wb1.getCreationHelper();
 
-        Sheet sheet = wb.createSheet();
+        Sheet sheet = wb1.createSheet();
 
         Cell cell = sheet.createRow(3).createCell(5);
         cell.setCellValue("F4");
@@ -252,8 +265,9 @@ public abstract class BaseTestCellCommen
         //assign the comment to the cell
         cell.setCellComment(comment);
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         cell = sheet.getRow(3).getCell(5);
         comment = cell.getCellComment();
         assertNotNull(comment);
@@ -261,6 +275,8 @@ public abstract class BaseTestCellCommen
         assertEquals("Apache POI", comment.getAuthor());
         assertEquals(3, comment.getRow());
         assertEquals(5, comment.getColumn());
+        
+        wb2.close();
     }
 
     @Test
@@ -334,5 +350,7 @@ public abstract class BaseTestCellCommen
             assertEquals( 3, anchor.getRow2());
             assertEquals(16*EMU_PER_PIXEL, anchor.getDy2());
         }
+        
+        wb.close();
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java?rev=1706742&r1=1706741&r2=1706742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java Mon Oct  5 00:28:54 2015
@@ -19,7 +19,14 @@
 
 package org.apache.poi.ss.usermodel;
 
-import junit.framework.TestCase;
+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 java.io.IOException;
 
 import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting;
 import org.apache.poi.hssf.usermodel.HSSFConditionalFormattingRule;
@@ -27,11 +34,12 @@ import org.apache.poi.ss.ITestDataProvid
 import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
 import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.junit.Test;
 
 /**
  * Base tests for Conditional Formatting, for both HSSF and XSSF
  */
-public abstract class BaseTestConditionalFormatting extends TestCase {
+public abstract class BaseTestConditionalFormatting {
     private final ITestDataProvider _testDataProvider;
 
     public BaseTestConditionalFormatting(ITestDataProvider testDataProvider){
@@ -40,7 +48,8 @@ public abstract class BaseTestConditiona
     
     protected abstract void assertColour(String hexExpected, Color actual);
 
-    public void testBasic() {
+    @Test
+    public void testBasic() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sh = wb.createSheet();
         SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
@@ -96,13 +105,15 @@ public abstract class BaseTestConditiona
         } catch (IllegalArgumentException e) {
             assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
         }
+        wb.close();
     }
 
     /**
      * Test format conditions based on a boolean formula
      */
+    @Test
     @SuppressWarnings("deprecation")
-    public void testBooleanFormulaConditions() {
+    public void testBooleanFormulaConditions() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sh = wb.createSheet();
         SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
@@ -135,10 +146,12 @@ public abstract class BaseTestConditiona
         CellRangeAddress[] ranges2 = sheetCF.getConditionalFormattingAt(formatIndex2).getFormattingRanges();
         assertEquals(1, ranges2.length);
         assertEquals("B1:B3", ranges2[0].formatAsString());
+        wb.close();
     }
 
+    @Test
     @SuppressWarnings("deprecation")
-    public void testSingleFormulaConditions() {
+    public void testSingleFormulaConditions() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sh = wb.createSheet();
         SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
@@ -207,10 +220,13 @@ public abstract class BaseTestConditiona
         assertEquals("0", rule9.getFormula1());
         assertEquals("5", rule9.getFormula2());
         assertEquals(ComparisonOperator.NOT_BETWEEN, rule9.getComparisonOperation());
+        
+        wb.close();
     }
 
+    @Test
     @SuppressWarnings("deprecation")
-    public void testCopy() {
+    public void testCopy() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet1 = wb.createSheet();
         Sheet sheet2 = wb.createSheet();
@@ -246,9 +262,12 @@ public abstract class BaseTestConditiona
         assertEquals("15", sheet2cf.getRule(1).getFormula1());
         assertEquals(ComparisonOperator.NOT_EQUAL, sheet2cf.getRule(1).getComparisonOperation());
         assertEquals(ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS, sheet2cf.getRule(1).getConditionType());
+        
+        wb.close();
     }
 
-    public void testRemove() {
+    @Test
+    public void testRemove() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet1 = wb.createSheet();
         SheetConditionalFormatting sheetCF = sheet1.getSheetConditionalFormatting();
@@ -287,9 +306,12 @@ public abstract class BaseTestConditiona
         } catch (IllegalArgumentException e) {
             assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
         }
+        
+        wb.close();
     }
     
-    public void testCreateCF() {
+    @Test
+    public void testCreateCF() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
         String formula = "7";
@@ -366,9 +388,12 @@ public abstract class BaseTestConditiona
         rule2 = cf.getRule(1);
         assertEquals("2",rule2.getFormula2());
         assertEquals("1",rule2.getFormula1());
+        
+        workbook.close();
     }
 
-    public void testClone() {
+    @Test
+    public void testClone() throws IOException {
 
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
@@ -399,16 +424,19 @@ public abstract class BaseTestConditiona
 
         try {
             wb.cloneSheet(0);
+            assertEquals(2, wb.getNumberOfSheets());
         } catch (RuntimeException e) {
             if (e.getMessage().indexOf("needs to define a clone method") > 0) {
                 fail("Indentified bug 45682");
             }
             throw e;
+        } finally {
+            wb.close();
         }
-        assertEquals(2, wb.getNumberOfSheets());
     }
 
-    public void testShiftRows() {
+    @Test
+    public void testShiftRows() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -457,9 +485,11 @@ public abstract class BaseTestConditiona
         cf2 = sheetCF.getConditionalFormattingAt(1);
         assertEquals("SUM(A10:A21)", cf2.getRule(0).getFormula1());
         assertEquals("1+SUM(#REF!)", cf2.getRule(0).getFormula2());
+
+        wb.close();
     }
 
-    protected void testRead(String filename){
+    protected void testRead(String filename) throws IOException {
         Workbook wb = _testDataProvider.openSampleWorkbook(filename);
         Sheet sh = wb.getSheet("CF");
         SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
@@ -542,9 +572,11 @@ public abstract class BaseTestConditiona
         assertEquals(ComparisonOperator.BETWEEN, rule5.getComparisonOperation());
         assertEquals("\"A\"", rule5.getFormula1());
         assertEquals("\"AAA\"", rule5.getFormula2());
+        
+        wb.close();
     }
 
-    public void testReadOffice2007(String filename) {
+    public void testReadOffice2007(String filename) throws IOException {
         Workbook wb = _testDataProvider.openSampleWorkbook(filename);
         Sheet s = wb.getSheet("CF");
         ConditionalFormatting cf = null;
@@ -768,6 +800,8 @@ public abstract class BaseTestConditiona
         
         // Mixed icons - Column U
         // TODO Support EXT formattings
+        
+        wb.close();
     }
     
     private void assertDataBar(ConditionalFormatting cf, String color) {
@@ -869,7 +903,8 @@ public abstract class BaseTestConditiona
         }
     }
 
-    public void testCreateFontFormatting() {
+    @Test
+    public void testCreateFontFormatting() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
 
@@ -934,9 +969,11 @@ public abstract class BaseTestConditiona
         assertEquals(FontFormatting.U_DOUBLE, r1fp.getUnderlineType());
         assertEquals(IndexedColors.BLUE.index, r1fp.getFontColorIndex());
 
+        workbook.close();
     }
 
-    public void testCreatePatternFormatting() {
+    @Test
+    public void testCreatePatternFormatting() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
 
@@ -979,9 +1016,12 @@ public abstract class BaseTestConditiona
         assertEquals(IndexedColors.RED.index, r1fp.getFillBackgroundColor());
         assertEquals(IndexedColors.BLUE.index, r1fp.getFillForegroundColor());
         assertEquals(PatternFormatting.BRICKS, r1fp.getFillPattern());
+        
+        workbook.close();
     }
 
-    public void testCreateBorderFormatting() {
+    @Test
+    public void testCreateBorderFormatting() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
 
@@ -1040,11 +1080,14 @@ public abstract class BaseTestConditiona
         assertEquals(BorderFormatting.BORDER_THICK, r1fp.getBorderTop());
         assertEquals(BorderFormatting.BORDER_THIN, r1fp.getBorderLeft());
         assertEquals(BorderFormatting.BORDER_HAIR, r1fp.getBorderRight());
+        
+        workbook.close();
     }
     
-    public void testCreateIconFormatting() {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+    @Test
+    public void testCreateIconFormatting() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
         ConditionalFormattingRule rule1 = 
@@ -1066,9 +1109,11 @@ public abstract class BaseTestConditiona
         
         CellRangeAddress [] regions = { CellRangeAddress.valueOf("A1:A5") };
         sheetCF.addConditionalFormatting(regions, rule1);
-        
+
         // Save, re-load and re-check
-        workbook = _testDataProvider.writeOutAndReadBack(workbook);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         sheetCF = sheet.getSheetConditionalFormatting();
         assertEquals(1, sheetCF.getNumConditionalFormattings());
         
@@ -1088,14 +1133,17 @@ public abstract class BaseTestConditiona
         assertEquals(RangeType.PERCENT,iconFmt.getThresholds()[2].getRangeType());
         assertEquals(RangeType.MAX,    iconFmt.getThresholds()[3].getRangeType());
         assertEquals(null, iconFmt.getThresholds()[0].getValue());
-        assertEquals(10d,  iconFmt.getThresholds()[1].getValue());
-        assertEquals(75d,  iconFmt.getThresholds()[2].getValue());
+        assertEquals(10d,  iconFmt.getThresholds()[1].getValue(), 0);
+        assertEquals(75d,  iconFmt.getThresholds()[2].getValue(), 0);
         assertEquals(null, iconFmt.getThresholds()[3].getValue());
+        
+        wb2.close();
     }
     
-    public void testCreateColorScaleFormatting() {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+    @Test
+    public void testCreateColorScaleFormatting() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
         ConditionalFormattingRule rule1 = 
@@ -1115,7 +1163,9 @@ public abstract class BaseTestConditiona
         sheetCF.addConditionalFormatting(regions, rule1);
         
         // Save, re-load and re-check
-        workbook = _testDataProvider.writeOutAndReadBack(workbook);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         sheetCF = sheet.getSheetConditionalFormatting();
         assertEquals(1, sheetCF.getNumConditionalFormattings());
         
@@ -1133,16 +1183,19 @@ public abstract class BaseTestConditiona
         assertEquals(RangeType.NUMBER, clrFmt.getThresholds()[1].getRangeType());
         assertEquals(RangeType.MAX,    clrFmt.getThresholds()[2].getRangeType());
         assertEquals(null, clrFmt.getThresholds()[0].getValue());
-        assertEquals(10d,  clrFmt.getThresholds()[1].getValue());
+        assertEquals(10d,  clrFmt.getThresholds()[1].getValue(), 0);
         assertEquals(null, clrFmt.getThresholds()[2].getValue());
+        
+        wb2.close();
     }
     
-    public void testCreateDataBarFormatting() {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet();
+    @Test
+    public void testCreateDataBarFormatting() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         String colorHex = "FFFFEB84";
-        ExtendedColor color = workbook.getCreationHelper().createExtendedColor();
+        ExtendedColor color = wb1.getCreationHelper().createExtendedColor();
         color.setARGBHex(colorHex);
         SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
         ConditionalFormattingRule rule1 = 
@@ -1162,7 +1215,9 @@ public abstract class BaseTestConditiona
         sheetCF.addConditionalFormatting(regions, rule1);
         
         // Save, re-load and re-check
-        workbook = _testDataProvider.writeOutAndReadBack(workbook);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         sheetCF = sheet.getSheetConditionalFormatting();
         assertEquals(1, sheetCF.getNumConditionalFormattings());
         
@@ -1182,15 +1237,19 @@ public abstract class BaseTestConditiona
         assertEquals(RangeType.MAX, dbFmt.getMaxThreshold().getRangeType());
         assertEquals(null, dbFmt.getMinThreshold().getValue());
         assertEquals(null, dbFmt.getMaxThreshold().getValue());
+        
+        wb2.close();
     }
     
-    public void testBug55380() {
+    @Test
+    public void testBug55380() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         CellRangeAddress[] ranges = new CellRangeAddress[] {
             CellRangeAddress.valueOf("C9:D30"), CellRangeAddress.valueOf("C7:C31")
         };
         ConditionalFormattingRule rule = sheet.getSheetConditionalFormatting().createConditionalFormattingRule("$A$1>0");
-        sheet.getSheetConditionalFormatting().addConditionalFormatting(ranges, rule);        
+        sheet.getSheetConditionalFormatting().addConditionalFormatting(ranges, rule);
+        wb.close();
     }
-}
+}
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java?rev=1706742&r1=1706741&r2=1706742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java Mon Oct  5 00:28:54 2015
@@ -17,17 +17,21 @@
 
 package org.apache.poi.ss.usermodel;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
 
 import org.apache.poi.ss.ITestDataProvider;
+import org.junit.Test;
 
 /**
  * Common superclass for testing implementatiosn of{@link FormulaEvaluator}
  *
  * @author Yegor Kozlov
  */
-public abstract class BaseTestFormulaEvaluator extends TestCase {
+public abstract class BaseTestFormulaEvaluator {
 
 	protected final ITestDataProvider _testDataProvider;
 
@@ -38,7 +42,8 @@ public abstract class BaseTestFormulaEva
 		_testDataProvider = testDataProvider;
 	}
 
-    public void testSimpleArithmetic() {
+	@Test
+    public void testSimpleArithmetic() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet s = wb.createSheet();
         Row r = s.createRow(0);
@@ -58,9 +63,12 @@ public abstract class BaseTestFormulaEva
 
         assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
         assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
+        
+        wb.close();
     }
 
-    public void testSumCount() {
+	@Test
+	public void testSumCount() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet s = wb.createSheet();
         Row r = s.createRow(0);
@@ -100,9 +108,11 @@ public abstract class BaseTestFormulaEva
         assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
         assertEquals(1, c3.getNumericCellValue(), 0.0001);
         assertEquals(4, c4.getNumericCellValue(), 0.0001);
+        
+        wb.close();
     }
 
-    public void baseTestSharedFormulas(String sampleFile){
+	public void baseTestSharedFormulas(String sampleFile) throws IOException {
         Workbook wb = _testDataProvider.openSampleWorkbook(sampleFile);
 
         Sheet sheet = wb.getSheetAt(0);
@@ -125,12 +135,15 @@ public abstract class BaseTestFormulaEva
         cell = sheet.getRow(4).getCell(0);
         assertEquals("B5", cell.getCellFormula());
         assertEquals("UniqueDocumentNumberID", evaluator.evaluate(cell).getStringValue());
+        
+        wb.close();
     }
 
     /**
      * Test creation / evaluation of formulas with sheet-level names
      */
-    public void testSheetLevelFormulas(){
+	@Test
+    public void testSheetLevelFormulas() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
 
         Row row;
@@ -161,9 +174,12 @@ public abstract class BaseTestFormulaEva
 
         assertEquals(5.0, evaluator.evaluate(sh2.getRow(0).getCell(1)).getNumberValue(), 0.0);
         assertEquals(15.0, evaluator.evaluate(sh2.getRow(0).getCell(2)).getNumberValue(), 0.0);
+        
+        wb.close();
     }
 
-    public void testFullColumnRefs() {
+	@Test
+    public void testFullColumnRefs() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet("Sheet1");
         Row row = sheet.createRow(0);
@@ -192,9 +208,12 @@ public abstract class BaseTestFormulaEva
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
         assertEquals(26.0, fe.evaluate(cell0).getNumberValue(), 0.0);
         assertEquals(56.0, fe.evaluate(cell1).getNumberValue(), 0.0);
+        
+        wb.close();
     }
     
-    public void testRepeatedEvaluation() {
+	@Test
+    public void testRepeatedEvaluation() throws IOException {
        Workbook wb = _testDataProvider.createWorkbook();
        FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
        Sheet sheet = wb.createSheet("Sheet1");
@@ -230,6 +249,8 @@ public abstract class BaseTestFormulaEva
        fe.clearAllCachedResultValues();
        cellValue = fe.evaluate(c);
        assertEquals(40455.0, cellValue.getNumberValue(), 0.0);
+       
+       wb.close();
     }
 
     private static void setValue(Sheet sheet, int rowIndex, int colIndex, double value) {
@@ -244,19 +265,22 @@ public abstract class BaseTestFormulaEva
      * {@link FormulaEvaluator#evaluate(org.apache.poi.ss.usermodel.Cell)} should behave the same whether the cell
      * is <code>null</code> or blank.
      */
-    public void testEvaluateBlank() {
+    @Test
+    public void testEvaluateBlank() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
         assertNull(fe.evaluate(null));
         Sheet sheet = wb.createSheet("Sheet1");
         Cell cell = sheet.createRow(0).createCell(0);
         assertNull(fe.evaluate(cell));
+        wb.close();
     }
 
     /**
      * Test for bug due to attempt to convert a cached formula error result to a boolean
      */
-    public void testUpdateCachedFormulaResultFromErrorToNumber_bug46479() {
+    @Test
+    public void testUpdateCachedFormulaResultFromErrorToNumber_bug46479() throws IOException {
 
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet("Sheet1");
@@ -275,14 +299,16 @@ public abstract class BaseTestFormulaEva
             fe.evaluateInCell(cellB1);
         } catch (IllegalStateException e) {
             if (e.getMessage().equals("Cannot get a numeric value from a error formula cell")) {
-                throw new AssertionFailedError("Identified bug 46479a");
+                fail("Identified bug 46479a");
             }
         }
         assertEquals(3.5, cellB1.getNumericCellValue(), 0.0);
+        
+        wb.close();
     }
 
-
-    public void testRounding_bug51339() {
+    @Test
+    public void testRounding_bug51339() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet("Sheet1");
         Row row = sheet.createRow(0);
@@ -299,5 +325,7 @@ public abstract class BaseTestFormulaEva
         assertEquals(2162.62, fe.evaluateInCell(cellB1).getNumericCellValue(), 0.0);
         assertEquals(2162.62, fe.evaluateInCell(cellC1).getNumericCellValue(), 0.0);
         assertEquals(2162.61, fe.evaluateInCell(cellD1).getNumericCellValue(), 0.0);
+        
+        wb.close();
     }
 }
\ No newline at end of file

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1706742&r1=1706741&r2=1706742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Mon Oct  5 00:28:54 2015
@@ -49,7 +49,7 @@ public abstract class BaseTestSheet {
     }
 
     @Test
-    public void createRow() {
+    public void createRow() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
         assertEquals(0, sheet.getPhysicalNumberOfRows());
@@ -86,36 +86,38 @@ public abstract class BaseTestSheet {
         Row row2_ovrewritten_ref = it2.next();
         assertSame(row2_ovrewritten, row2_ovrewritten_ref);
         assertEquals(100.0, row2_ovrewritten_ref.getCell(0).getNumericCellValue(), 0.0);
+        
+        workbook.close();
     }
     
-    @Test
-    public void createRowBeforeFirstRow() {
+    @Test(expected=IllegalArgumentException.class)
+    public void createRowBeforeFirstRow() throws IOException {
         final Workbook workbook = _testDataProvider.createWorkbook();
         final Sheet sh = workbook.createSheet();
         sh.createRow(0);
         try {
+            // Negative rows not allowed
             sh.createRow(-1);
-            fail("Negative rows not allowed");
-        } catch (final IllegalArgumentException e) {
-            // expected
+        } finally {
+            workbook.close();
         }
     }
     
-    protected void createRowAfterLastRow(SpreadsheetVersion version) {
+    protected void createRowAfterLastRow(SpreadsheetVersion version) throws IOException {
         final Workbook workbook = _testDataProvider.createWorkbook();
         final Sheet sh = workbook.createSheet();
         sh.createRow(version.getLastRowIndex());
         try {
+            // Row number must be between 0 and last row
             sh.createRow(version.getLastRowIndex() + 1);
-            fail("Row number must be between 0 and " + version.getLastColumnIndex());
-        } catch (final IllegalArgumentException e) {
-            // expected
+        } finally {
+            workbook.close();
         }
     }
 
 
     @Test
-    public void removeRow() {
+    public void removeRow() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet1 = workbook.createSheet();
         assertEquals(0, sheet1.getPhysicalNumberOfRows());
@@ -152,10 +154,12 @@ public abstract class BaseTestSheet {
         thrown.expect(IllegalArgumentException.class);
         thrown.expectMessage("Specified row does not belong to this sheet");
         sheet2.removeRow(row3);
+
+        workbook.close();
     }
 
     @Test
-    public void cloneSheet() {
+    public void cloneSheet() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         CreationHelper factory = workbook.getCreationHelper();
         Sheet sheet = workbook.createSheet("Test Clone");
@@ -182,13 +186,15 @@ public abstract class BaseTestSheet {
         }
         assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
         assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
+        
+        workbook.close();
     }
 
     /** tests that the sheet name for multiple clones of the same sheet is unique
      * BUG 37416
      */
     @Test
-    public void cloneSheetMultipleTimes() {
+    public void cloneSheetMultipleTimes() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         CreationHelper factory = workbook.getCreationHelper();
         Sheet sheet = workbook.createSheet("Test Clone");
@@ -210,16 +216,18 @@ public abstract class BaseTestSheet {
         workbook.createSheet("abc ( 123)");
         workbook.cloneSheet(0);
         assertEquals("abc (124)", workbook.getSheetName(1));
+        
+        workbook.close();
     }
 
     /**
      * Setting landscape and portrait stuff on new sheets
      */
     @Test
-    public void printSetupLandscapeNew() {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheetL = workbook.createSheet("LandscapeS");
-        Sheet sheetP = workbook.createSheet("LandscapeP");
+    public void printSetupLandscapeNew() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheetL = wb1.createSheet("LandscapeS");
+        Sheet sheetP = wb1.createSheet("LandscapeP");
 
         // Check two aspects of the print setup
         assertFalse(sheetL.getPrintSetup().getLandscape());
@@ -238,14 +246,16 @@ public abstract class BaseTestSheet {
         assertEquals(3, sheetP.getPrintSetup().getCopies());
 
         // Save and re-load, and check still there
-        workbook = _testDataProvider.writeOutAndReadBack(workbook);
-        sheetL = workbook.getSheet("LandscapeS");
-        sheetP = workbook.getSheet("LandscapeP");
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheetL = wb2.getSheet("LandscapeS");
+        sheetP = wb2.getSheet("LandscapeP");
 
         assertTrue(sheetL.getPrintSetup().getLandscape());
         assertFalse(sheetP.getPrintSetup().getLandscape());
         assertEquals(1, sheetL.getPrintSetup().getCopies());
         assertEquals(3, sheetP.getPrintSetup().getCopies());
+        wb2.close();
     }
 
     /**
@@ -254,7 +264,7 @@ public abstract class BaseTestSheet {
      *
      */
     @Test
-    public void addMerged() {
+    public void addMerged() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         assertEquals(0, sheet.getNumMergedRegions());
@@ -286,6 +296,8 @@ public abstract class BaseTestSheet {
             assertEquals("Maximum row number is " + ssVersion.getLastRowIndex(), e.getMessage());
         }
         assertEquals(1, sheet.getNumMergedRegions());
+        
+        wb.close();
     }
 
     /**
@@ -293,7 +305,7 @@ public abstract class BaseTestSheet {
      *
      */
     @Test
-    public void removeMerged() {
+    public void removeMerged() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
@@ -325,10 +337,12 @@ public abstract class BaseTestSheet {
         assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
         region = sheet.getMergedRegion(0);
         assertEquals("the merged row to doesnt match the one we put in ", 4, region.getLastRow());
+        
+        wb.close();
     }
 
     @Test
-    public void shiftMerged() {
+    public void shiftMerged() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         CreationHelper factory = wb.getCreationHelper();
         Sheet sheet = wb.createSheet();
@@ -347,16 +361,17 @@ public abstract class BaseTestSheet {
 
         region = sheet.getMergedRegion(0);
         assertEquals("Merged region not moved over to row 2", 2, region.getFirstRow());
+        
+        wb.close();
     }
 
     /**
      * Tests the display of gridlines, formulas, and rowcolheadings.
-     * @author Shawn Laubach (slaubach at apache dot org)
      */
     @Test
-    public void displayOptions() {
-        Workbook wb = _testDataProvider.createWorkbook();
-        Sheet sheet = wb.createSheet();
+    public void displayOptions() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         assertEquals(sheet.isDisplayGridlines(), true);
         assertEquals(sheet.isDisplayRowColHeadings(), true);
@@ -368,19 +383,22 @@ public abstract class BaseTestSheet {
         sheet.setDisplayFormulas(true);
         sheet.setDisplayZeros(false);
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
 
         assertEquals(sheet.isDisplayGridlines(), false);
         assertEquals(sheet.isDisplayRowColHeadings(), false);
         assertEquals(sheet.isDisplayFormulas(), true);
         assertEquals(sheet.isDisplayZeros(), false);
+        
+        wb2.close();
     }
 
     @Test
-    public void columnWidth() {
-        Workbook wb = _testDataProvider.createWorkbook();
-        Sheet sheet = wb.createSheet();
+    public void columnWidth() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet();
 
         //default column width measured in characters
         sheet.setDefaultColumnWidth(10);
@@ -421,9 +439,10 @@ public abstract class BaseTestSheet {
         }
 
         //serialize and read again
-        wb = _testDataProvider.writeOutAndReadBack(wb);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
 
-        sheet = wb.getSheetAt(0);
+        sheet = wb2.getSheetAt(0);
         assertEquals(20, sheet.getDefaultColumnWidth());
         //columns A-C have default width
         assertEquals(256*20, sheet.getColumnWidth(0));
@@ -435,11 +454,13 @@ public abstract class BaseTestSheet {
             assertEquals(w, sheet.getColumnWidth(i));
         }
         assertEquals(40000, sheet.getColumnWidth(10));
+        
+        wb2.close();
     }
 
     
     @Test
-    public void defaultRowHeight() {
+    public void defaultRowHeight() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
         sheet.setDefaultRowHeightInPoints(15);
@@ -464,11 +485,13 @@ public abstract class BaseTestSheet {
         sheet.setDefaultRowHeightInPoints(17.5f);
         assertEquals(17.5f, sheet.getDefaultRowHeightInPoints(), 0F);
         assertEquals((short)(17.5f*20), sheet.getDefaultRowHeight());
+        
+        workbook.close();
     }
 
     /** cell with formula becomes null on cloning a sheet*/
     @Test
-    public void bug35084() {
+    public void bug35084() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet s = wb.createSheet("Sheet1");
         Row r = s.createRow(0);
@@ -479,11 +502,12 @@ public abstract class BaseTestSheet {
         assertEquals("double", r.getCell(0).getNumericCellValue(), 1, 0); // sanity check
         assertNotNull(r.getCell(1));
         assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2");
+        wb.close();
     }
 
     /** test that new default column styles get applied */
     @Test
-    public void defaultColumnStyle() {
+    public void defaultColumnStyle() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         CellStyle style = wb.createCellStyle();
         Sheet sheet = wb.createSheet();
@@ -496,13 +520,14 @@ public abstract class BaseTestSheet {
         CellStyle style2 = cell.getCellStyle();
         assertNotNull(style2);
         assertEquals("style should match", style.getIndex(), style2.getIndex());
+        wb.close();
     }
 
     @Test
-    public void outlineProperties() {
-        Workbook wb = _testDataProvider.createWorkbook();
+    public void outlineProperties() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
 
-        Sheet sheet = wb.createSheet();
+        Sheet sheet = wb1.createSheet();
 
         //TODO defaults are different in HSSF and XSSF
         //assertTrue(sheet.getRowSumsBelow());
@@ -520,17 +545,19 @@ public abstract class BaseTestSheet {
         assertTrue(sheet.getRowSumsBelow());
         assertTrue(sheet.getRowSumsRight());
 
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         assertTrue(sheet.getRowSumsBelow());
         assertTrue(sheet.getRowSumsRight());
+        wb2.close();
     }
 
     /**
      * Test basic display properties
      */
     @Test
-    public void sheetProperties() {
+    public void sheetProperties() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -580,9 +607,11 @@ public abstract class BaseTestSheet {
         assertTrue(sheet.getFitToPage());
         sheet.setFitToPage(false);
         assertFalse(sheet.getFitToPage());
+        
+        wb.close();
     }
 
-    public void baseTestGetSetMargin(double[] defaultMargins) {
+    public void baseTestGetSetMargin(double[] defaultMargins) throws IOException {
         double marginLeft = defaultMargins[0];
         double marginRight = defaultMargins[1];
         double marginTop = defaultMargins[2];
@@ -615,10 +644,12 @@ public abstract class BaseTestSheet {
         thrown.expect(IllegalArgumentException.class);
         thrown.expectMessage("Unknown margin constant:  65");
         sheet.setMargin((short) 65, 15);
+        
+        workbook.close();
     }
 
     @Test
-    public void rowBreaks() {
+    public void rowBreaks() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
         //Sheet#getRowBreaks() returns an empty array if no row breaks are defined
@@ -644,10 +675,12 @@ public abstract class BaseTestSheet {
 
         assertFalse(sheet.isRowBroken(1));
         assertFalse(sheet.isRowBroken(15));
+        
+        workbook.close();
     }
 
     @Test
-    public void columnBreaks() {
+    public void columnBreaks() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet();
         assertNotNull(sheet.getColumnBreaks());
@@ -672,10 +705,11 @@ public abstract class BaseTestSheet {
 
         assertFalse(sheet.isColumnBroken(11));
         assertFalse(sheet.isColumnBroken(12));
+        workbook.close();
     }
 
     @Test
-    public void getFirstLastRowNum() {
+    public void getFirstLastRowNum() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         sheet.createRow(9);
@@ -683,27 +717,30 @@ public abstract class BaseTestSheet {
         sheet.createRow(1);
         assertEquals(0, sheet.getFirstRowNum());
         assertEquals(9, sheet.getLastRowNum());
+        workbook.close();
     }
 
     @Test
-    public void getFooter() {
+    public void getFooter() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         assertNotNull(sheet.getFooter());
         sheet.getFooter().setCenter("test center footer");
         assertEquals("test center footer", sheet.getFooter().getCenter());
+        workbook.close();
     }
 
     @Test
-    public void getSetColumnHidden() {
+    public void getSetColumnHidden() throws IOException {
         Workbook workbook = _testDataProvider.createWorkbook();
         Sheet sheet = workbook.createSheet("Sheet 1");
         sheet.setColumnHidden(2, true);
         assertTrue(sheet.isColumnHidden(2));
+        workbook.close();
     }
 
     @Test
-    public void protectSheet() {
+    public void protectSheet() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         assertFalse(sheet.getProtect());
@@ -711,11 +748,11 @@ public abstract class BaseTestSheet {
         assertTrue(sheet.getProtect());
         sheet.protectSheet(null);
         assertFalse(sheet.getProtect());
-
+        wb.close();
     }
 
     @Test
-    public void createFreezePane() {
+    public void createFreezePane() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         // create a workbook
         Sheet sheet = wb.createSheet();
@@ -762,11 +799,13 @@ public abstract class BaseTestSheet {
         sheet.createFreezePane(0, 0);
         // If both colSplit and rowSplit are zero then the existing freeze pane is removed
         assertNull(sheet.getPaneInformation());
+        
+        wb.close();
     }
 
     
     @Test
-    public void getRepeatingRowsAndColumns() {
+    public void getRepeatingRowsAndColumns() throws IOException {
         Workbook wb = _testDataProvider.openSampleWorkbook(
             "RepeatingRowsCols." 
             + _testDataProvider.getStandardFileNameExtension());
@@ -775,11 +814,12 @@ public abstract class BaseTestSheet {
         checkRepeatingRowsAndColumns(wb.getSheetAt(1), "1:1", null);
         checkRepeatingRowsAndColumns(wb.getSheetAt(2), null, "A:A");
         checkRepeatingRowsAndColumns(wb.getSheetAt(3), "2:3", "A:B");
+        wb.close();
     }
 
 
     @Test
-    public void setRepeatingRowsAndColumnsBug47294(){
+    public void setRepeatingRowsAndColumnsBug47294() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet1 = wb.createSheet();
         sheet1.setRepeatingRows(CellRangeAddress.valueOf("1:4"));
@@ -789,14 +829,15 @@ public abstract class BaseTestSheet {
         Sheet sheet2 = wb.createSheet("My' Sheet");
         sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:4"));
         assertEquals("1:4", sheet2.getRepeatingRows().formatAsString());
+        wb.close();
     }
 
     @Test
-    public void setRepeatingRowsAndColumns() {
-        Workbook wb = _testDataProvider.createWorkbook();
-        Sheet sheet1 = wb.createSheet("Sheet1");
-        Sheet sheet2 = wb.createSheet("Sheet2");
-        Sheet sheet3 = wb.createSheet("Sheet3");
+    public void setRepeatingRowsAndColumns() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet1 = wb1.createSheet("Sheet1");
+        Sheet sheet2 = wb1.createSheet("Sheet2");
+        Sheet sheet3 = wb1.createSheet("Sheet3");
         
         checkRepeatingRowsAndColumns(sheet1, null, null);
         
@@ -810,10 +851,11 @@ public abstract class BaseTestSheet {
         checkRepeatingRowsAndColumns(sheet3, "1:4", "A:A");
         
         // write out, read back, and test refrain...
-        wb = _testDataProvider.writeOutAndReadBack(wb);
-        sheet1 = wb.getSheetAt(0);
-        sheet2 = wb.getSheetAt(1);
-        sheet3 = wb.getSheetAt(2);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet1 = wb2.getSheetAt(0);
+        sheet2 = wb2.getSheetAt(1);
+        sheet3 = wb2.getSheetAt(2);
         
         checkRepeatingRowsAndColumns(sheet1, "4:5", null);
         checkRepeatingRowsAndColumns(sheet2, null, "A:C");
@@ -825,6 +867,7 @@ public abstract class BaseTestSheet {
         
         sheet3.setRepeatingColumns(null);
         checkRepeatingRowsAndColumns(sheet3, null, null);
+        wb2.close();
     }
 
     private void checkRepeatingRowsAndColumns(
@@ -842,23 +885,25 @@ public abstract class BaseTestSheet {
     }
 
     @Test
-    public void baseZoom() {
+    public void baseZoom() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         
         // here we can only verify that setting some zoom values works, range-checking is different between the implementations
         sheet.setZoom(3,4);
+        wb.close();
     }
     
     @Test
-    public void baseShowInPane() {
+    public void baseShowInPane() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
         sheet.showInPane(2, 3);
+        wb.close();
     }
 
     @Test
-    public void bug55723(){
+    public void bug55723() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -871,6 +916,7 @@ public abstract class BaseTestSheet {
         filter = sheet.setAutoFilter(range);
         assertNotNull(filter);
         // there seems to be currently no generic way to check the setting...
+        wb.close();
     }
 
     @Test
@@ -956,9 +1002,9 @@ public abstract class BaseTestSheet {
     }
 
     @Test
-    public void showInPaneManyRowsBug55248() {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
+    public void showInPaneManyRowsBug55248() throws IOException {
+        Workbook wb1 = _testDataProvider.createWorkbook();
+        Sheet sheet = wb1.createSheet("Sheet 1");
 
         sheet.showInPane(0, 0);
 
@@ -971,8 +1017,11 @@ public abstract class BaseTestSheet {
         int i = 0;
         sheet.showInPane(i, i);
 
-        Workbook wb = _testDataProvider.writeOutAndReadBack(workbook);
-        checkRowCount(wb);
+        Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
+        checkRowCount(wb2);
+        
+        wb2.close();
+        wb1.close();
     }
 
     private void checkRowCount(Workbook wb) {



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


Mime
View raw message