mirror of https://github.com/apache/poi.git
Apply IDE suggestions and ignore sonar false positive
Use NullOutputStream.INSTANCE Rework one test slightly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72282b8780
commit
f490e43442
|
@ -169,7 +169,7 @@ public abstract class Record implements GenericRecord
|
|||
// From there, we instanciate the class
|
||||
// Any special record handling occurs once we have the class
|
||||
RecordTypes recordType = RecordTypes.forTypeID((short) type);
|
||||
RecordConstructor c = recordType.recordConstructor;
|
||||
RecordConstructor<?> c = recordType.recordConstructor;
|
||||
if (c == null) {
|
||||
// How odd. RecordTypes normally substitutes in
|
||||
// a default handler class if it has heard of the record
|
||||
|
|
|
@ -92,7 +92,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh
|
|||
enum LoadSavePhase {
|
||||
INIT, LOADED
|
||||
}
|
||||
private static final ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<>();
|
||||
private static final ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<>(); // NOSONAR
|
||||
static {
|
||||
// allow to clear all thread-locals via ThreadLocalUtil
|
||||
ThreadLocalUtil.registerCleaner(loadSavePhase::remove);
|
||||
|
|
|
@ -26,7 +26,6 @@ import javax.swing.*;
|
|||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -136,7 +135,7 @@ public class CellFormatPart {
|
|||
"|\\[h{1,2}] # Elapsed time: hour spec\n" +
|
||||
"|\\[m{1,2}] # Elapsed time: minute spec\n" +
|
||||
"|\\[s{1,2}] # Elapsed time: second spec\n" +
|
||||
"|[^;] # A character\n" + "";
|
||||
"|[^;] # A character\n";
|
||||
|
||||
String format = "(?:" + color + ")? # Text color\n" +
|
||||
"(?:\\[" + condition + "])? # Condition\n" +
|
||||
|
|
|
@ -198,7 +198,7 @@ public final class BiffViewer {
|
|||
|
||||
if (os == null) {
|
||||
cs = Charset.defaultCharset();
|
||||
osOut = NullOutputStream.NULL_OUTPUT_STREAM;
|
||||
osOut = NullOutputStream.INSTANCE;
|
||||
} else if (os == System.out) {
|
||||
// Use the system default encoding when sending to System Out
|
||||
cs = Charset.defaultCharset();
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.hssf.dev;
|
||||
|
||||
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -39,6 +37,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
import org.apache.tools.ant.util.NullOutputStream;
|
||||
|
||||
class TestBiffDrawingToXml extends BaseTestIteratingXLS {
|
||||
|
||||
|
@ -74,7 +73,7 @@ class TestBiffDrawingToXml extends BaseTestIteratingXLS {
|
|||
@Override
|
||||
void runOneFile(File pFile) throws Exception {
|
||||
try (InputStream inp = new FileInputStream(pFile);
|
||||
OutputStream outputStream = NULL_OUTPUT_STREAM) {
|
||||
OutputStream outputStream = NullOutputStream.INSTANCE) {
|
||||
writeToFile(outputStream, inp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,21 +59,21 @@ class TestWorkbookEvaluator {
|
|||
|
||||
private static final double EPSILON = 0.0000001;
|
||||
|
||||
private static ValueEval evaluateFormula(Ptg[] ptgs) {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
private static ValueEval evaluateFormula(Ptg[] ptgs) throws IOException {
|
||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||
wb.createSheet().createRow(0).createCell(0);
|
||||
EvaluationWorkbook ewb = HSSFEvaluationWorkbook.create(wb);
|
||||
OperationEvaluationContext ec = new OperationEvaluationContext(null, ewb, 0, 0, 0, null);
|
||||
return new WorkbookEvaluator(null, null, null).evaluateFormula(ec, ptgs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that the evaluator can directly handle tAttrSum (instead of relying on re-parsing
|
||||
* the whole formula which converts tAttrSum to tFuncVar("SUM") )
|
||||
*/
|
||||
@Test
|
||||
void testAttrSum() {
|
||||
|
||||
void testAttrSum() throws IOException {
|
||||
Ptg[] ptgs = {
|
||||
new IntPtg(42),
|
||||
AttrPtg.SUM,
|
||||
|
@ -89,14 +89,14 @@ class TestWorkbookEvaluator {
|
|||
* to the error constant #REF! )
|
||||
*/
|
||||
@Test
|
||||
void testRefErr() {
|
||||
|
||||
void testRefErr() throws IOException {
|
||||
confirmRefErr(new RefErrorPtg());
|
||||
confirmRefErr(new AreaErrPtg());
|
||||
confirmRefErr(new DeletedRef3DPtg(0));
|
||||
confirmRefErr(new DeletedArea3DPtg(0));
|
||||
}
|
||||
private static void confirmRefErr(Ptg ptg) {
|
||||
|
||||
private static void confirmRefErr(Ptg ptg) throws IOException {
|
||||
Ptg[] ptgs = {
|
||||
ptg,
|
||||
};
|
||||
|
@ -110,7 +110,7 @@ class TestWorkbookEvaluator {
|
|||
* the whole formula which converts tAttrSum to tFuncVar("SUM") )
|
||||
*/
|
||||
@Test
|
||||
void testMemFunc() {
|
||||
void testMemFunc() throws IOException {
|
||||
Ptg[] ptgs = {
|
||||
new IntPtg(42),
|
||||
AttrPtg.SUM,
|
||||
|
@ -139,16 +139,16 @@ class TestWorkbookEvaluator {
|
|||
HSSFSheet bSheet1 = wbB.getSheetAt(0);
|
||||
|
||||
// Simple case - single link from wbA to wbB
|
||||
confirmFormula(wbA, 0, 0, 0, "[multibookFormulaB.xls]BSheet1!B1");
|
||||
confirmFormula(wbA, 0, 0, "[multibookFormulaB.xls]BSheet1!B1");
|
||||
cell = aSheet1.getRow(0).getCell(0);
|
||||
confirmEvaluation(35, evaluatorA, cell);
|
||||
|
||||
|
||||
// more complex case - back link into wbA
|
||||
// [wbA]ASheet1!A2 references (among other things) [wbB]BSheet1!B2
|
||||
confirmFormula(wbA, 0, 1, 0, "[multibookFormulaB.xls]BSheet1!$B$2+2*A3");
|
||||
confirmFormula(wbA, 1, 0, "[multibookFormulaB.xls]BSheet1!$B$2+2*A3");
|
||||
// [wbB]BSheet1!B2 references (among other things) [wbA]AnotherSheet!A1:B2
|
||||
confirmFormula(wbB, 0, 1, 1, "SUM([multibookFormulaA.xls]AnotherSheet!$A$1:$B$2)+B3");
|
||||
confirmFormula(wbB, 1, 1, "SUM([multibookFormulaA.xls]AnotherSheet!$A$1:$B$2)+B3");
|
||||
|
||||
cell = aSheet1.getRow(1).getCell(0);
|
||||
confirmEvaluation(264, evaluatorA, cell);
|
||||
|
@ -176,9 +176,9 @@ class TestWorkbookEvaluator {
|
|||
assertEquals(expectedValue, fe.evaluate(cell).getNumberValue(), 0.0);
|
||||
}
|
||||
|
||||
private static void confirmFormula(HSSFWorkbook wb, int sheetIndex, int rowIndex, int columnIndex,
|
||||
private static void confirmFormula(HSSFWorkbook wb, int rowIndex, int columnIndex,
|
||||
String expectedFormula) {
|
||||
HSSFCell cell = wb.getSheetAt(sheetIndex).getRow(rowIndex).getCell(columnIndex);
|
||||
HSSFCell cell = wb.getSheetAt(0).getRow(rowIndex).getCell(columnIndex);
|
||||
assertEquals(expectedFormula, cell.getCellFormula());
|
||||
}
|
||||
|
||||
|
@ -187,8 +187,8 @@ class TestWorkbookEvaluator {
|
|||
* the result of a function gets translated to {@link BlankEval}.
|
||||
*/
|
||||
@Test
|
||||
void testMissingArg() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
void testMissingArg() throws IOException {
|
||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||
HSSFSheet sheet = wb.createSheet("Sheet1");
|
||||
HSSFRow row = sheet.createRow(0);
|
||||
HSSFCell cell = row.createCell(0);
|
||||
|
@ -217,6 +217,7 @@ class TestWorkbookEvaluator {
|
|||
// adding blank to "abc" gives "abc"
|
||||
assertEquals("abc", cv.getStringValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Functions like IF, INDIRECT, INDEX, OFFSET etc can return AreaEvals which
|
||||
|
@ -255,7 +256,7 @@ class TestWorkbookEvaluator {
|
|||
*/
|
||||
@Test
|
||||
void testNamesInFormulas() throws IOException {
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
try (Workbook wb = new HSSFWorkbook()) {
|
||||
Sheet sheet = wb.createSheet("Sheet1");
|
||||
|
||||
Name name1 = wb.createName();
|
||||
|
@ -304,8 +305,7 @@ class TestWorkbookEvaluator {
|
|||
assertEquals(28.14, fe.evaluate(row3.getCell(2)).getNumberValue(), EPSILON);
|
||||
assertEquals(10.0, fe.evaluate(row4.getCell(2)).getNumberValue(), EPSILON);
|
||||
assertEquals(6.0, fe.evaluate(row5.getCell(2)).getNumberValue(), EPSILON);
|
||||
|
||||
wb.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -384,8 +384,8 @@ class TestWorkbookEvaluator {
|
|||
|
||||
|
||||
private void testIFEqualsFormulaEvaluation_evaluate(
|
||||
String formula, CellType cellType, String expectedFormula, double expectedResult) {
|
||||
Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType);
|
||||
String formula, CellType cellType, String expectedFormula, double expectedResult) throws IOException {
|
||||
try (Workbook wb = testIFEqualsFormulaEvaluation_setup(formula, cellType)) {
|
||||
Cell D1 = wb.getSheet("IFEquals").getRow(0).getCell(3);
|
||||
|
||||
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
|
||||
|
@ -400,9 +400,11 @@ class TestWorkbookEvaluator {
|
|||
|
||||
testIFEqualsFormulaEvaluation_teardown(wb);
|
||||
}
|
||||
}
|
||||
|
||||
private void testIFEqualsFormulaEvaluation_eval(
|
||||
final String formula, final CellType cellType, final String expectedFormula, final double expectedValue) {
|
||||
final String formula, final CellType cellType, final String expectedFormula, final double expectedValue)
|
||||
throws IOException {
|
||||
testIFEqualsFormulaEvaluation_evaluate(formula, cellType, expectedFormula, expectedValue);
|
||||
testIFEqualsFormulaEvaluation_evaluateFormulaCell(formula, cellType, expectedFormula, expectedValue);
|
||||
testIFEqualsFormulaEvaluation_evaluateInCell(formula, cellType, expectedValue);
|
||||
|
@ -411,7 +413,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_NumericLiteral() {
|
||||
void testIFEqualsFormulaEvaluation_NumericLiteral() throws IOException {
|
||||
final String formula = "IF(A1=1, 2, 3)";
|
||||
final CellType cellType = CellType.NUMERIC;
|
||||
final String expectedFormula = "IF(A1=1,2,3)";
|
||||
|
@ -420,7 +422,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_Numeric() {
|
||||
void testIFEqualsFormulaEvaluation_Numeric() throws IOException {
|
||||
final String formula = "IF(A1=1, B1, C1)";
|
||||
final CellType cellType = CellType.NUMERIC;
|
||||
final String expectedFormula = "IF(A1=1,B1,C1)";
|
||||
|
@ -429,7 +431,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_NumericCoerceToString() {
|
||||
void testIFEqualsFormulaEvaluation_NumericCoerceToString() throws IOException {
|
||||
final String formula = "IF(A1&\"\"=\"1\", B1, C1)";
|
||||
final CellType cellType = CellType.NUMERIC;
|
||||
final String expectedFormula = "IF(A1&\"\"=\"1\",B1,C1)";
|
||||
|
@ -438,7 +440,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_String() {
|
||||
void testIFEqualsFormulaEvaluation_String() throws IOException {
|
||||
final String formula = "IF(A1=1, B1, C1)";
|
||||
final CellType cellType = CellType.STRING;
|
||||
final String expectedFormula = "IF(A1=1,B1,C1)";
|
||||
|
@ -447,7 +449,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_StringCompareToString() {
|
||||
void testIFEqualsFormulaEvaluation_StringCompareToString() throws IOException {
|
||||
final String formula = "IF(A1=\"1\", B1, C1)";
|
||||
final CellType cellType = CellType.STRING;
|
||||
final String expectedFormula = "IF(A1=\"1\",B1,C1)";
|
||||
|
@ -456,7 +458,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_StringCoerceToNumeric() {
|
||||
void testIFEqualsFormulaEvaluation_StringCoerceToNumeric() throws IOException {
|
||||
final String formula = "IF(A1+0=1, B1, C1)";
|
||||
final CellType cellType = CellType.STRING;
|
||||
final String expectedFormula = "IF(A1+0=1,B1,C1)";
|
||||
|
@ -466,7 +468,7 @@ class TestWorkbookEvaluator {
|
|||
|
||||
@Disabled("Bug 58591: this test currently fails")
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_Boolean() {
|
||||
void testIFEqualsFormulaEvaluation_Boolean() throws IOException {
|
||||
final String formula = "IF(A1=1, B1, C1)";
|
||||
final CellType cellType = CellType.BOOLEAN;
|
||||
final String expectedFormula = "IF(A1=1,B1,C1)";
|
||||
|
@ -476,7 +478,7 @@ class TestWorkbookEvaluator {
|
|||
|
||||
@Disabled("Bug 58591: this test currently fails")
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_BooleanSimple() {
|
||||
void testIFEqualsFormulaEvaluation_BooleanSimple() throws IOException {
|
||||
final String formula = "3-(A1=1)";
|
||||
final CellType cellType = CellType.BOOLEAN;
|
||||
final String expectedFormula = "3-(A1=1)";
|
||||
|
@ -485,7 +487,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_Formula() {
|
||||
void testIFEqualsFormulaEvaluation_Formula() throws IOException {
|
||||
final String formula = "IF(A1=1, B1, C1)";
|
||||
final CellType cellType = CellType.FORMULA;
|
||||
final String expectedFormula = "IF(A1=1,B1,C1)";
|
||||
|
@ -494,7 +496,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_Blank() {
|
||||
void testIFEqualsFormulaEvaluation_Blank() throws IOException {
|
||||
final String formula = "IF(A1=1, B1, C1)";
|
||||
final CellType cellType = CellType.BLANK;
|
||||
final String expectedFormula = "IF(A1=1,B1,C1)";
|
||||
|
@ -503,7 +505,7 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_BlankCompareToZero() {
|
||||
void testIFEqualsFormulaEvaluation_BlankCompareToZero() throws IOException {
|
||||
final String formula = "IF(A1=0, B1, C1)";
|
||||
final CellType cellType = CellType.BLANK;
|
||||
final String expectedFormula = "IF(A1=0,B1,C1)";
|
||||
|
@ -513,7 +515,7 @@ class TestWorkbookEvaluator {
|
|||
|
||||
@Disabled("Bug 58591: this test currently fails")
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_BlankInverted() {
|
||||
void testIFEqualsFormulaEvaluation_BlankInverted() throws IOException {
|
||||
final String formula = "IF(NOT(A1)=1, B1, C1)";
|
||||
final CellType cellType = CellType.BLANK;
|
||||
final String expectedFormula = "IF(NOT(A1)=1,B1,C1)";
|
||||
|
@ -523,7 +525,7 @@ class TestWorkbookEvaluator {
|
|||
|
||||
@Disabled("Bug 58591: this test currently fails")
|
||||
@Test
|
||||
void testIFEqualsFormulaEvaluation_BlankInvertedSimple() {
|
||||
void testIFEqualsFormulaEvaluation_BlankInvertedSimple() throws IOException {
|
||||
final String formula = "3-(NOT(A1)=1)";
|
||||
final CellType cellType = CellType.BLANK;
|
||||
final String expectedFormula = "3-(NOT(A1)=1)";
|
||||
|
@ -605,12 +607,12 @@ class TestWorkbookEvaluator {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testRefToBlankCellInArrayFormula() {
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
void testRefToBlankCellInArrayFormula() throws IOException {
|
||||
try (Workbook wb = new HSSFWorkbook()) {
|
||||
Sheet sheet = wb.createSheet();
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cellA1 = row.createCell(0);
|
||||
Cell cellB1 = row.createCell(1);
|
||||
/*Cell cellB1 =*/ row.createCell(1);
|
||||
Cell cellC1 = row.createCell(2);
|
||||
Row row2 = sheet.createRow(1);
|
||||
Cell cellA2 = row2.createCell(0);
|
||||
|
@ -634,11 +636,12 @@ class TestWorkbookEvaluator {
|
|||
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
||||
|
||||
assertEquals("1", cellA2.getStringCellValue());
|
||||
assertEquals(0,cellB2.getNumericCellValue(), 0.00001);
|
||||
assertEquals("3",cellC2.getStringCellValue());
|
||||
assertEquals(0, cellB2.getNumericCellValue(), 0.00001);
|
||||
assertEquals("3", cellC2.getStringCellValue());
|
||||
|
||||
assertEquals("1", cellA3.getStringCellValue());
|
||||
assertEquals(0,cellB3.getNumericCellValue(), 0.00001);
|
||||
assertEquals("3",cellC3.getStringCellValue());
|
||||
assertEquals(0, cellB3.getNumericCellValue(), 0.00001);
|
||||
assertEquals("3", cellC3.getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
|
@ -49,9 +48,8 @@ class TestCodepointsUtil {
|
|||
final String unicodeSurrogates = "\uD835\uDF4A\uD835\uDF4B\uD835\uDF4C\uD835\uDF4D\uD835\uDF4E"
|
||||
+ "abcdef123456";
|
||||
List<String> codePoints = new ArrayList<>();
|
||||
CodepointsUtil.primitiveIterator(unicodeSurrogates).forEachRemaining((IntConsumer) (i) -> {
|
||||
codePoints.add(new String(Character.toChars(i)));
|
||||
});
|
||||
CodepointsUtil.primitiveIterator(unicodeSurrogates).forEachRemaining((IntConsumer) (i) ->
|
||||
codePoints.add(new String(Character.toChars(i))));
|
||||
assertEquals(17, codePoints.size());
|
||||
for (String point : codePoints) {
|
||||
assertTrue(point.length() >= 1 && point.length() <= 2, "codepoint " + point + "is wrong size");
|
||||
|
|
Loading…
Reference in New Issue