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
This commit is contained in:
Dominik Stadler 2021-12-30 16:10:52 +00:00
parent 6aa1e58bdf
commit 32311e42c2
5 changed files with 26 additions and 23 deletions

View 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");
}

View 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);
}
}
}

View 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();

View 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]]");
}
}
}

View 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();