poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1844878 - /poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
Date Fri, 26 Oct 2018 09:32:30 GMT
Author: centic
Date: Fri Oct 26 09:32:30 2018
New Revision: 1844878

URL: http://svn.apache.org/viewvc?rev=1844878&view=rev
Log:
Set NOSONAR, adjust test slightly and reformat code

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java?rev=1844878&r1=1844877&r2=1844878&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java Fri
Oct 26 09:32:30 2018
@@ -38,7 +38,6 @@ import java.util.Arrays;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POITestCase;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.ss.usermodel.BaseTestXWorkbook;
@@ -55,7 +54,6 @@ import org.apache.poi.xssf.XSSFTestDataS
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.After;
-import org.junit.Assume;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -103,9 +101,9 @@ public final class TestSXSSFWorkbook ext
      *  changes.
      */
     @Override
+    @Ignore("SXSSF doesn't update formulas on sheet name changes, as most cells probably
aren't in memory at the time")
     @Test
     public void setSheetName() {
-        Assume.assumeTrue("SXSSF doesn't update formulas on sheet name changes, as most cells
probably aren't in memory at the time", false);
     }
 
     @Test
@@ -374,7 +372,7 @@ public final class TestSXSSFWorkbook ext
     @Test
     public void bug53515a() throws Exception {
         File out = new File("Test.xlsx");
-        out.delete();
+        assertTrue(!out.exists() || out.delete());
         for (int i = 0; i < 2; i++) {
             final SXSSFWorkbook wb;
             if (out.exists()) {
@@ -402,7 +400,8 @@ public final class TestSXSSFWorkbook ext
             }
             wb.close();
         }
-        out.delete();
+        assertTrue(out.exists());
+        assertTrue(out.delete());
     }
 
     private static void populateWorkbook(Workbook wb) {
@@ -500,33 +499,37 @@ public final class TestSXSSFWorkbook ext
     @Test
     @Ignore
     public void createFromReadOnlyWorkbook() throws Exception {
-        File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
-        OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ);
-        XSSFWorkbook xssf = new XSSFWorkbook(pkg);
-        SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2);
-        
         String sheetName = "Test SXSSF";
-        Sheet s = wb.createSheet(sheetName);
-        for (int i=0; i<10; i++) {
-            Row r = s.createRow(i);
-            r.createCell(0).setCellValue(true);
-            r.createCell(1).setCellValue(2.4);
-            r.createCell(2).setCellValue("Test Row " + i);
+        File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
+
+        try (OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ)) {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            try (XSSFWorkbook xssf = new XSSFWorkbook(pkg)) {
+                try (SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2)) {
+                    Sheet s = wb.createSheet(sheetName);
+                    for (int i = 0; i < 10; i++) {
+                        Row r = s.createRow(i);
+                        r.createCell(0).setCellValue(true);
+                        r.createCell(1).setCellValue(2.4);
+                        r.createCell(2).setCellValue("Test Row " + i);
+                    }
+                    assertEquals(10, s.getLastRowNum());
+
+                    wb.write(bos);
+                    wb.dispose();
+                }
+            }
+
+            try (XSSFWorkbook xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray())))
{
+                Sheet s = xssf.getSheet(sheetName);
+                assertEquals(10, s.getLastRowNum());
+                assertTrue(s.getRow(0).getCell(0).getBooleanCellValue());
+                assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue());
+            }
         }
-        assertEquals(10, s.getLastRowNum());
-        
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        wb.write(bos);
-        wb.dispose();
-        wb.close();
-        
-        xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()));
-        s = xssf.getSheet(sheetName);
-        assertEquals(10, s.getLastRowNum());
-        assertTrue(s.getRow(0).getCell(0).getBooleanCellValue());
-        assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue());
     }
 
+
     @Test
     public void test56557() throws IOException {
         Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56557.xlsx");



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


Mime
View raw message