]> source.dussan.org Git - poi.git/commitdiff
Fix Sonar issues and print out some more in test-assertions that do fail sometimes
authorDominik Stadler <centic@apache.org>
Thu, 30 Dec 2021 16:10:52 +0000 (16:10 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 30 Dec 2021 16:10:52 +0000 (16:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896531 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/functions/TestVlookup.java
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java

index 15d0dedd90f721bf59c83b431de41e89fd58646e..30d0e22ee13b185a7a5f71b736e4d3dbb0450a3b 100644 (file)
@@ -47,8 +47,10 @@ class TestVlookup {
         try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("VLookupFullColumn.xlsx")) {
             FormulaEvaluator feval = wb.getCreationHelper().createFormulaEvaluator();
             feval.evaluateAll();
-            assertEquals("Value1", feval.evaluate(wb.getSheetAt(0).getRow(3).getCell(1)).getStringValue(),
-                "Wrong lookup value");
+
+            Cell cell = wb.getSheetAt(0).getRow(3).getCell(1);
+            assertEquals("Value1", feval.evaluate(cell).getStringValue(),
+                "Wrong lookup value for cell " + cell);
             assertEquals(CellType.ERROR, feval.evaluate(wb.getSheetAt(0).getRow(4).getCell(1)).getCellType(),
                 "Lookup should return #N/A");
         }
index de527e03857cc74ae16b01aaddf7272ade1d4f92..f322bd233976ec27c7efc10c58f610304958923a 100644 (file)
@@ -1057,6 +1057,7 @@ class TestXSLFBugs {
             targetPresentationSlide.importContent(sourceSlide);
 
             XSLFSlide targetSlide = targetPresentation.getSlides().get(0);
+            assertNotNull(targetSlide);
             assertEquals(2, targetPresentation.getPictureData().size());
 
             targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM);
@@ -1102,7 +1103,8 @@ class TestXSLFBugs {
         try (XMLSlideShow slideShowModel = openSampleDocument("bug65673.pptx")) {
             final XSLFSlide modelSlide = slideShowModel.getSlides().get(0);
             try (XMLSlideShow newSlideShow = new XMLSlideShow()) {
-                newSlideShow.createSlide().importContent(modelSlide);
+                XSLFSlide slide = newSlideShow.createSlide().importContent(modelSlide);
+                assertNotNull(slide);
             }
         }
     }
index 9cf439faa991b956b4703fc53526a9810fa35146..16a42dab55163a3ed07ec0268de5bcc850380cba 100644 (file)
@@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.IOException;
 import java.util.Arrays;
@@ -69,6 +68,7 @@ public final class TestXSSFFormulaParser {
     private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla) {
         return FormulaParser.parse(fmla, fpb, FormulaType.CELL, -1);
     }
+
     private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla, int rowIndex) {
         return FormulaParser.parse(fmla, fpb, FormulaType.CELL, -1, rowIndex);
     }
@@ -533,6 +533,11 @@ public final class TestXSSFFormulaParser {
         Sheet sheet = wb.getSheet("my-sheet");
         Cell cell = sheet.getRow(1).getCell(4);
 
+        assertEquals(CellType.FORMULA, cell.getCellType(),
+                "Had: " + cell);
+        assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultType(),
+                "Had: " + cell + " and " + cell.getCachedFormulaResultType());
+
         assertEquals(5d, cell.getNumericCellValue(), 0d);
 
         wb.close();
index 10a31e46a8ecfc64b52c51e914de63b473ca022a..e7e52e1c9eb1c25b62048a93d6d07af538815926 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.TempFile;
@@ -601,19 +602,15 @@ public final class TestXSSFTable {
             try (XSSFWorkbook wb = new XSSFWorkbook()) {
                 XSSFSheet sheet = wb.createSheet();
 
-                final String column = testValue;
-
                 // Set the values for the table
-                XSSFRow row;
-                XSSFCell cell;
                 for (int i = 0; i < 3; i++) {
                     // Create row
-                    row = sheet.createRow(i);
+                    Row row = sheet.createRow(i);
                     for (int j = 0; j < 3; j++) {
                         // Create cell
-                        cell = row.createCell(j);
+                        Cell cell = row.createCell(j);
                         if (i == 0) {
-                            final String columnName = column + (j + 1);
+                            final String columnName = testValue + (j + 1);
                             cell.setCellValue(columnName);
                         } else {
                             if (j != 2) {
@@ -630,8 +627,9 @@ public final class TestXSSFTable {
                 table.setName("Table1");
                 table.setDisplayName("Table1");
                 for (int i = 1; i < 3; i++) {
-                    cell = sheet.getRow(i).getCell(2);
-                    cell.setCellFormula("Table1[[#This Row],[" + column + "1]]");
+                    Cell cell = sheet.getRow(i).getCell(2);
+                    assertNotNull(cell);
+                    cell.setCellFormula("Table1[[#This Row],[" + testValue + "1]]");
                 }
             }
         }
index 46939beec4a8dcdec7a423a3ce2676a139b85e8c..f325f2cf92376c0da09fb91f2ab5ca9ba81914ac 100644 (file)
@@ -46,7 +46,6 @@ import org.apache.poi.sl.usermodel.BaseTestSlideShow;
 import org.apache.poi.sl.usermodel.PlaceholderDetails;
 import org.apache.poi.util.LocaleUtil;
 import org.junit.jupiter.api.Test;
-import org.opentest4j.AssertionFailedError;
 
 /**
  * Tests for TextRuns
@@ -464,7 +463,6 @@ public final class TestTextRun {
             shape2.setText("Text 2");
             slide.addShape(shape2);
 
-            runs = slide.getTextParagraphs();
             assertEquals(2, runs.size());
 
             assertSame(run1, runs.get(0));
@@ -541,6 +539,7 @@ public final class TestTextRun {
             assertTrue(runs.stream().map(HSLFTextRun::getFontFamily).allMatch("Arial"::equals));
 
             int[] exp = {36, 24, 12, 32, 12, 12};
+            //noinspection ConstantConditions
             int[] act = runs.stream().map(HSLFTextRun::getFontSize).mapToInt(Double::intValue).toArray();
             assertArrayEquals(exp, act);
         }
@@ -610,15 +609,12 @@ public final class TestTextRun {
             for (Map.Entry<Locale,String[]> me : formats.entrySet()) {
                 LocaleUtil.setUserLocale(me.getKey());
 
-                try {
-                    // refresh internal members
-                    phs.forEach(PlaceholderDetails::getPlaceholder);
+                // refresh internal members
+                phs.forEach(PlaceholderDetails::getPlaceholder);
 
-                    String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
-                    assertArrayEquals(me.getValue(), actDate);
-                } catch (AssertionFailedError e) {
-                    throw new AssertionFailedError("While handling local " + me.getKey());
-                }
+                String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
+                assertArrayEquals(me.getValue(), actDate,
+                        "While handling local " + me.getKey());
             }
         } finally {
             LocaleUtil.resetUserLocale();