poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1885253 - in /poi/trunk/src/testcases/org/apache/poi/hssf/usermodel: TestCellStyle.java TestFormulaEvaluatorBugs.java TestFormulas.java TestHSSFChart.java
Date Fri, 08 Jan 2021 00:26:16 GMT
Author: kiwiwings
Date: Fri Jan  8 00:26:16 2021
New Revision: 1885253

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

Modified:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=1885253&r1=1885252&r2=1885253&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java Fri Jan  8 00:26:16
2021
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import static org.apache.poi.ss.usermodel.BorderStyle.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -30,6 +32,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Random;
+import java.util.stream.Stream;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.usermodel.BorderStyle;
@@ -189,10 +193,10 @@ public final class TestCellStyle {
             HSSFCellStyle cs = wb.createCellStyle();
             HSSFCellStyle cs2 = wb.createCellStyle();
 
-            cs.setBorderBottom(BorderStyle.THIN);
-            cs.setBorderLeft(BorderStyle.THIN);
-            cs.setBorderRight(BorderStyle.THIN);
-            cs.setBorderTop(BorderStyle.THIN);
+            cs.setBorderBottom(THIN);
+            cs.setBorderLeft(THIN);
+            cs.setBorderRight(THIN);
+            cs.setBorderTop(THIN);
             cs.setFillForegroundColor((short) 0xA);
             cs.setFillPattern(FillPatternType.DIAMONDS);
             fnt.setColor((short) 0xf);
@@ -359,45 +363,17 @@ public final class TestCellStyle {
 
     @Test
     public void testGetSetBorderHair() throws IOException {
-    	try (HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls")) {
-            HSSFSheet s = wb.getSheetAt(0);
-            HSSFCellStyle cs;
-
-            cs = s.getRow(0).getCell(0).getCellStyle();
-            assertEquals(BorderStyle.HAIR, cs.getBorderRight());
-
-            cs = s.getRow(1).getCell(1).getCellStyle();
-            assertEquals(BorderStyle.DOTTED, cs.getBorderRight());
-
-            cs = s.getRow(2).getCell(2).getCellStyle();
-            assertEquals(BorderStyle.DASH_DOT_DOT, cs.getBorderRight());
-
-            cs = s.getRow(3).getCell(3).getCellStyle();
-            assertEquals(BorderStyle.DASHED, cs.getBorderRight());
-
-            cs = s.getRow(4).getCell(4).getCellStyle();
-            assertEquals(BorderStyle.THIN, cs.getBorderRight());
-
-            cs = s.getRow(5).getCell(5).getCellStyle();
-            assertEquals(BorderStyle.MEDIUM_DASH_DOT_DOT, cs.getBorderRight());
+        BorderStyle[] bs = {
+            HAIR, DOTTED, DASH_DOT_DOT, DASHED, THIN, MEDIUM_DASH_DOT_DOT, SLANTED_DASH_DOT,
+            MEDIUM_DASH_DOT, MEDIUM_DASHED, MEDIUM, THICK, DOUBLE
+        };
 
-            cs = s.getRow(6).getCell(6).getCellStyle();
-            assertEquals(BorderStyle.SLANTED_DASH_DOT, cs.getBorderRight());
-
-            cs = s.getRow(7).getCell(7).getCellStyle();
-            assertEquals(BorderStyle.MEDIUM_DASH_DOT, cs.getBorderRight());
-
-            cs = s.getRow(8).getCell(8).getCellStyle();
-            assertEquals(BorderStyle.MEDIUM_DASHED, cs.getBorderRight());
-
-            cs = s.getRow(9).getCell(9).getCellStyle();
-            assertEquals(BorderStyle.MEDIUM, cs.getBorderRight());
-
-            cs = s.getRow(10).getCell(10).getCellStyle();
-            assertEquals(BorderStyle.THICK, cs.getBorderRight());
-
-            cs = s.getRow(11).getCell(11).getCellStyle();
-            assertEquals(BorderStyle.DOUBLE, cs.getBorderRight());
+        try (HSSFWorkbook wb = openSample("55341_CellStyleBorder.xls")) {
+            HSSFSheet s = wb.getSheetAt(0);
+            for (int i = 0; i<bs.length; i++) {
+                HSSFCellStyle cs = s.getRow(i).getCell(i).getCellStyle();
+                assertEquals(bs[i], cs.getBorderRight());
+            }
         }
     }
 
@@ -435,62 +411,26 @@ public final class TestCellStyle {
         }
     }
 
-
-
-    private static class CellFormatBugExample extends Thread {
-        private final String fileName;
-        private Throwable exception;
-
-        public CellFormatBugExample(String fileName) {
-            this.fileName = fileName;
-        }
-
-        @Override
-        public void run() {
-            try {
-                for(int i = 0;i< 10;i++) {
-                    try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook(fileName))
{
-                        Sheet sheet = wb.getSheetAt(0);
-
-                        for (Row row : sheet) {
-                            for (int idxCell = 0; idxCell < row.getLastCellNum(); idxCell++)
{
-
-                                Cell cell = row.getCell(idxCell);
-                                cell.getCellStyle().getDataFormatString();
-                                if (cell.getCellType() == CellType.NUMERIC) {
-                                    boolean isDate = DateUtil.isCellDateFormatted(cell);
-                                    assertFalse(idxCell > 0 && isDate, "cell "
+ idxCell + " is not a date.");
-                                }
+    @Test
+    public void test56563() {
+        Stream.of("56563a.xls", "56563b.xls").parallel().forEach(fileName -> assertDoesNotThrow(()
-> {
+            Random rand = new Random();
+            for(int i=0; i<10; i++) {
+                Thread.sleep(rand.nextInt(300));
+                try (Workbook wb = openSample(fileName)) {
+                    for (Row row : wb.getSheetAt(0)) {
+                        for (Cell cell : row) {
+                            cell.getCellStyle().getDataFormatString();
+                            if (cell.getCellType() == CellType.NUMERIC) {
+                                boolean isDate = DateUtil.isCellDateFormatted(cell);
+                                int cid = cell.getColumnIndex();
+                                assertFalse(cid > 0 && isDate, "cell " + cid +
" is not a date.");
                             }
                         }
                     }
                 }
-            } catch (Throwable e) {
-                exception = e;
             }
-        }
-
-        public Throwable getException() {
-            return exception;
-        }
-    }
-
-    @Test
-    public void test56563() throws Throwable {
-        CellFormatBugExample threadA = new CellFormatBugExample("56563a.xls");
-        threadA.start();
-        CellFormatBugExample threadB = new CellFormatBugExample("56563b.xls");
-        threadB.start();
-
-        threadA.join();
-        threadB.join();
-
-        if(threadA.getException() != null) {
-            throw threadA.getException();
-        }
-        if(threadB.getException() != null) {
-            throw threadB.getException();
-        }
+        }));
     }
 
     @Test
@@ -509,7 +449,7 @@ public final class TestCellStyle {
             font.setColor(Font.COLOR_RED);
 
             CellStyle style = wb.createCellStyle();
-            style.setBorderBottom(BorderStyle.DOTTED);
+            style.setBorderBottom(DOTTED);
             style.setFont(font);
 
             Cell cell = row.createCell(0);
@@ -522,7 +462,7 @@ public final class TestCellStyle {
             newCell.setCellValue("2testtext2");
 
             CellStyle newStyle = newCell.getCellStyle();
-            assertEquals(BorderStyle.DOTTED, newStyle.getBorderBottom());
+            assertEquals(DOTTED, newStyle.getBorderBottom());
             assertEquals(Font.COLOR_RED, ((HSSFCellStyle) newStyle).getFont(wb).getColor());
         }
     }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java?rev=1885253&r1=1885252&r2=1885253&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java Fri
Jan  8 00:26:16 2021
@@ -17,7 +17,9 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
@@ -43,6 +45,7 @@ import org.apache.poi.ss.formula.ptg.Ref
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.LocaleUtil;
 import org.junit.jupiter.api.BeforeAll;
@@ -76,7 +79,7 @@ public final class TestFormulaEvaluatorB
         // Open the existing file, tweak one value and
         // re-calculate
 
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44636.xls");
+        HSSFWorkbook wb = openSampleWorkbook("44636.xls");
         HSSFSheet sheet = wb.getSheetAt(0);
         HSSFRow row = sheet.getRow(0);
 
@@ -129,7 +132,7 @@ public final class TestFormulaEvaluatorB
     @Test
     public void test44297() throws Exception {
 
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44297.xls");
+        HSSFWorkbook wb = openSampleWorkbook("44297.xls");
 
         HSSFRow row;
         HSSFCell cell;
@@ -192,7 +195,7 @@ public final class TestFormulaEvaluatorB
      */
     @Test
     public void test44410() throws Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SingleLetterRanges.xls");
+        HSSFWorkbook wb = openSampleWorkbook("SingleLetterRanges.xls");
 
         HSSFSheet sheet = wb.getSheetAt(0);
 
@@ -273,27 +276,23 @@ public final class TestFormulaEvaluatorB
 
     @Test
     public void testClassCast_bug44861() throws Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44861.xls");
-
-        // Check direct
-        HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
-
-        // And via calls
-        int numSheets = wb.getNumberOfSheets();
-        for (int i = 0; i < numSheets; i++) {
-            HSSFSheet s = wb.getSheetAt(i);
-            HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
-
-            for (Iterator<Row> rows = s.rowIterator(); rows.hasNext();) {
-                HSSFRow r = (HSSFRow)rows.next();
-                for (Iterator<Cell> cells = r.cellIterator(); cells.hasNext();) {
-                    HSSFCell c = (HSSFCell)cells.next();
-                    eval.evaluateFormulaCell(c);
+        try (HSSFWorkbook wb = openSampleWorkbook("44861.xls")) {
+            // Check direct
+            HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
+
+            // And via calls
+            for (Sheet s : wb) {
+                HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
+
+                for (Row r : s) {
+                    for (Cell c : r) {
+                        CellType ct = eval.evaluateFormulaCell(c);
+                        assertNotNull(ct);
+                    }
                 }
             }
-        }
 
-        wb.close();
+        }
     }
 
     @Test

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java?rev=1885253&r1=1885252&r2=1885253&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java Fri Jan  8 00:26:16
2021
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.usermodel;
 
 import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
@@ -864,7 +865,7 @@ public final class TestFormulas {
     public void testMissingArgPtg() throws IOException {
         try (HSSFWorkbook wb = new HSSFWorkbook()) {
             HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell(0);
-            cell.setCellFormula("IF(A1=\"A\",1,)");
+            assertDoesNotThrow(() -> cell.setCellFormula("IF(A1=\"A\",1,)"));
         }
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java?rev=1885253&r1=1885252&r2=1885253&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java Fri Jan  8 00:26:16
2021
@@ -17,7 +17,9 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
@@ -38,7 +40,7 @@ public final class TestHSSFChart {
 
 	@Test
 	public void testSingleChart() {
-		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls");
+		HSSFWorkbook wb = openSampleWorkbook("WithChart.xls");
 
 		HSSFSheet s1 = wb.getSheetAt(0);
 		HSSFSheet s2 = wb.getSheetAt(1);
@@ -68,7 +70,7 @@ public final class TestHSSFChart {
 
 	@Test
 	public void testTwoCharts() {
-		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls");
+		HSSFWorkbook wb = openSampleWorkbook("WithTwoCharts.xls");
 
 		HSSFSheet s1 = wb.getSheetAt(0);
 		HSSFSheet s2 = wb.getSheetAt(1);
@@ -101,7 +103,7 @@ public final class TestHSSFChart {
 
 	@Test
 	public void testThreeCharts() {
-		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xls");
+		HSSFWorkbook wb = openSampleWorkbook("WithThreeCharts.xls");
 
 		HSSFSheet s1 = wb.getSheetAt(0);
 		HSSFSheet s2 = wb.getSheetAt(1);
@@ -142,7 +144,7 @@ public final class TestHSSFChart {
 
     @Test
     public void testExistingSheet3() throws Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
+        HSSFWorkbook wb = openSampleWorkbook("49581.xls");
 
         HSSFSheet sheet = wb.getSheetAt( 2 ) ;
         HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
@@ -165,7 +167,7 @@ public final class TestHSSFChart {
 
     @Test
     public void testExistingSheet2() throws Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
+        HSSFWorkbook wb = openSampleWorkbook("49581.xls");
         HSSFSheet sheet = wb.getSheetAt( 1 ) ;
         HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
 
@@ -197,45 +199,38 @@ public final class TestHSSFChart {
 
     @Test
     public void testExistingSheet1() throws Exception {
-       HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
-        HSSFSheet sheet = wb.getSheetAt( 0 ) ;
-        HSSFChart[] charts = HSSFChart.getSheetCharts( sheet ) ;
-
-        for ( HSSFChart chart : charts ) {
-            //System.out.println( chart.getType() ) ;
-            HSSFSeries[] seriesArray = chart.getSeries() ;
-            //System.out.println( "seriesArray.length=" + seriesArray.length ) ;
-            for ( HSSFSeries series : seriesArray )
-            {
-                //System.out.println( "serie.getNumValues()=" + series.getNumValues() ) ;
-                CellRangeAddressBase range ;
-
-                range = series.getValuesCellRange() ;
-                //System.out.println( range.toString() ) ;
-                range.setLastRow( range.getLastRow() + 1 ) ;
-                series.setValuesCellRange( range ) ;
-
-                range = series.getCategoryLabelsCellRange() ;
-                //System.out.println( range.toString() ) ;
-                range.setLastRow( range.getLastRow() + 1 ) ;
-                series.setCategoryLabelsCellRange( range ) ;
-            }
+        try (HSSFWorkbook wb = openSampleWorkbook("49581.xls")) {
+            HSSFSheet sheet = wb.getSheetAt(0);
+            HSSFChart[] charts = HSSFChart.getSheetCharts(sheet);
+
+            for (HSSFChart chart : charts) {
+                for (HSSFSeries series : chart.getSeries()) {
+                    CellRangeAddressBase range;
+
+                    range = series.getValuesCellRange();
+                    range.setLastRow(range.getLastRow() + 1);
+                    series.setValuesCellRange(range);
+
+                    range = series.getCategoryLabelsCellRange();
+                    range.setLastRow(range.getLastRow() + 1);
+                    series.setCategoryLabelsCellRange(range);
+                }
 
-            for ( int id = 0 ; id < 2 ; id++ )
-            {
-                HSSFSeries newSeries = chart.createSeries() ;
-                newSeries.setValuesCellRange( new CellRangeAddress( 1 + id, 4, 3, 3 ) ) ;
-                String oldSeriesTitle = newSeries.getSeriesTitle() ;
-                if ( oldSeriesTitle != null )
-                {
-                    //System.out.println( "old series title: " + oldSeriesTitle ) ;
-                    newSeries.setSeriesTitle( "new series" ) ;
+                for (int id = 0; id < 2; id++) {
+                    HSSFSeries newSeries = chart.createSeries();
+                    assertNotNull(newSeries);
+                    newSeries.setValuesCellRange(new CellRangeAddress(1 + id, 4, 3, 3));
+                    String oldSeriesTitle = newSeries.getSeriesTitle();
+                    if (oldSeriesTitle != null) {
+                        newSeries.setSeriesTitle("new series");
+                    }
                 }
             }
-        }
 
-        HSSFChart chart = charts[ 2 ] ;
-        chart.removeSeries( chart.getSeries()[ 0 ] ) ;
+            HSSFChart chart = charts[2];
+            chart.removeSeries(chart.getSeries()[0]);
+            assertEquals(2, chart.getSeries().length);
+        }
     }
 
     /**
@@ -243,7 +238,7 @@ public final class TestHSSFChart {
      */
     @Test
     public void test26862() throws IOException, Exception {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
+        HSSFWorkbook wb = openSampleWorkbook("SimpleChart.xls");
         HSSFSheet srcSheet = wb.getSheetAt(0);
         HSSFChart[] srcCharts = HSSFChart.getSheetCharts(srcSheet);
         assertEquals(1, srcCharts.length);



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


Mime
View raw message