diff options
author | Dominik Stadler <centic@apache.org> | 2021-12-30 16:10:52 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2021-12-30 16:10:52 +0000 |
commit | 32311e42c2fb1403b165fdda5cbd46d9869f561e (patch) | |
tree | 78eb2526f5cf1f33a8645002b9eace607014e609 /poi-ooxml | |
parent | 6aa1e58bdfd1b2ec402598c829b8b56d7e868ad7 (diff) | |
download | poi-32311e42c2fb1403b165fdda5cbd46d9869f561e.tar.gz poi-32311e42c2fb1403b165fdda5cbd46d9869f561e.zip |
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
Diffstat (limited to 'poi-ooxml')
4 files changed, 20 insertions, 13 deletions
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]]"); } } } |