poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1885179 - in /poi/trunk/src/testcases/org/apache/poi/hssf: record/common/TestUnicodeString.java usermodel/TestBugs.java
Date Tue, 05 Jan 2021 23:40:36 GMT
Author: kiwiwings
Date: Tue Jan  5 23:40:36 2021
New Revision: 1885179

URL: http://svn.apache.org/viewvc?rev=1885179&view=rev
Log:
Sonar fixes

Modified:
    poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java?rev=1885179&r1=1885178&r2=1885179&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java Tue Jan
 5 23:40:36 2021
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.common;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.ByteArrayInputStream;
@@ -350,21 +351,20 @@ public final class TestUnicodeString {
 
     @Test
     public void unicodeStringsNullPointer() throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
 
-        Sheet sheet = wb.createSheet("styles");
-        Row row = sheet.createRow(0);
-        Cell cell = row.createCell(0);
+            Sheet sheet = wb.createSheet("styles");
+            Row row = sheet.createRow(0);
+            Cell cell = row.createCell(0);
 
-        CellStyle style = wb.createCellStyle();
-        style.setFont(wb.createFont());
-        cell.setCellStyle(style);
+            CellStyle style = wb.createCellStyle();
+            style.setFont(wb.createFont());
+            cell.setCellStyle(style);
 
-        cell.setCellValue("test");
+            cell.setCellValue("test");
 
-        HSSFOptimiser.optimiseFonts(wb);
-
-        wb.close();
+            assertDoesNotThrow(() -> HSSFOptimiser.optimiseFonts(wb));
+        }
     }
 
     @Test

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1885179&r1=1885178&r2=1885179&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Tue Jan  5 23:40:36
2021
@@ -283,14 +283,11 @@ public final class TestBugs extends Base
     @Test
     public void bug27852() throws Exception {
         try (HSSFWorkbook wb = openSampleWorkbook("27852.xls")) {
-
-            for (int i = 0; i < wb.getNumberOfNames(); i++) {
-                HSSFName name = wb.getNameAt(i);
-                name.getNameName();
-                if (name.isFunctionName()) {
-                    continue;
+            for (HSSFName name : wb.getAllNames()) {
+                assertNotNull(name.getNameName());
+                if (!name.isFunctionName()) {
+                    assertNotNull(name.getRefersToFormula());
                 }
-                name.getRefersToFormula();
             }
         }
     }
@@ -305,9 +302,7 @@ public final class TestBugs extends Base
             HSSFSheet sheet = wb.createSheet();
             for (int i = 1; i < 400; i++) {
                 HSSFRow row = sheet.getRow(i);
-                if (row != null) {
-                    row.getCell(0);
-                }
+                assertNull(row);
             }
         }
     }
@@ -1970,6 +1965,7 @@ public final class TestBugs extends Base
         try (HSSFWorkbook wb = openSampleWorkbook("46250.xls")) {
             Sheet sh = wb.getSheet("Template");
             Sheet cSh = wb.cloneSheet(wb.getSheetIndex(sh));
+            int sIdx = wb.getSheetIndex(cSh);
 
             HSSFPatriarch patriarch = (HSSFPatriarch) cSh.createDrawingPatriarch();
             HSSFTextbox tb = (HSSFTextbox) patriarch.getChildren().get(2);
@@ -1977,7 +1973,11 @@ public final class TestBugs extends Base
             tb.setString(new HSSFRichTextString("POI test"));
             tb.setAnchor(new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 10, 10));
 
-            writeOutAndReadBack(wb).close();
+            try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) {
+                HSSFSheet sh2 = wb2.getSheetAt(sIdx);
+                assertNotNull(sh2);
+                assertNotNull(sh2.getDrawingPatriarch());
+            }
         }
     }
 
@@ -1999,7 +1999,12 @@ public final class TestBugs extends Base
                 row.createCell(6).setCellValue("added cells.");
             }
 
-            writeOutAndReadBack(wb).close();
+            try (HSSFWorkbook wb2 = writeOutAndReadBack(wb)) {
+                Sheet sheet2 = wb2.getSheet("test-sheet");
+                Row row2 = sheet2.getRow(5);
+                assertNotNull(row2);
+                assertEquals(cal.getTime(),row2.getCell(2).getDateCellValue());
+            }
         }
     }
 
@@ -2299,12 +2304,11 @@ public final class TestBugs extends Base
     public void test57925() throws IOException {
         try (Workbook wb = openSampleWorkbook("57925.xls")) {
             wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
-
-            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
-                Sheet sheet = wb.getSheetAt(i);
+            DataFormatter df = new DataFormatter();
+            for (Sheet sheet : wb) {
                 for (Row row : sheet) {
                     for (Cell cell : row) {
-                        new DataFormatter().formatCellValue(cell);
+                        assertNotNull(df.formatCellValue(cell));
                     }
                 }
             }



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


Mime
View raw message