From: Dominik Stadler Date: Thu, 30 Dec 2021 16:10:52 +0000 (+0000) Subject: Fix Sonar issues and print out some more in test-assertions that do fail sometimes X-Git-Tag: REL_5_2_0~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=32311e42c2fb1403b165fdda5cbd46d9869f561e;p=poi.git Fix Sonar issues and print out some more in test-assertions that do fail sometimes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896531 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/functions/TestVlookup.java b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/functions/TestVlookup.java index 15d0dedd90..30d0e22ee1 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/functions/TestVlookup.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/formula/functions/TestVlookup.java @@ -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"); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java index de527e0385..f322bd2339 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java @@ -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); } } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java index 9cf439faa9..16a42dab55 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java @@ -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(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java index 10a31e46a8..e7e52e1c9e 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java @@ -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]]"); } } } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java index 46939beec4..f325f2cf92 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java @@ -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 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();