poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1797043 [2/2] - in /poi/trunk/src: ooxml/testcases/org/apache/poi/xslf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/ scratchpad/src/org/apache/poi/extractor/ scratchpad/src...
Date Wed, 31 May 2017 14:10:18 GMT
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java?rev=1797043&r1=1797042&r2=1797043&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
Wed May 31 14:10:18 2017
@@ -17,138 +17,117 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
-import junit.framework.TestCase;
+import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.junit.Test;
 
 /**
  * Tests for how HSSFWorkbook behaves with XLS files
  *  with a WORKBOOK or BOOK directory entry (instead of 
  *  the more usual, Workbook)
  */
-public final class TestNonStandardWorkbookStreamNames extends TestCase {
+public final class TestNonStandardWorkbookStreamNames {
 	private final String xlsA = "WORKBOOK_in_capitals.xls";
-   private final String xlsB = "BOOK_in_capitals.xls";
+    private final String xlsB = "BOOK_in_capitals.xls";
 
 	/**
 	 * Test that we can open a file with WORKBOOK
 	 */
-	public void testOpenWORKBOOK() throws Exception {
+    @Test
+	public void testOpenWORKBOOK() throws IOException {
+        // Try to open the workbook
 		InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
-		
-		POIFSFileSystem fs = new POIFSFileSystem(is);
-
-		// Ensure that we have a WORKBOOK entry
-		fs.getRoot().getEntry("WORKBOOK");
-		// And a summary
-		fs.getRoot().getEntry("\005SummaryInformation");
-		assertTrue(true);
+		HSSFWorkbook wb = new HSSFWorkbook(is);
+		is.close();
+		DirectoryNode root = wb.getDirectory();
+
+		// Ensure that we have a WORKBOOK entry and a summary
+		assertTrue(root.hasEntry("WORKBOOK"));
+		assertTrue(root.hasEntry("\005SummaryInformation"));
 
 		// But not a Workbook one
-		try {
-			fs.getRoot().getEntry("Workbook");
-			fail();
-		} catch(FileNotFoundException e) {}
+		assertFalse(root.hasEntry("Workbook"));
 		
-		// Try to open the workbook
-		HSSFWorkbook wb = new HSSFWorkbook(fs);
+		wb.close();
 	}
 
    /**
     * Test that we can open a file with BOOK
     */
-   public void testOpenBOOK() throws Exception {
+   @Test
+   public void testOpenBOOK() throws IOException {
+       // Try to open the workbook
       InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsB);
-      
-      POIFSFileSystem fs = new POIFSFileSystem(is);
+      HSSFWorkbook wb = new HSSFWorkbook(is);
+      is.close();
+      DirectoryNode root = wb.getDirectory();
 
       // Ensure that we have a BOOK entry
-      fs.getRoot().getEntry("BOOK");
-      assertTrue(true);
+      assertTrue(root.hasEntry("BOOK"));
 
-      // But not a Workbook one
-      try {
-         fs.getRoot().getEntry("Workbook");
-         fail();
-      } catch(FileNotFoundException e) {}
-      // And not a Summary one
-      try {
-         fs.getRoot().getEntry("\005SummaryInformation");
-         fail();
-      } catch(FileNotFoundException e) {}
+      // But not a Workbook one and not a Summary one
+      assertFalse(root.hasEntry("Workbook"));
+      assertFalse(root.hasEntry("\\005SummaryInformation"));
       
-      // Try to open the workbook
-      HSSFWorkbook wb = new HSSFWorkbook(fs);
+      wb.close();
    }
 
 	/**
 	 * Test that when we write out, we go back to the correct case
 	 */
-	public void testWrite() throws Exception {
+    @Test
+	public void testWrite() throws IOException {
 	   for (String file : new String[] {xlsA, xlsB}) {
-   		InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
-   		POIFSFileSystem fs = new POIFSFileSystem(is);
-   
-   		// Open the workbook, not preserving nodes
-   		HSSFWorkbook wb = new HSSFWorkbook(fs);
-   		ByteArrayOutputStream out = new ByteArrayOutputStream();
-   		wb.write(out);
-   
-   		// Check now
-   		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-   		POIFSFileSystem fs2 = new POIFSFileSystem(in);
-   
-   		// Check that we have the new entries
-   		fs2.getRoot().getEntry("Workbook");
-   		try {
-   			fs2.getRoot().getEntry("BOOK");
-   			fail();
-   		} catch(FileNotFoundException e) {}
-         try {
-            fs2.getRoot().getEntry("WORKBOOK");
-            fail();
-         } catch(FileNotFoundException e) {}
-   
-   		// And it can be opened
-   		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
-	   }
+           // Open the workbook, not preserving nodes
+	       InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
+	       HSSFWorkbook wb = new HSSFWorkbook(is, false);
+           is.close();
+
+           // Check now it can be opened
+           HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
+           wb.close();
+           
+           DirectoryNode root = wb2.getDirectory();
+       
+           // Check that we have the new entries
+           assertTrue(root.hasEntry("Workbook"));
+           assertFalse(root.hasEntry("BOOK"));
+           assertFalse(root.hasEntry("WORKBOOK"));
+
+           wb2.close();
+       }
 	}
 
 	/**
 	 * Test that when we write out preserving nodes, we go back to the
 	 *  correct case
 	 */
-	public void testWritePreserve() throws Exception {
+    @Test
+	public void testWritePreserve() throws IOException {
+        // Open the workbook, not preserving nodes
 		InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
-		POIFSFileSystem fs = new POIFSFileSystem(is);
-
-		// Open the workbook, not preserving nodes
-		HSSFWorkbook wb = new HSSFWorkbook(fs,true);
-
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		wb.write(out);
-
-		// Check now
-		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-		POIFSFileSystem fs2 = new POIFSFileSystem(in);
-
-		// Check that we have the new entries
-		fs2.getRoot().getEntry("Workbook");
-		try {
-			fs2.getRoot().getEntry("WORKBOOK");
-			fail();
-		} catch(FileNotFoundException e) {}
-
-		// As we preserved, should also have a few other streams
-		fs2.getRoot().getEntry("\005SummaryInformation");
-
-		// And it can be opened
-		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
+        HSSFWorkbook wb = new HSSFWorkbook(is,true);
+        is.close();
+        
+        // Check now it can be opened
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        wb.close();
+
+        DirectoryNode root = wb2.getDirectory();
+
+        // Check that we have the new entries
+        assertTrue(root.hasEntry("Workbook"));
+        assertFalse(root.hasEntry("BOOK"));
+        assertFalse(root.hasEntry("WORKBOOK"));
+
+        // As we preserved, should also have a few other streams
+        assertTrue(root.hasEntry("\005SummaryInformation"));
+        wb2.close();
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java?rev=1797043&r1=1797042&r2=1797043&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java Wed May 31 14:10:18
2017
@@ -17,23 +17,25 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
 import org.apache.poi.POITestCase;
 import org.apache.poi.ddf.EscherContainerRecord;
 import org.apache.poi.ddf.EscherSpgrRecord;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.EscherAggregate;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-/**
- * @author Evgeniy Berlog
- * @date 29.06.12
- */
-public class TestShapeGroup extends TestCase{
+public class TestShapeGroup {
 
-    public void testSetGetCoordinates(){
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sh = wb.createSheet();
+    @Test
+    public void testSetGetCoordinates() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet sh = wb1.createSheet();
         HSSFPatriarch patriarch = sh.createDrawingPatriarch();
         HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
         assertEquals(group.getX1(), 0);
@@ -48,8 +50,9 @@ public class TestShapeGroup extends Test
         assertEquals(group.getX2(), 3);
         assertEquals(group.getY2(), 4);
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sh = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sh = wb2.getSheetAt(0);
         patriarch = sh.getDrawingPatriarch();
 
         group = (HSSFShapeGroup) patriarch.getChildren().get(0);
@@ -57,11 +60,13 @@ public class TestShapeGroup extends Test
         assertEquals(group.getY1(), 2);
         assertEquals(group.getX2(), 3);
         assertEquals(group.getY2(), 4);
+        wb2.close();
     }
 
-    public void testAddToExistingFile(){
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sh = wb.createSheet();
+    @Test
+    public void testAddToExistingFile() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet sh = wb1.createSheet();
         HSSFPatriarch patriarch = sh.createDrawingPatriarch();
         HSSFShapeGroup group1 = patriarch.createGroup(new HSSFClientAnchor());
         HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
@@ -69,8 +74,9 @@ public class TestShapeGroup extends Test
         group1.setCoordinates(1,2,3,4);
         group2.setCoordinates(5,6,7,8);
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sh = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sh = wb2.getSheetAt(0);
         patriarch = sh.getDrawingPatriarch();
 
         assertEquals(patriarch.getChildren().size(), 2);
@@ -78,18 +84,21 @@ public class TestShapeGroup extends Test
         HSSFShapeGroup group3 = patriarch.createGroup(new HSSFClientAnchor());
         group3.setCoordinates(9,10,11,12);
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sh = wb.getSheetAt(0);
+        HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+        wb2.close();
+        sh = wb3.getSheetAt(0);
         patriarch = sh.getDrawingPatriarch();
 
         assertEquals(patriarch.getChildren().size(), 3);
+        wb3.close();
     }
 
-    public void testModify() throws Exception {
-        HSSFWorkbook wb = new HSSFWorkbook();
+    @Test
+    public void testModify() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
 
         // create a sheet with a text box
-        HSSFSheet sheet = wb.createSheet();
+        HSSFSheet sheet = wb1.createSheet();
         HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
 
         HSSFShapeGroup group1 = patriarch.createGroup(new
@@ -103,8 +112,9 @@ public class TestShapeGroup extends Test
         textbox1.setString(rt1);
 
         // write, read back and check that our text box is there
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
         assertEquals(1, patriarch.getChildren().size());
 
@@ -128,8 +138,9 @@ public class TestShapeGroup extends Test
         textbox2.setString(rt2);
         assertEquals(2, group1.getChildren().size());
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+        wb2.close();
+        sheet = wb3.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
         assertEquals(1, patriarch.getChildren().size());
 
@@ -146,8 +157,9 @@ public class TestShapeGroup extends Test
         assertEquals(new HSSFChildAnchor(400, 400, 600, 600),
                 textbox2.getAnchor());
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3);
+        wb3.close();
+        sheet = wb4.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
         group1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
         textbox1 = (HSSFTextbox)group1.getChildren().get(0);
@@ -156,25 +168,28 @@ public class TestShapeGroup extends Test
                 HSSFChildAnchor(400,200, 600, 400));
         HSSFRichTextString rt3 = new HSSFRichTextString("Hello, World-3");
         textbox3.setString(rt3);
+        wb4.close();
     }
 
-    public void testAddShapesToGroup(){
-        HSSFWorkbook wb = new HSSFWorkbook();
+    @Test
+    public void testAddShapesToGroup() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
 
         // create a sheet with a text box
-        HSSFSheet sheet = wb.createSheet();
+        HSSFSheet sheet = wb1.createSheet();
         HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
 
         HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
-        int index = wb.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_JPEG);
+        int index = wb1.addPicture(new byte[]{1,2,3}, HSSFWorkbook.PICTURE_TYPE_JPEG);
         group.createPicture(new HSSFChildAnchor(), index);
         HSSFPolygon polygon = group.createPolygon(new HSSFChildAnchor());
         polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
         group.createTextbox(new HSSFChildAnchor());
         group.createShape(new HSSFChildAnchor());
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
         assertEquals(1, patriarch.getChildren().size());
 
@@ -190,7 +205,7 @@ public class TestShapeGroup extends Test
 
         HSSFShapeGroup group2 = patriarch.createGroup(new HSSFClientAnchor());
 
-        index = wb.addPicture(new byte[]{2,2,2}, HSSFWorkbook.PICTURE_TYPE_JPEG);
+        index = wb2.addPicture(new byte[]{2,2,2}, HSSFWorkbook.PICTURE_TYPE_JPEG);
         group2.createPicture(new HSSFChildAnchor(), index);
         polygon = group2.createPolygon(new HSSFChildAnchor());
         polygon.setPoints(new int[]{1,100, 1}, new int[]{1, 50, 100});
@@ -198,8 +213,9 @@ public class TestShapeGroup extends Test
         group2.createShape(new HSSFChildAnchor());
         group2.createShape(new HSSFChildAnchor());
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+        wb2.close();
+        sheet = wb3.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
         assertEquals(2, patriarch.getChildren().size());
 
@@ -214,9 +230,11 @@ public class TestShapeGroup extends Test
         assertTrue(group.getChildren().get(4) instanceof HSSFSimpleShape);
 
         group.getShapeId();
+        wb3.close();
     }
 
-    public void testSpgrRecord(){
+    @Test
+    public void testSpgrRecord() throws IOException {
         HSSFWorkbook wb = new HSSFWorkbook();
 
         // create a sheet with a text box
@@ -225,15 +243,17 @@ public class TestShapeGroup extends Test
 
         HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
         assertSame(((EscherContainerRecord)group.getEscherContainer().getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID),
getSpgrRecord(group));
+        wb.close();
     }
 
     private static EscherSpgrRecord getSpgrRecord(HSSFShapeGroup group) {
         return POITestCase.getFieldValue(HSSFShapeGroup.class, group, EscherSpgrRecord.class,
"_spgrRecord");
     }
 
-    public void testClearShapes(){
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet();
+    @Test
+    public void testClearShapes() throws IOException {
+        HSSFWorkbook wb1 = new HSSFWorkbook();
+        HSSFSheet sheet = wb1.createSheet();
         HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
         HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
 
@@ -252,8 +272,9 @@ public class TestShapeGroup extends Test
         assertEquals(agg.getTailRecords().size(), 0);
         assertEquals(group.getChildren().size(), 0);
 
-        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
-        sheet = wb.getSheetAt(0);
+        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+        sheet = wb2.getSheetAt(0);
         patriarch = sheet.getDrawingPatriarch();
 
         group = (HSSFShapeGroup) patriarch.getChildren().get(0);
@@ -261,5 +282,6 @@ public class TestShapeGroup extends Test
         assertEquals(agg.getShapeToObjMapping().size(), 1);
         assertEquals(agg.getTailRecords().size(), 0);
         assertEquals(group.getChildren().size(), 0);
+        wb2.close();
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java?rev=1797043&r1=1797042&r2=1797043&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSubtotal.java Wed May
31 14:10:18 2017
@@ -17,21 +17,32 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.FormulaParseException;
-import org.apache.poi.ss.formula.eval.*;
-
-import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.formula.eval.AreaEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.NotImplementedException;
+import org.apache.poi.ss.formula.eval.NumberEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.FormulaError;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.junit.Test;
 
 /**
  * Tests for {@link Subtotal}
- *
- * @author Paul Tomlin
  */
-public final class TestSubtotal extends TestCase {
+public final class TestSubtotal {
 	private static final int FUNCTION_AVERAGE = 1;
 	private static final int FUNCTION_COUNT = 2;
 	private static final int FUNCTION_MAX = 4;
@@ -63,6 +74,7 @@ public final class TestSubtotal extends
 		assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
 	}
 
+	@Test
 	public void testBasics() {
 		confirmSubtotal(FUNCTION_SUM, 55.0);
 		confirmSubtotal(FUNCTION_AVERAGE, 5.5);
@@ -73,7 +85,8 @@ public final class TestSubtotal extends
 		confirmSubtotal(FUNCTION_STDEV, 3.0276503540974917);
 	}
 
-     public void testAvg(){
+    @Test
+     public void testAvg() throws IOException {
         Workbook wb = new HSSFWorkbook();
 
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
@@ -98,13 +111,16 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(2.0, a3.getNumericCellValue());
-        assertEquals(8.0, a6.getNumericCellValue());
-        assertEquals(3.0, a7.getNumericCellValue());
-        assertEquals(3.0, a8.getNumericCellValue());
+        assertEquals(2.0, a3.getNumericCellValue(), 0);
+        assertEquals(8.0, a6.getNumericCellValue(), 0);
+        assertEquals(3.0, a7.getNumericCellValue(), 0);
+        assertEquals(3.0, a8.getNumericCellValue(), 0);
+        wb.close();
+
     }
 
-    public void testSum(){
+    @Test
+    public void testSum() throws IOException {
         Workbook wb = new HSSFWorkbook();
 
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
@@ -129,13 +145,15 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(4.0, a3.getNumericCellValue());
-        assertEquals(26.0, a6.getNumericCellValue());
-        assertEquals(12.0, a7.getNumericCellValue());
-        assertEquals(12.0, a8.getNumericCellValue());
+        assertEquals(4.0, a3.getNumericCellValue(), 0);
+        assertEquals(26.0, a6.getNumericCellValue(), 0);
+        assertEquals(12.0, a7.getNumericCellValue(), 0);
+        assertEquals(12.0, a8.getNumericCellValue(), 0);
+        wb.close();
     }
 
-    public void testCount(){
+    @Test
+    public void testCount() throws IOException {
 
         Workbook wb = new HSSFWorkbook();
 
@@ -161,13 +179,15 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(2.0, a3.getNumericCellValue());
-        assertEquals(6.0, a6.getNumericCellValue());
-        assertEquals(2.0, a7.getNumericCellValue());
-        assertEquals(2.0, a8.getNumericCellValue());
+        assertEquals(2.0, a3.getNumericCellValue(), 0);
+        assertEquals(6.0, a6.getNumericCellValue(), 0);
+        assertEquals(2.0, a7.getNumericCellValue(), 0);
+        assertEquals(2.0, a8.getNumericCellValue(), 0);
+        wb.close();
     }
 
-    public void testCounta(){
+    @Test
+    public void testCounta() throws IOException {
 
         Workbook wb = new HSSFWorkbook();
 
@@ -193,13 +213,15 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(2.0, a3.getNumericCellValue());
-        assertEquals(8.0, a6.getNumericCellValue());
-        assertEquals(3.0, a7.getNumericCellValue());
-        assertEquals(3.0, a8.getNumericCellValue());
+        assertEquals(2.0, a3.getNumericCellValue(), 0);
+        assertEquals(8.0, a6.getNumericCellValue(), 0);
+        assertEquals(3.0, a7.getNumericCellValue(), 0);
+        assertEquals(3.0, a8.getNumericCellValue(), 0);
+        wb.close();
     }
 
-    public void testMax(){
+    @Test
+    public void testMax() throws IOException {
 
         Workbook wb = new HSSFWorkbook();
 
@@ -225,13 +247,15 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(3.0, a3.getNumericCellValue());
-        assertEquals(16.0, a6.getNumericCellValue());
-        assertEquals(7.0, a7.getNumericCellValue());
-        assertEquals(7.0, a8.getNumericCellValue());
+        assertEquals(3.0, a3.getNumericCellValue(), 0);
+        assertEquals(16.0, a6.getNumericCellValue(), 0);
+        assertEquals(7.0, a7.getNumericCellValue(), 0);
+        assertEquals(7.0, a8.getNumericCellValue(), 0);
+        wb.close();
     }
 
-    public void testMin(){
+    @Test
+    public void testMin() throws IOException {
 
         Workbook wb = new HSSFWorkbook();
 
@@ -257,13 +281,15 @@ public final class TestSubtotal extends
 
         fe.evaluateAll();
 
-        assertEquals(1.0, a3.getNumericCellValue());
-        assertEquals(4.0, a6.getNumericCellValue());
-        assertEquals(1.0, a7.getNumericCellValue());
-        assertEquals(1.0, a8.getNumericCellValue());
+        assertEquals(1.0, a3.getNumericCellValue(), 0);
+        assertEquals(4.0, a6.getNumericCellValue(), 0);
+        assertEquals(1.0, a7.getNumericCellValue(), 0);
+        assertEquals(1.0, a8.getNumericCellValue(), 0);
+        wb.close();
     }
 
-    public void testStdev(){
+    @Test
+    public void testStdev() throws IOException {
 
         Workbook wb = new HSSFWorkbook();
 
@@ -293,9 +319,11 @@ public final class TestSubtotal extends
         assertEquals(7.65685, a6.getNumericCellValue(), 0.0001);
         assertEquals(2.82842, a7.getNumericCellValue(), 0.0001);
         assertEquals(2.82842, a8.getNumericCellValue(), 0.0001);
+        wb.close();
     }
 
-    public void test50209(){
+    @Test
+    public void test50209() throws IOException {
         Workbook wb = new HSSFWorkbook();
         Sheet sh = wb.createSheet();
         Cell a1 = sh.createRow(1).createCell(1);
@@ -307,8 +335,9 @@ public final class TestSubtotal extends
 
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
         fe.evaluateAll();
-        assertEquals(1.0, a2.getNumericCellValue());
-        assertEquals(1.0, a3.getNumericCellValue());
+        assertEquals(1.0, a2.getNumericCellValue(), 0);
+        assertEquals(1.0, a3.getNumericCellValue(), 0);
+        wb.close();
     }
 
     private static void confirmExpectedResult(FormulaEvaluator evaluator, String msg, Cell
cell, double expected) {
@@ -316,16 +345,17 @@ public final class TestSubtotal extends
         CellValue value = evaluator.evaluate(cell);
         if (value.getErrorValue() != 0)
             throw new RuntimeException(msg + ": " + value.formatAsString());
-        assertEquals(msg, expected, value.getNumberValue());
+        assertEquals(msg, expected, value.getNumberValue(), 0);
     }
 
-    public void testFunctionsFromTestSpreadsheet() {
+    @Test
+    public void testFunctionsFromTestSpreadsheet() throws IOException {
         HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SubtotalsNested.xls");
         HSSFSheet sheet = workbook.getSheetAt(0);
         FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
 
-        assertEquals("B2", 10.0, sheet.getRow(1).getCell(1).getNumericCellValue());
-        assertEquals("B3", 20.0, sheet.getRow(2).getCell(1).getNumericCellValue());
+        assertEquals("B2", 10.0, sheet.getRow(1).getCell(1).getNumericCellValue(), 0);
+        assertEquals("B3", 20.0, sheet.getRow(2).getCell(1).getNumericCellValue(), 0);
 
         //Test simple subtotal over one area
         Cell cellA3 = sheet.getRow(3).getCell(1);
@@ -333,7 +363,7 @@ public final class TestSubtotal extends
 
         //Test existence of the second area
         assertNotNull("C2 must not be null", sheet.getRow(1).getCell(2));
-        assertEquals("C2", 7.0, sheet.getRow(1).getCell(2).getNumericCellValue());
+        assertEquals("C2", 7.0, sheet.getRow(1).getCell(2).getNumericCellValue(), 0);
 
         Cell cellC1 = sheet.getRow(1).getCell(3);
         Cell cellC2 = sheet.getRow(2).getCell(3);
@@ -345,70 +375,48 @@ public final class TestSubtotal extends
         confirmExpectedResult(evaluator, "SUBTOTAL(SUM;B2:B8;C2:C8)", cellC1, 37.0);
         confirmExpectedResult(evaluator, "SUBTOTAL(COUNT;B2:B8,C2:C8)", cellC2, 3.0);
         confirmExpectedResult(evaluator, "SUBTOTAL(COUNTA;B2:B8,C2:C8)", cellC3, 5.0);
+    
+        workbook.close();
     }
 
-    public void testUnimplemented(){
+    @Test
+    public void testUnimplemented() throws IOException {
         Workbook wb = new HSSFWorkbook();
 
         FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
 
         Sheet sh = wb.createSheet();
         Cell a3 = sh.createRow(3).createCell(1);
-        a3.setCellFormula("SUBTOTAL(8,B2:B3)");
-
-        try {
-            fe.evaluateAll();
-            fail("Should catch an NotImplementedFunctionException here, adjust these tests
if it was actually implemented");
-        } catch (NotImplementedException e) {
-            // expected here
-        }
-
-        a3.setCellFormula("SUBTOTAL(10,B2:B3)");
-
-        try {
-            fe.evaluateAll();
-            fail("Should catch an NotImplementedFunctionException here, adjust these tests
if it was actually implemented");
-        } catch (NotImplementedException e) {
-            // expected here
-        }
-
-        a3.setCellFormula("SUBTOTAL(11,B2:B3)");
-
-        try {
-            fe.evaluateAll();
-            fail("Should catch an NotImplementedFunctionException here, adjust these tests
if it was actually implemented");
-        } catch (NotImplementedException e) {
-            // expected here
-        }
-
-        a3.setCellFormula("SUBTOTAL(107,B2:B3)");
-
-        try {
-            fe.evaluateAll();
-            fail("Should catch an NotImplementedFunctionException here, adjust these tests
if it was actually implemented");
-        } catch (NotImplementedException e) {
-            // expected here
-        }
-
-        a3.setCellFormula("SUBTOTAL(0,B2:B3)");
-        fe.evaluateAll();
-        assertEquals(FormulaError.VALUE.getCode(), a3.getErrorCellValue());
-
-        try {
-            a3.setCellFormula("SUBTOTAL(9)");
-            fail("Should catch an exception here");
-        } catch (FormulaParseException e) {
-            // expected here
-        }
-
-        try {
-            a3.setCellFormula("SUBTOTAL()");
-            fail("Should catch an exception here");
-        } catch (FormulaParseException e) {
-            // expected here
+        
+        // formula, throws NotImplemnted?
+        String[][] formulas = {
+            { "SUBTOTAL(8,B2:B3)", NotImplementedException.class.getName() },
+            { "SUBTOTAL(10,B2:B3)", NotImplementedException.class.getName() },
+            { "SUBTOTAL(11,B2:B3)", NotImplementedException.class.getName() },
+            { "SUBTOTAL(107,B2:B3)", NotImplementedException.class.getName() },
+            { "SUBTOTAL(0,B2:B3)", null },
+            { "SUBTOTAL(9)", FormulaParseException.class.getName() },
+            { "SUBTOTAL()", FormulaParseException.class.getName() },
+        };
+        
+        for (String[] f : formulas) {
+            Exception actualEx = null;
+            try {
+                a3.setCellFormula(f[0]);
+                fe.evaluateAll();
+                assertEquals(FormulaError.VALUE.getCode(), a3.getErrorCellValue());
+            } catch (Exception e) {
+                actualEx = e;
+            }
+            String msg =
+                "Check "+(f[1] == null ? "unexpected exception" : f[1])+" here, "+
+                "adjust these tests if it was actually implemented - "+f[0];
+            assertEquals(msg, f[1], (actualEx == null ? null : actualEx.getClass().getName()));
         }
 
         Subtotal subtotal = new Subtotal();
         assertEquals(ErrorEval.VALUE_INVALID, subtotal.evaluate(new ValueEval[] {}, 0, 0));
+        
+        wb.close();
     }
 }



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


Mime
View raw message