You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/12/24 18:42:38 UTC
svn commit: r1884783 [36/40] - in /poi:
site/src/documentation/content/xdocs/ trunk/ trunk/sonar/
trunk/sonar/integration-test/ trunk/sonar/ooxml/
trunk/src/excelant/poi-ant-contrib/
trunk/src/excelant/testcases/org/apache/poi/ss/excelant/ trunk/src/ex...
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java Thu Dec 24 18:42:29 2020
@@ -19,12 +19,12 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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 java.io.IOException;
@@ -34,7 +34,8 @@ import org.apache.poi.ss.ITestDataProvid
import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
/**
* Base tests for Conditional Formatting, for both HSSF and XSSF
@@ -50,70 +51,47 @@ public abstract class BaseTestConditiona
return true;
}
- protected abstract void assertColour(String hexExpected, Color actual);
+ protected abstract void assertColor(String hexExpected, Color actual);
@Test
- public void testBasic() throws IOException {
+ public void testBasic() throws Throwable {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Sheet sh = wb.createSheet();
SheetConditionalFormatting sheetCF = sh.getSheetConditionalFormatting();
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- try {
- sheetCF.removeConditionalFormatting(0);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.removeConditionalFormatting(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("1");
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule("2");
ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule("3");
ConditionalFormattingRule rule4 = sheetCF.createConditionalFormattingRule("4");
- try {
- sheetCF.addConditionalFormatting(null, rule1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("regions must not be null"));
- }
- try {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- (ConditionalFormattingRule) null);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("cfRules must not be null"));
- }
- try {
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(null, rule1));
+ assertTrue(e.getMessage().startsWith("regions must not be null"));
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")}, (ConditionalFormattingRule) null));
+ assertTrue(e.getMessage().startsWith("cfRules must not be null"));
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.addConditionalFormatting(
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")}, new ConditionalFormattingRule[0]));
+ assertTrue(e.getMessage().startsWith("cfRules must not be empty"));
+
+ Executable exec = () ->
sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[0]);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("cfRules must not be empty"));
- }
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
+ new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
if (applyLimitOf3()) {
- try {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
- }
+ e = assertThrows(IllegalArgumentException.class, exec);
+ assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
} else {
- sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
- new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
+ exec.execute();
}
}
}
@@ -273,34 +251,25 @@ public abstract class BaseTestConditiona
// adjacent address are merged
int formatIndex = sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{
- CellRangeAddress.valueOf("A1:A5")
- }, rule1);
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A5")}, rule1);
assertEquals(0, formatIndex);
assertEquals(1, sheetCF.getNumConditionalFormattings());
sheetCF.removeConditionalFormatting(0);
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
formatIndex = sheetCF.addConditionalFormatting(
- new CellRangeAddress[]{
- CellRangeAddress.valueOf("A1:A5")
- }, rule1);
+ new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A5")}, rule1);
assertEquals(0, formatIndex);
assertEquals(1, sheetCF.getNumConditionalFormattings());
sheetCF.removeConditionalFormatting(0);
assertEquals(0, sheetCF.getNumConditionalFormattings());
- try {
- assertNull(sheetCF.getConditionalFormattingAt(0));
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
- }
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheetCF.getConditionalFormattingAt(0));
+ assertTrue(e.getMessage().startsWith("Specified CF index 0 is outside the allowable range"));
}
}
@@ -611,11 +580,11 @@ public abstract class BaseTestConditiona
// Sets the background colour to lighter green
// TODO Should the colours be slightly different between formats? Would CFEX support help for HSSF?
if (cr instanceof HSSFConditionalFormattingRule) {
- assertColour("0:8080:0", cr.getFontFormatting().getFontColor());
- assertColour("CCCC:FFFF:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("0:8080:0", cr.getFontFormatting().getFontColor());
+ assertColor("CCCC:FFFF:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
} else {
- assertColour("006100", cr.getFontFormatting().getFontColor());
- assertColour("C6EFCE", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("006100", cr.getFontFormatting().getFontColor());
+ assertColor("C6EFCE", cr.getPatternFormatting().getFillBackgroundColorColor());
}
@@ -635,11 +604,11 @@ public abstract class BaseTestConditiona
// Sets the background colour to lighter red
// TODO Should the colours be slightly different between formats? Would CFEX support help for HSSF?
if (cr instanceof HSSFConditionalFormattingRule) {
- assertColour("8080:0:8080", cr.getFontFormatting().getFontColor());
- assertColour("FFFF:9999:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("8080:0:8080", cr.getFontFormatting().getFontColor());
+ assertColor("FFFF:9999:CCCC", cr.getPatternFormatting().getFillBackgroundColorColor());
} else {
- assertColour("9C0006", cr.getFontFormatting().getFontColor());
- assertColour("FFC7CE", cr.getPatternFormatting().getFillBackgroundColorColor());
+ assertColor("9C0006", cr.getFontFormatting().getFontColor());
+ assertColor("FFC7CE", cr.getPatternFormatting().getFillBackgroundColorColor());
}
@@ -798,7 +767,7 @@ public abstract class BaseTestConditiona
assertEquals(0, databar.getWidthMin());
assertEquals(100, databar.getWidthMax());
- assertColour(color, databar.getColor());
+ assertColor(color, databar.getColor());
ConditionalFormattingThreshold th;
th = databar.getMinThreshold();
@@ -877,7 +846,7 @@ public abstract class BaseTestConditiona
// Colors should match
for (int i=0; i<colors.length; i++) {
- assertColour(colors[i], color.getColors()[i]);
+ assertColor(colors[i], color.getColors()[i]);
}
}
@@ -1210,7 +1179,7 @@ public abstract class BaseTestConditiona
assertTrue(dbFmt.isLeftToRight());
assertEquals(0, dbFmt.getWidthMin());
assertEquals(100, dbFmt.getWidthMax());
- assertColour(colorHex, dbFmt.getColor());
+ assertColor(colorHex, dbFmt.getColor());
dbFmt.getMinThreshold().setRangeType(RangeType.MIN);
dbFmt.getMaxThreshold().setRangeType(RangeType.MAX);
@@ -1234,7 +1203,7 @@ public abstract class BaseTestConditiona
assertTrue(dbFmt.isLeftToRight());
assertEquals(0, dbFmt.getWidthMin());
assertEquals(100, dbFmt.getWidthMax());
- assertColour(colorHex, dbFmt.getColor());
+ assertColor(colorHex, dbFmt.getColor());
assertEquals(RangeType.MIN, dbFmt.getMinThreshold().getRangeType());
assertEquals(RangeType.MAX, dbFmt.getMaxThreshold().getRangeType());
@@ -1319,7 +1288,7 @@ public abstract class BaseTestConditiona
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testSetCellRangeAddressWithNullRanges() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
final Sheet sheet = wb.createSheet("S1");
@@ -1332,7 +1301,7 @@ public abstract class BaseTestConditiona
assertEquals(1, cf.getNumConditionalFormattings());
ConditionalFormatting readCf = cf.getConditionalFormattingAt(0);
- readCf.setFormattingRanges(null);
+ assertThrows(IllegalArgumentException.class, () -> readCf.setFormattingRanges(null));
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java Thu Dec 24 18:42:29 2020
@@ -17,14 +17,14 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests of implementation of {@link DataFormat}
@@ -116,7 +116,7 @@ public abstract class BaseTestDataFormat
DataFormat dataFormat = wb.createDataFormat();
short fmtIdx = dataFormat.getFormat(fmt);
String readbackFmt = dataFormat.getFormat(fmtIdx);
- assertEquals(msg, fmt, readbackFmt);
+ assertEquals(fmt, readbackFmt, msg);
}
}
@@ -158,10 +158,10 @@ public abstract class BaseTestDataFormat
String expWhole = r.getCell(2).getStringCellValue();
String exp3dp = r.getCell(4).getStringCellValue();
- assertEquals("Wrong formatting of " + value + " for row " + rn,
- expWhole, fmt.formatCellValue(r.getCell(1), eval));
- assertEquals("Wrong formatting of " + value + " for row " + rn,
- exp3dp, fmt.formatCellValue(r.getCell(3), eval));
+ assertEquals(expWhole, fmt.formatCellValue(r.getCell(1), eval),
+ "Wrong formatting of " + value + " for row " + rn);
+ assertEquals(exp3dp, fmt.formatCellValue(r.getCell(3), eval),
+ "Wrong formatting of " + value + " for row " + rn);
}
}
@@ -198,7 +198,7 @@ public abstract class BaseTestDataFormat
assertEquals("-"+pound+" 12,345", formatter.formatCellValue(nve));
// TODO Fix this to not have an extra 0 at the end
//assertEquals(pound+" - ", formatter.formatCellValue(zero));
-
+
wb.close();
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataValidation.java Thu Dec 24 18:42:29 2020
@@ -25,7 +25,7 @@ import org.apache.poi.ss.util.CellRangeA
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class for testing Excel's data validation mechanism
@@ -492,7 +492,7 @@ public abstract class BaseTestDataValida
log("done !");
_testDataProvider.writeOutAndReadBack(wb).close();
-
+
wb.close();
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java Thu Dec 24 18:42:29 2020
@@ -17,18 +17,18 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.poi.ss.ITestDataProvider;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* @author Yegor Kozlov
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java Thu Dec 24 18:42:29 2020
@@ -17,15 +17,20 @@
package org.apache.poi.ss.usermodel;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.IOException;
import java.util.Locale;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing implementation of {@link FormulaEvaluator}
@@ -62,7 +67,7 @@ public abstract class BaseTestFormulaEva
assertEquals(6.0, c1.getNumericCellValue(), 0.0001);
assertEquals(5.0, c2.getNumericCellValue(), 0.0001);
-
+
wb.close();
}
@@ -107,7 +112,7 @@ public abstract class BaseTestFormulaEva
assertEquals(17.5, c2.getNumericCellValue(), 0.0001);
assertEquals(1, c3.getNumericCellValue(), 0.0001);
assertEquals(4, c4.getNumericCellValue(), 0.0001);
-
+
wb.close();
}
@@ -134,7 +139,7 @@ public abstract class BaseTestFormulaEva
cell = sheet.getRow(4).getCell(0);
assertEquals("B5", cell.getCellFormula());
assertEquals("UniqueDocumentNumberID", evaluator.evaluate(cell).getStringValue());
-
+
wb.close();
}
@@ -173,7 +178,7 @@ public abstract class BaseTestFormulaEva
assertEquals(5.0, evaluator.evaluate(sh2.getRow(0).getCell(1)).getNumberValue(), 0.0);
assertEquals(15.0, evaluator.evaluate(sh2.getRow(0).getCell(2)).getNumberValue(), 0.0);
-
+
wb.close();
}
@@ -207,10 +212,10 @@ public abstract class BaseTestFormulaEva
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(26.0, fe.evaluate(cell0).getNumberValue(), 0.0);
assertEquals(56.0, fe.evaluate(cell1).getNumberValue(), 0.0);
-
+
wb.close();
}
-
+
@Test
public void testRepeatedEvaluation() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
@@ -218,37 +223,37 @@ public abstract class BaseTestFormulaEva
Sheet sheet = wb.createSheet("Sheet1");
Row r = sheet.createRow(0);
Cell c = r.createCell(0, CellType.FORMULA);
-
+
// Create a value and check it
c.setCellFormula("Date(2011,10,6)");
CellValue cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
-
+
// Change it
c.setCellFormula("Date(2011,10,4)");
-
+
// Evaluate it, no change as the formula evaluator
// won't know to clear the cache
cellValue = fe.evaluate(c);
assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
-
+
// Manually flush for this cell, and check
fe.notifySetFormula(c);
cellValue = fe.evaluate(c);
assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
-
+
// Change again, without notifying
c.setCellFormula("Date(2010,10,4)");
cellValue = fe.evaluate(c);
assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
-
+
// Now manually clear all, will see the new value
fe.clearAllCachedResultValues();
cellValue = fe.evaluate(c);
assertEquals(40455.0, cellValue.getNumberValue(), 0.0);
-
+
wb.close();
}
@@ -323,10 +328,10 @@ public abstract class BaseTestFormulaEva
assertEquals(2162.62, fe.evaluateInCell(cellB1).getNumericCellValue(), 0.0);
assertEquals(2162.62, fe.evaluateInCell(cellC1).getNumericCellValue(), 0.0);
assertEquals(2162.61, fe.evaluateInCell(cellD1).getNumericCellValue(), 0.0);
-
+
wb.close();
}
-
+
@Test
public void evaluateInCellReturnsSameCell() throws IOException {
try (Workbook wb = _testDataProvider.createWorkbook()) {
@@ -638,8 +643,8 @@ public abstract class BaseTestFormulaEva
double result = a3.getNumericCellValue();
// result is correct
- assertTrue(String.format(Locale.ROOT, "Expected %f to be greater than %f", result, 2.0), result > 2.0);
- assertTrue(String.format(Locale.ROOT, "Expected %f to be less than %f", result, 4.0), result < 4.0);
+ assertTrue(result > 2.0, String.format(Locale.ROOT, "Expected %f to be greater than %f", result, 2.0));
+ assertTrue(result < 4.0, String.format(Locale.ROOT, "Expected %f to be less than %f", result, 4.0));
// ensure that this works for SUM
assertEquals(CellType.FORMULA, a3.getCellType());
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java Thu Dec 24 18:42:29 2020
@@ -17,16 +17,16 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import java.io.IOException;
import java.util.List;
-import org.junit.Test;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.ITestDataProvider;
+import org.junit.jupiter.api.Test;
/**
* Test diffrent types of Excel hyperlinks
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java Thu Dec 24 18:42:29 2020
@@ -17,12 +17,12 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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 java.io.IOException;
import java.util.Arrays;
@@ -34,7 +34,7 @@ import org.apache.poi.ss.ITestDataProvid
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests of implementations of {@link org.apache.poi.ss.usermodel.Name}.
@@ -51,159 +51,130 @@ public abstract class BaseTestNamedRange
@Test
public final void testCreate() throws Exception {
- // Create a new workbook
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet("Test1");
- wb.createSheet("Testing Named Ranges");
-
- Name name1 = wb.createName();
- name1.setNameName("testOne");
-
- //setting a duplicate name should throw IllegalArgumentException
- Name name2 = wb.createName();
- try {
- name2.setNameName("testOne");
- fail("expected exception");
- } catch (IllegalArgumentException e){
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ wb.createSheet("Test1");
+ wb.createSheet("Testing Named Ranges");
+
+ Name name1 = wb.createName();
+ name1.setNameName("testOne");
+
+ //setting a duplicate name should throw IllegalArgumentException
+ Name name2 = wb.createName();
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> name2.setNameName("testOne"));
assertEquals("The workbook already contains this name: testOne", e.getMessage());
- }
- //the check for duplicates is case-insensitive
- try {
- name2.setNameName("TESTone");
- fail("expected exception");
- } catch (IllegalArgumentException e){
+
+ //the check for duplicates is case-insensitive
+ e = assertThrows(IllegalArgumentException.class, () -> name2.setNameName("TESTone"));
assertEquals("The workbook already contains this name: TESTone", e.getMessage());
- }
- name2.setNameName("testTwo");
+ name2.setNameName("testTwo");
- String ref1 = "Test1!$A$1:$B$1";
- name1.setRefersToFormula(ref1);
- assertEquals(ref1, name1.getRefersToFormula());
- assertEquals("Test1", name1.getSheetName());
-
- String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
- name1.setRefersToFormula(ref2);
- assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());
- assertEquals("Testing Named Ranges", name1.getSheetName());
-
- assertEquals(-1, name1.getSheetIndex());
- name1.setSheetIndex(-1);
- assertEquals(-1, name1.getSheetIndex());
- try {
- name1.setSheetIndex(2);
- fail("should throw IllegalArgumentException");
- } catch(IllegalArgumentException e){
+ String ref1 = "Test1!$A$1:$B$1";
+ name1.setRefersToFormula(ref1);
+ assertEquals(ref1, name1.getRefersToFormula());
+ assertEquals("Test1", name1.getSheetName());
+
+ String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
+ name1.setRefersToFormula(ref2);
+ assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());
+ assertEquals("Testing Named Ranges", name1.getSheetName());
+
+ assertEquals(-1, name1.getSheetIndex());
+ name1.setSheetIndex(-1);
+ assertEquals(-1, name1.getSheetIndex());
+ e = assertThrows(IllegalArgumentException.class, () -> name1.setSheetIndex(2));
assertEquals("Sheet index (2) is out of range (0..1)", e.getMessage());
- }
- name1.setSheetIndex(1);
- assertEquals(1, name1.getSheetIndex());
+ name1.setSheetIndex(1);
+ assertEquals(1, name1.getSheetIndex());
- //-1 means the name applies to the entire workbook
- name1.setSheetIndex(-1);
- assertEquals(-1, name1.getSheetIndex());
-
- //names cannot be blank and must begin with a letter or underscore and not contain spaces
- String[] invalidNames = {"", "123", "1Name", "Named Range"};
- for (String name : invalidNames) {
- try {
- name1.setNameName(name);
- fail("should have thrown exceptiuon due to invalid name: " + name);
- } catch (IllegalArgumentException e) {
- // expected during successful test
+ //-1 means the name applies to the entire workbook
+ name1.setSheetIndex(-1);
+ assertEquals(-1, name1.getSheetIndex());
+
+ //names cannot be blank and must begin with a letter or underscore and not contain spaces
+ String[] invalidNames = {"", "123", "1Name", "Named Range"};
+ for (String name : invalidNames) {
+ assertThrows(IllegalArgumentException.class, () -> name1.setNameName(name),
+ "should have thrown exceptiuon due to invalid name: " + name);
}
}
-
- wb.close();
}
@Test
public final void testUnicodeNamedRange() throws Exception {
- HSSFWorkbook wb1 = new HSSFWorkbook();
- wb1.createSheet("Test");
- Name name = wb1.createName();
- name.setNameName("\u03B1");
- name.setRefersToFormula("Test!$D$3:$E$8");
-
+ try (HSSFWorkbook wb1 = new HSSFWorkbook()) {
+ wb1.createSheet("Test");
+ Name name = wb1.createName();
+ name.setNameName("\u03B1");
+ name.setRefersToFormula("Test!$D$3:$E$8");
+
+ try (HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1)) {
+ Name name2 = wb2.getName("\u03B1");
+
+ assertNotNull(name2);
+ assertEquals("\u03B1", name2.getNameName());
+ assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
- HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
- Name name2 = wb2.getName("\u03B1");
-
- assertEquals("\u03B1", name2.getNameName());
- assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
-
- wb2.close();
- wb1.close();
+ }
+ }
}
@Test
public final void testAddRemove() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- assertEquals(0, wb.getNumberOfNames());
- Name name1 = wb.createName();
- name1.setNameName("name1");
- assertEquals(1, wb.getNumberOfNames());
-
- Name name2 = wb.createName();
- name2.setNameName("name2");
- assertEquals(2, wb.getNumberOfNames());
-
- Name name3 = wb.createName();
- name3.setNameName("name3");
- assertEquals(3, wb.getNumberOfNames());
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ assertEquals(0, wb.getNumberOfNames());
+ Name name1 = wb.createName();
+ name1.setNameName("name1");
+ assertEquals(1, wb.getNumberOfNames());
+
+ Name name2 = wb.createName();
+ name2.setNameName("name2");
+ assertEquals(2, wb.getNumberOfNames());
+
+ Name name3 = wb.createName();
+ name3.setNameName("name3");
+ assertEquals(3, wb.getNumberOfNames());
- wb.removeName(wb.getName("name2"));
- assertEquals(2, wb.getNumberOfNames());
-
- wb.close();
+ wb.removeName(wb.getName("name2"));
+ assertEquals(2, wb.getNumberOfNames());
+ }
}
@Test
public final void testScope() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- wb.createSheet();
- wb.createSheet();
-
- Name name;
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ wb.createSheet();
+ wb.createSheet();
- name = wb.createName();
- name.setNameName("aaa");
- name = wb.createName();
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ wb.createName().setNameName("aaa");
+ Exception e = assertThrows(Exception.class, () -> wb.createName().setNameName("aaa"));
assertEquals("The workbook already contains this name: aaa", e.getMessage());
- }
- name = wb.createName();
- name.setSheetIndex(0);
- name.setNameName("aaa");
- name = wb.createName();
- name.setSheetIndex(0);
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ Name name1 = wb.createName();
+ name1.setSheetIndex(0);
+ name1.setNameName("aaa");
+
+ e = assertThrows(Exception.class, () -> {
+ Name name2 = wb.createName();
+ name2.setSheetIndex(0);
+ name2.setNameName("aaa");
+ });
assertEquals("The sheet already contains this name: aaa", e.getMessage());
- }
- name = wb.createName();
- name.setSheetIndex(1);
- name.setNameName("aaa");
- name = wb.createName();
- name.setSheetIndex(1);
- try {
- name.setNameName("aaa");
- fail("Expected exception");
- } catch(Exception e){
+ name1 = wb.createName();
+ name1.setSheetIndex(1);
+ name1.setNameName("aaa");
+
+ e = assertThrows(Exception.class, () -> {
+ Name name2 = wb.createName();
+ name2.setSheetIndex(1);
+ name2.setNameName("aaa");
+ });
assertEquals("The sheet already contains this name: aaa", e.getMessage());
- }
- assertEquals(3, wb.getNames("aaa").size());
-
- wb.close();
+ assertEquals(3, wb.getNames("aaa").size());
+ }
}
/**
@@ -247,13 +218,13 @@ public abstract class BaseTestNamedRange
// Read the Excel file and verify its content
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
Name nm1 = wb2.getName("RangeTest1");
- assertEquals("Name is " + nm1.getNameName(), "RangeTest1", nm1.getNameName());
- assertEquals("Reference is " + nm1.getRefersToFormula(), (wb2.getSheetName(0) + "!$A$1:$L$41"), nm1.getRefersToFormula());
+ assertEquals("RangeTest1", nm1.getNameName(), "Name is " + nm1.getNameName());
+ assertEquals((wb2.getSheetName(0) + "!$A$1:$L$41"), nm1.getRefersToFormula(), "Reference is " + nm1.getRefersToFormula());
Name nm2 = wb2.getName("RangeTest2");
- assertEquals("Name is " + nm2.getNameName(), "RangeTest2", nm2.getNameName());
- assertEquals("Reference is " + nm2.getRefersToFormula(), (wb2.getSheetName(1) + "!$A$1:$O$21"), nm2.getRefersToFormula());
-
+ assertEquals("RangeTest2", nm2.getNameName(), "Name is " + nm2.getNameName());
+ assertEquals((wb2.getSheetName(1) + "!$A$1:$O$21"), nm2.getRefersToFormula(), "Reference is " + nm2.getRefersToFormula());
+
wb2.close();
wb1.close();
}
@@ -272,9 +243,9 @@ public abstract class BaseTestNamedRange
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+
workbook.close();
}
@@ -293,9 +264,9 @@ public abstract class BaseTestNamedRange
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
-
+
workbook.close();
}
@@ -315,9 +286,9 @@ public abstract class BaseTestNamedRange
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
String retrievedPrintArea = wb2.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
- assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
+ assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+
wb2.close();
wb1.close();
}
@@ -327,51 +298,50 @@ public abstract class BaseTestNamedRange
*/
@Test
public final void testMultiplePrintAreaFile() throws Exception {
- Workbook wb1 = _testDataProvider.createWorkbook();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
- wb1.createSheet("Sheet1");
- wb1.createSheet("Sheet2");
- wb1.createSheet("Sheet3");
- String reference1 = "$A$1:$B$1";
- String reference2 = "$B$2:$D$5";
- String reference3 = "$D$2:$F$5";
-
- wb1.setPrintArea(0, reference1);
- wb1.setPrintArea(1, reference2);
- wb1.setPrintArea(2, reference3);
-
- //Check created print areas
- String retrievedPrintArea;
-
- retrievedPrintArea = wb1.getPrintArea(0);
- assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
- assertEquals("Sheet1!" + reference1, retrievedPrintArea);
-
- retrievedPrintArea = wb1.getPrintArea(1);
- assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
- assertEquals("Sheet2!" + reference2, retrievedPrintArea);
-
- retrievedPrintArea = wb1.getPrintArea(2);
- assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
- assertEquals("Sheet3!" + reference3, retrievedPrintArea);
-
- // Check print areas after re-reading workbook
- Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
-
- retrievedPrintArea = wb2.getPrintArea(0);
- assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
- assertEquals("Sheet1!" + reference1, retrievedPrintArea);
-
- retrievedPrintArea = wb2.getPrintArea(1);
- assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea);
- assertEquals("Sheet2!" + reference2, retrievedPrintArea);
-
- retrievedPrintArea = wb2.getPrintArea(2);
- assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea);
- assertEquals("Sheet3!" + reference3, retrievedPrintArea);
-
- wb2.close();
- wb1.close();
+ wb1.createSheet("Sheet1");
+ wb1.createSheet("Sheet2");
+ wb1.createSheet("Sheet3");
+ String reference1 = "$A$1:$B$1";
+ String reference2 = "$B$2:$D$5";
+ String reference3 = "$D$2:$F$5";
+
+ wb1.setPrintArea(0, reference1);
+ wb1.setPrintArea(1, reference2);
+ wb1.setPrintArea(2, reference3);
+
+ //Check created print areas
+ String retrievedPrintArea;
+
+ retrievedPrintArea = wb1.getPrintArea(0);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 1)");
+ assertEquals("Sheet1!" + reference1, retrievedPrintArea);
+
+ retrievedPrintArea = wb1.getPrintArea(1);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 2)");
+ assertEquals("Sheet2!" + reference2, retrievedPrintArea);
+
+ retrievedPrintArea = wb1.getPrintArea(2);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 3)");
+ assertEquals("Sheet3!" + reference3, retrievedPrintArea);
+
+ // Check print areas after re-reading workbook
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+
+ retrievedPrintArea = wb2.getPrintArea(0);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 1)");
+ assertEquals("Sheet1!" + reference1, retrievedPrintArea);
+
+ retrievedPrintArea = wb2.getPrintArea(1);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 2)");
+ assertEquals("Sheet2!" + reference2, retrievedPrintArea);
+
+ retrievedPrintArea = wb2.getPrintArea(2);
+ assertNotNull(retrievedPrintArea, "Print Area Not Found (Sheet 3)");
+ assertEquals("Sheet3!" + reference3, retrievedPrintArea);
+ }
+ }
}
/**
@@ -388,9 +358,9 @@ public abstract class BaseTestNamedRange
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-
+
workbook.close();
}
@@ -407,9 +377,9 @@ public abstract class BaseTestNamedRange
String reference = "$A$1:$B$1,$D$1:$F$2";
workbook.setPrintArea(0, reference);
String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
assertEquals("'Test Print Area'!$A$1:$B$1,'Test Print Area'!$D$1:$F$2", retrievedPrintArea);
-
+
workbook.close();
}
@@ -419,19 +389,19 @@ public abstract class BaseTestNamedRange
*/
@Test
public final void testPrintAreaRemove() throws Exception {
- Workbook workbook = _testDataProvider.createWorkbook();
- workbook.createSheet("Test Print Area");
- workbook.getSheetName(0);
+ try (Workbook workbook = _testDataProvider.createWorkbook()) {
+ workbook.createSheet("Test Print Area");
+ workbook.getSheetName(0);
- workbook.setPrintArea(0, 0, 1, 0, 0);
+ workbook.setPrintArea(0, 0, 1, 0, 0);
- String retrievedPrintArea = workbook.getPrintArea(0);
+ String retrievedPrintArea = workbook.getPrintArea(0);
- assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+ assertNotNull(retrievedPrintArea, "Print Area not defined for first sheet");
- workbook.removePrintArea(0);
- assertNull("PrintArea was not removed", workbook.getPrintArea(0));
- workbook.close();
+ workbook.removePrintArea(0);
+ assertNull(workbook.getPrintArea(0), "PrintArea was not removed");
+ }
}
/**
@@ -461,13 +431,13 @@ public abstract class BaseTestNamedRange
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
Name nm = wb2.getName("RangeTest");
- assertEquals("Name is " + nm.getNameName(), "RangeTest", nm.getNameName());
- assertEquals("Reference is " + nm.getRefersToFormula(), (wb2.getSheetName(0) + "!$D$4:$E$8"), nm.getRefersToFormula());
+ assertEquals("RangeTest", nm.getNameName(), "Name is " + nm.getNameName());
+ assertEquals((wb2.getSheetName(0) + "!$D$4:$E$8"), nm.getRefersToFormula(), "Reference is " + nm.getRefersToFormula());
nm = wb2.getName("AnotherTest");
- assertEquals("Name is " + nm.getNameName(), "AnotherTest", nm.getNameName());
- assertEquals("Reference is " + nm.getRefersToFormula(), newNamedRange2.getRefersToFormula(), nm.getRefersToFormula());
-
+ assertEquals("AnotherTest", nm.getNameName(), "Name is " + nm.getNameName());
+ assertEquals(newNamedRange2.getRefersToFormula(), nm.getRefersToFormula(), "Reference is " + nm.getRefersToFormula());
+
wb2.close();
wb1.close();
}
@@ -499,7 +469,7 @@ public abstract class BaseTestNamedRange
// retrieve the cell at the named range and test its contents
AreaReference aref = wb.getCreationHelper().createAreaReference(aNamedCell.getRefersToFormula());
- assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
+ assertTrue(aref.isSingleCell(), "Should be exactly 1 cell in the named cell :'" +cellName+"'");
CellReference cref = aref.getFirstCell();
assertNotNull(cref);
@@ -508,7 +478,7 @@ public abstract class BaseTestNamedRange
Row r = sheet.getRow(cref.getRow());
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
- assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
+ assertEquals(contents, cellValue, "Contents of cell retrieved by its named reference");
wb.close();
}
@@ -543,8 +513,8 @@ public abstract class BaseTestNamedRange
Row r = sheet.getRow(cref.getRow());
Cell c = r.getCell(cref.getCol());
String contents = c.getRichStringCellValue().getString();
- assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
-
+ assertEquals(contents, cvalue, "Contents of cell retrieved by its named reference");
+
wb.close();
}
@@ -571,7 +541,7 @@ public abstract class BaseTestNamedRange
Name n = wb.createName();
n.setNameName("UPSState");
String formula = n.getRefersToFormula();
-
+
// bug 46973: fails here with IllegalArgumentException
// ptgs must not be null
@@ -589,8 +559,8 @@ public abstract class BaseTestNamedRange
// contrived example to expose bug:
n.setRefersToFormula("if(A1,\"#REF!\", \"\")");
- assertFalse("Identified bug in recoginising formulas referring to deleted cells", n.isDeleted());
-
+ assertFalse(n.isDeleted(), "Identified bug in recoginising formulas referring to deleted cells");
+
wb.close();
}
@@ -608,35 +578,30 @@ public abstract class BaseTestNamedRange
n.setFunction(false);
assertFalse(n.isFunctionName());
-
+
wb.close();
}
@Test
public final void testDefferedSetting() throws Exception {
- Workbook wb = _testDataProvider.createWorkbook();
- Name n1 = wb.createName();
- assertNull(n1.getRefersToFormula());
- assertEquals("", n1.getNameName());
-
- Name n2 = wb.createName();
- assertNull(n2.getRefersToFormula());
- assertEquals("", n2.getNameName());
-
- n1.setNameName("sale_1");
- n1.setRefersToFormula("10");
-
- n2.setNameName("sale_2");
- n2.setRefersToFormula("20");
-
- try {
- n2.setNameName("sale_1");
- fail("Expected exception");
- } catch(Exception e){
+ try (Workbook wb = _testDataProvider.createWorkbook()) {
+ Name n1 = wb.createName();
+ assertNull(n1.getRefersToFormula());
+ assertEquals("", n1.getNameName());
+
+ Name n2 = wb.createName();
+ assertNull(n2.getRefersToFormula());
+ assertEquals("", n2.getNameName());
+
+ n1.setNameName("sale_1");
+ n1.setRefersToFormula("10");
+
+ n2.setNameName("sale_2");
+ n2.setRefersToFormula("20");
+
+ Exception e = assertThrows(Exception.class, () -> n2.setNameName("sale_1"));
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
}
-
- wb.close();
}
@Test
@@ -659,23 +624,23 @@ public abstract class BaseTestNamedRange
x2.setSheetIndex(wb.getSheetIndex("sheet2"));
List<? extends Name> names = wb.getNames("x");
- assertEquals("Had: " + names, 2, names.size());
+ assertEquals(2, names.size(), "Had: " + names);
assertEquals("1", names.get(0).getRefersToFormula());
assertEquals("2", names.get(1).getRefersToFormula());
assertEquals("1", wb.getName("x").getRefersToFormula());
wb.removeName(wb.getName("x"));
assertEquals("2", wb.getName("x").getRefersToFormula());
-
+
wb.close();
}
-
+
// bug 56781: name validation only checks for first character's validity and presence of spaces
// bug 60246: validate name does not allow DOT in named ranges
@Test
public void testValid() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
-
+
Name name = wb.createName();
for (String valid : Arrays.asList(
"Hello",
@@ -688,63 +653,54 @@ public abstract class BaseTestNamedRange
)) {
name.setNameName(valid);
}
-
+
wb.close();
}
-
+
@Test
public void testInvalid() {
Workbook wb = _testDataProvider.createWorkbook();
-
+
Name name = wb.createName();
- try {
- name.setNameName("");
- fail("expected exception: (blank)");
- } catch (final IllegalArgumentException e) {
- assertEquals("Name cannot be blank", e.getMessage());
- }
-
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> name.setNameName(""));
+ assertEquals("Name cannot be blank", e.getMessage());
+
for (String invalid : Arrays.asList(
- "1number",
- "Sheet1!A1",
- "Exclamation!",
- "Has Space",
- "Colon:",
- "A-Minus",
- "A+Plus",
- "Dollar$",
- ".periodAtBeginning",
- "R", //special shorthand
- "C", //special shorthand
- "A1", // A1-style cell reference
- "R1C1", // R1C1-style cell reference
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
- "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters"
- )) {
- try {
- name.setNameName(invalid);
- fail("expected exception: " + invalid);
- } catch (final IllegalArgumentException e) {
- assertTrue(invalid,
- e.getMessage().startsWith("Invalid name: '"+invalid+"'"));
- }
+ "1number",
+ "Sheet1!A1",
+ "Exclamation!",
+ "Has Space",
+ "Colon:",
+ "A-Minus",
+ "A+Plus",
+ "Dollar$",
+ ".periodAtBeginning",
+ "R", //special shorthand
+ "C", //special shorthand
+ "A1", // A1-style cell reference
+ "R1C1", // R1C1-style cell reference
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters..."+
+ "NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters.NameThatIsLongerThan255Characters"
+ )) {
+ e = assertThrows(IllegalArgumentException.class, () -> name.setNameName(invalid));
+ assertTrue(e.getMessage().startsWith("Invalid name: '"+invalid+"'"));
}
-
+
}
-
+
// bug 60260: renaming a sheet with a named range referring to a unicode (non-ASCII) sheet name
@Test
public void renameSheetWithNamedRangeReferringToUnicodeSheetName() {
Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("Sheet\u30FB1");
-
+
Name name = wb.createName();
name.setNameName("test_named_range");
name.setRefersToFormula("'Sheet\u30FB201'!A1:A6");
-
+
wb.setSheetName(0, "Sheet 1");
IOUtils.closeQuietly(wb);
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java Thu Dec 24 18:42:29 2020
@@ -17,9 +17,9 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.awt.BasicStroke;
import java.awt.Color;
@@ -43,7 +43,7 @@ import org.apache.poi.hssf.usermodel.HSS
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.util.Units;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class BaseTestPicture {
@@ -64,12 +64,12 @@ public abstract class BaseTestPicture {
double emuPX = Units.EMU_PER_PIXEL;
- assertEquals("the image height differs", inpDim.getHeight(), cmpDim.getHeight(), emuPX*6);
- assertEquals("the image width differs", inpDim.getWidth(), cmpDim.getWidth(), emuPX*6);
- assertEquals("the starting column differs", inpCA.getCol1(), cmpCA.getCol1());
- assertEquals("the column x-offset differs", inpCA.getDx1(), cmpCA.getDx1(), 1);
- assertEquals("the column y-offset differs", inpCA.getDy1(), cmpCA.getDy1(), 1);
- assertEquals("the ending columns differs", inpCA.getCol2(), cmpCA.getCol2());
+ assertEquals(inpDim.getHeight(), cmpDim.getHeight(), emuPX*6, "the image height differs");
+ assertEquals(inpDim.getWidth(), cmpDim.getWidth(), emuPX*6, "the image width differs");
+ assertEquals(inpCA.getCol1(), cmpCA.getCol1(), "the starting column differs");
+ assertEquals(inpCA.getDx1(), cmpCA.getDx1(), 1, "the column x-offset differs");
+ assertEquals(inpCA.getDy1(), cmpCA.getDy1(), 1, "the column y-offset differs");
+ assertEquals(inpCA.getCol2(), cmpCA.getCol2(), "the ending columns differs");
// can't compare row heights because of variable test heights
input.resize();
@@ -77,8 +77,8 @@ public abstract class BaseTestPicture {
Dimension imgDim = input.getImageDimension();
- assertEquals("the image height differs", imgDim.getHeight(), inpDim.getHeight()/emuPX, 1);
- assertEquals("the image width differs", imgDim.getWidth(), inpDim.getWidth()/emuPX, 1);
+ assertEquals(imgDim.getHeight(), inpDim.getHeight()/emuPX, 1, "the image height differs");
+ assertEquals(imgDim.getWidth(), inpDim.getWidth()/emuPX, 1, "the image width differs");
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRangeCopier.java Thu Dec 24 18:42:29 2020
@@ -19,17 +19,17 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-@Ignore
+@Disabled
public abstract class BaseTestRangeCopier {
protected Sheet sheet1;
protected Sheet sheet2;
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java Thu Dec 24 18:42:29 2020
@@ -17,20 +17,21 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* A base class for testing implementations of
@@ -139,76 +140,56 @@ public abstract class BaseTestRow {
assertEquals(-1, row.getFirstCellNum());
assertEquals(0, row.getPhysicalNumberOfCells());
}
-
+
wb2.close();
}
protected void baseTestRowBounds(int maxRowNum) throws IOException {
- Workbook workbook = _testDataProvider.createWorkbook();
- Sheet sheet = workbook.createSheet();
- //Test low row bound
- sheet.createRow(0);
- //Test low row bound exception
- try {
- sheet.createRow(-1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertTrue("Did not find expected error message, had: " + e,
- e.getMessage().startsWith("Invalid row number (-1)"));
+ try (Workbook workbook = _testDataProvider.createWorkbook()) {
+ Sheet sheet = workbook.createSheet();
+ //Test low row bound
+ sheet.createRow(0);
+ //Test low row bound exception
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> sheet.createRow(-1));
+ assertTrue(e.getMessage().startsWith("Invalid row number (-1)"));
+
+ //Test high row bound
+ sheet.createRow(maxRowNum);
+ //Test high row bound exception
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.createRow(maxRowNum + 1));
+ assertEquals("Invalid row number (" + (maxRowNum + 1) + ") outside allowable range (0.." + maxRowNum + ")", e.getMessage());
}
-
- //Test high row bound
- sheet.createRow(maxRowNum);
- //Test high row bound exception
- try {
- sheet.createRow(maxRowNum + 1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertEquals("Invalid row number ("+(maxRowNum + 1)+") outside allowable range (0.."+maxRowNum+")", e.getMessage());
- }
-
- workbook.close();
}
protected void baseTestCellBounds(int maxCellNum) throws IOException {
- Workbook wb1 = _testDataProvider.createWorkbook();
- Sheet sheet = wb1.createSheet();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ Sheet sheet = wb1.createSheet();
- Row row = sheet.createRow(0);
- //Test low cell bound
- try {
- row.createCell(-1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
+ Row row1 = sheet.createRow(0);
+ //Test low cell bound
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> row1.createCell(-1));
assertTrue(e.getMessage().startsWith("Invalid column index (-1)"));
- }
- //Test high cell bound
- try {
- row.createCell(maxCellNum + 1);
- fail("expected exception");
- } catch (IllegalArgumentException e) {
- // expected during successful test
- assertTrue(e.getMessage().startsWith("Invalid column index ("+(maxCellNum+1)+")"));
- }
- for(int i=0; i < maxCellNum; i++){
- row.createCell(i);
- }
- assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
- Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
- wb1.close();
-
- sheet = wb2.getSheetAt(0);
- row = sheet.getRow(0);
- assertEquals(maxCellNum, row.getPhysicalNumberOfCells());
- for(int i=0; i < maxCellNum; i++){
- Cell cell = row.getCell(i);
- assertEquals(i, cell.getColumnIndex());
+ //Test high cell bound
+ e = assertThrows(IllegalArgumentException.class, () -> row1.createCell(maxCellNum + 1));
+ assertTrue(e.getMessage().startsWith("Invalid column index (" + (maxCellNum + 1) + ")"));
+
+ for (int i = 0; i < maxCellNum; i++) {
+ row1.createCell(i);
+ }
+ assertEquals(maxCellNum, row1.getPhysicalNumberOfCells());
+
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+ sheet = wb2.getSheetAt(0);
+ Row row2 = sheet.getRow(0);
+ assertEquals(maxCellNum, row2.getPhysicalNumberOfCells());
+ for (int i = 0; i < maxCellNum; i++) {
+ Cell cell = row2.getCell(i);
+ assertEquals(i, cell.getColumnIndex());
+ }
+ }
}
- wb2.close();
}
/**
@@ -223,9 +204,7 @@ public abstract class BaseTestRow {
// New row has last col -1
assertEquals(-1, row.getLastCellNum());
- if(row.getLastCellNum() == 0) {
- fail("Identified bug 43901");
- }
+ assertNotEquals(0, row.getLastCellNum(), "Identified bug 43901");
// Create two cells, will return one higher
// than that for the last number
@@ -307,7 +286,7 @@ public abstract class BaseTestRow {
assertNull(row.getCell(3));
assertNull(row.getCell(4));
assertEquals(CellType.NUMERIC, row.getCell(5).getCellType());
-
+
workbook.close();
}
@@ -452,7 +431,7 @@ public abstract class BaseTestRow {
// Save, load and re-check
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
wb1.close();
-
+
sheet = wb2.getSheetAt(0);
row1 = sheet.getRow(0);
@@ -464,10 +443,10 @@ public abstract class BaseTestRow {
assertNull(row1.getRowStyle());
assertEquals(style, row2.getRowStyle());
assertEquals(4, style.getDataFormat());
-
+
wb2.close();
}
-
+
@Test
public void testCellShiftingRight() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -480,26 +459,23 @@ public abstract class BaseTestRow {
row.createCell(4, CellType.NUMERIC).setCellValue(4);//E
row.createCell(5, CellType.NUMERIC).setCellValue(5);//F
row.createCell(6, CellType.NUMERIC).setCellValue(6);//G
- try {
- row.shiftCellsLeft(6, 4, 2); // range [6-4] is illegal
- fail("expected shiftLeft to fail");
- } catch (IllegalArgumentException e){
- row.shiftCellsRight(2, 4, 1);
- //should be [0.0, 1.0, null, 2.0, 3.0, 4.0, 6.0, null]
-
- Cell h1 = row.getCell(7);
- assertNull(h1);
- Cell g1 = row.getCell(6);
- assertEquals(6, g1.getNumericCellValue(), 0.01);
- Cell f1 = row.getCell(5);
- assertEquals(4, f1.getNumericCellValue(), 0.01);
- Cell e1 = row.getCell(4);
- assertEquals(3, e1.getNumericCellValue(), 0.01);
- Cell d1 = row.getCell(3);
- assertEquals(2, d1.getNumericCellValue(), 0.01);
- Cell c1 = row.getCell(2);
- assertNull(c1);
- }
+
+ assertThrows(IllegalArgumentException.class, () -> row.shiftCellsLeft(6, 4, 2), "range [6-4] is illegal");
+ row.shiftCellsRight(2, 4, 1);
+ //should be [0.0, 1.0, null, 2.0, 3.0, 4.0, 6.0, null]
+
+ Cell h1 = row.getCell(7);
+ assertNull(h1);
+ Cell g1 = row.getCell(6);
+ assertEquals(6, g1.getNumericCellValue(), 0.01);
+ Cell f1 = row.getCell(5);
+ assertEquals(4, f1.getNumericCellValue(), 0.01);
+ Cell e1 = row.getCell(4);
+ assertEquals(3, e1.getNumericCellValue(), 0.01);
+ Cell d1 = row.getCell(3);
+ assertEquals(2, d1.getNumericCellValue(), 0.01);
+ Cell c1 = row.getCell(2);
+ assertNull(c1);
}
@Test
public void testCellShiftingLeft() {
@@ -513,24 +489,21 @@ public abstract class BaseTestRow {
row.createCell(4, CellType.NUMERIC).setCellValue(4);//E
row.createCell(5, CellType.NUMERIC).setCellValue(5);//F
row.createCell(6, CellType.NUMERIC).setCellValue(6);//G
- try {
- row.shiftCellsLeft(4, 6, -2); // step = -1 is illegal
- fail("expected shiftLeft to fail");
- } catch (IllegalArgumentException e){
- row.shiftCellsLeft(4, 6, 2);
- //should be [0.0, 1.0, 4.0, 5.0, 6.0, null, null, null]
-
- Cell b1 = row.getCell(1);
- assertEquals(1, b1.getNumericCellValue(), 0.01);
- Cell c1 = row.getCell(2);
- assertEquals(4, c1.getNumericCellValue(), 0.01);
- Cell d1 = row.getCell(3);
- assertEquals(5, d1.getNumericCellValue(), 0.01);
- Cell e1 = row.getCell(4);
- assertEquals(6, e1.getNumericCellValue(), 0.01);
- Cell f1 = row.getCell(5);
- assertNull(f1);
- }
+
+ assertThrows(IllegalArgumentException.class, () -> row.shiftCellsLeft(4, 6, -2), "step = -1 is illegal");
+ row.shiftCellsLeft(4, 6, 2);
+ //should be [0.0, 1.0, 4.0, 5.0, 6.0, null, null, null]
+
+ Cell b1 = row.getCell(1);
+ assertEquals(1, b1.getNumericCellValue(), 0.01);
+ Cell c1 = row.getCell(2);
+ assertEquals(4, c1.getNumericCellValue(), 0.01);
+ Cell d1 = row.getCell(3);
+ assertEquals(5, d1.getNumericCellValue(), 0.01);
+ Cell e1 = row.getCell(4);
+ assertEquals(6, e1.getNumericCellValue(), 0.01);
+ Cell f1 = row.getCell(5);
+ assertNull(f1);
}
@Test
@@ -538,13 +511,11 @@ public abstract class BaseTestRow {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("sheet1");
- assertEquals("Sheet without rows should return -1 as lastRowNum",
- -1, sheet.getLastRowNum());
+ assertEquals(-1, sheet.getLastRowNum(), "Sheet without rows should return -1 as lastRowNum");
Row row = sheet.createRow(0);
assertNotNull(row);
- assertEquals("Sheet with one row should return 0 as lastRowNum",
- 0, sheet.getLastRowNum());
+ assertEquals(0, sheet.getLastRowNum(), "Sheet with one row should return 0 as lastRowNum");
}
@Test
@@ -552,12 +523,10 @@ public abstract class BaseTestRow {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("sheet1");
- assertEquals("Sheet without rows should return -1 as firstRowNum",
- -1, sheet.getFirstRowNum());
+ assertEquals(-1, sheet.getFirstRowNum(), "Sheet without rows should return -1 as firstRowNum");
Row row = sheet.createRow(0);
assertNotNull(row);
- assertEquals("Sheet with one row should return 0 as firstRowNum",
- 0, sheet.getFirstRowNum());
+ assertEquals(0, sheet.getFirstRowNum(), "Sheet with one row should return 0 as firstRowNum");
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Thu Dec 24 18:42:29 2020
@@ -18,15 +18,15 @@
package org.apache.poi.ss.usermodel;
import static org.apache.poi.POITestCase.assertBetween;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -44,7 +44,7 @@ import org.apache.poi.ss.SpreadsheetVers
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PaneInformation;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing {@link org.apache.poi.hssf.usermodel.HSSFCell},
@@ -105,24 +105,24 @@ public abstract class BaseTestSheet {
}
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void createRowBeforeFirstRow() throws IOException {
try (Workbook workbook = _testDataProvider.createWorkbook()) {
final Sheet sh = workbook.createSheet();
sh.createRow(0);
// Negative rows not allowed
- sh.createRow(-1);
+ assertThrows(IllegalArgumentException.class, () -> sh.createRow(-1));
}
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void createRowAfterLastRow() throws IOException {
final SpreadsheetVersion version = _testDataProvider.getSpreadsheetVersion();
try (Workbook workbook = _testDataProvider.createWorkbook()) {
final Sheet sh = workbook.createSheet();
sh.createRow(version.getLastRowIndex());
// Row number must be between 0 and last row
- sh.createRow(version.getLastRowIndex() + 1);
+ assertThrows(IllegalArgumentException.class, () -> sh.createRow(version.getLastRowIndex() + 1));
}
}
@@ -189,12 +189,12 @@ public abstract class BaseTestSheet {
//Check that the cells are not somehow linked
cell.setCellValue(factory.createRichTextString("Difference Check"));
cell2.setCellFormula("cos(2)");
- if ("Difference Check".equals(clonedRow.getCell(0).getRichStringCellValue().getString())) {
- fail("string cell not properly cloned");
- }
- if ("COS(2)".equals(clonedRow.getCell(1).getCellFormula())) {
- fail("formula cell not properly cloned");
- }
+
+ assertNotEquals("Difference Check", clonedRow.getCell(0).getRichStringCellValue().getString(),
+ "string cell not properly cloned");
+
+ assertNotEquals("COS(2)", clonedRow.getCell(1).getCellFormula(), "formula cell not properly cloned");
+
assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
}
@@ -281,34 +281,34 @@ public abstract class BaseTestSheet {
final CellRangeAddress duplicateRegion = new CellRangeAddress(0, 1, 0, 1); //A1:B2
assertThrows(
- "Should not be able to add a merged region (" + duplicateRegion.formatAsString() + ") " +
- "if sheet already contains the same merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(duplicateRegion)
+ () -> sheet.addMergedRegion(duplicateRegion),
+ "Should not be able to add a merged region (" + duplicateRegion.formatAsString() + ") " +
+ "if sheet already contains the same merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress partiallyOverlappingRegion = new CellRangeAddress(1, 2, 1, 2); //B2:C3
assertThrows(
- "Should not be able to add a merged region (" + partiallyOverlappingRegion.formatAsString() + ") " +
- "if it partially overlaps with an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(partiallyOverlappingRegion)
+ () -> sheet.addMergedRegion(partiallyOverlappingRegion),
+ "Should not be able to add a merged region (" + partiallyOverlappingRegion.formatAsString() + ") " +
+ "if it partially overlaps with an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress subsetRegion = new CellRangeAddress(0, 1, 0, 0); //A1:A2
assertThrows(
- "Should not be able to add a merged region (" + subsetRegion.formatAsString() + ") " +
- "if it is a formal subset of an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(subsetRegion)
+ () -> sheet.addMergedRegion(subsetRegion),
+ "Should not be able to add a merged region (" + subsetRegion.formatAsString() + ") " +
+ "if it is a formal subset of an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress supersetRegion = new CellRangeAddress(0, 2, 0, 2); //A1:C3
assertThrows(
- "Should not be able to add a merged region (" + supersetRegion.formatAsString() + ") " +
- "if it is a formal superset of an existing merged region (" + baseRegion.formatAsString() + ")",
IllegalStateException.class,
- () -> sheet.addMergedRegion(supersetRegion)
+ () -> sheet.addMergedRegion(supersetRegion),
+ "Should not be able to add a merged region (" + supersetRegion.formatAsString() + ") " +
+ "if it is a formal superset of an existing merged region (" + baseRegion.formatAsString() + ")"
);
final CellRangeAddress disjointRegion = new CellRangeAddress(10, 11, 10, 11);
@@ -326,9 +326,9 @@ public abstract class BaseTestSheet {
final Sheet sheet = wb.createSheet();
final CellRangeAddress region = CellRangeAddress.valueOf("A1:A1");
assertThrows(
- "Should not be able to add a single-cell merged region (" + region.formatAsString() + ")",
IllegalArgumentException.class,
- () -> sheet.addMergedRegion(region)
+ () -> sheet.addMergedRegion(region),
+ "Should not be able to add a single-cell merged region (" + region.formatAsString() + ")"
);
}
}
@@ -387,27 +387,27 @@ public abstract class BaseTestSheet {
sheet.removeMergedRegion(0);
region = sheet.getMergedRegion(0);
- assertEquals("Left over region should be starting at row 2", 2, region.getFirstRow());
+ assertEquals(2, region.getFirstRow(), "Left over region should be starting at row 2");
sheet.removeMergedRegion(0);
- assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
+ assertEquals(0, sheet.getNumMergedRegions(), "there should be no merged regions left!");
//an, add, remove, get(0) would null pointer
assertEquals(0, sheet.addMergedRegion(region));
- assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+ assertEquals(1, sheet.getNumMergedRegions(), "there should now be one merged region!");
sheet.removeMergedRegion(0);
- assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
+ assertEquals(0, sheet.getNumMergedRegions(), "there should now be zero merged regions!");
//add it again!
region.setLastRow(4);
assertEquals(0, sheet.addMergedRegion(region));
- assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
+ assertEquals(1, sheet.getNumMergedRegions(), "there should now be one merged region!");
//should exist now!
- assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
+ assertTrue(1 <= sheet.getNumMergedRegions(), "there isn't more than one merged region in there");
region = sheet.getMergedRegion(0);
- assertEquals("the merged row to doesn't match the one we put in ", 4, region.getLastRow());
+ assertEquals(4, region.getLastRow(), "the merged row to doesn't match the one we put in ");
}
}
@@ -461,7 +461,7 @@ public abstract class BaseTestSheet {
region = sheet.getMergedRegion(0);
CellRangeAddress expectedRegion = CellRangeAddress.valueOf("A3:B3");
- assertEquals("Merged region should shift down a row", expectedRegion, region);
+ assertEquals(expectedRegion, region, "Merged region should shift down a row");
}
}
@@ -493,9 +493,9 @@ public abstract class BaseTestSheet {
// the safe version of addMergedRegion should throw when trying to add a merged region that overlaps an existing region
assertTrue(sh.getMergedRegions().contains(region2));
assertThrows(
- "region3 overlaps already added merged region2.",
IllegalStateException.class,
- () -> sh.addMergedRegion(region3)
+ () -> sh.addMergedRegion(region3),
+ "region3 overlaps already added merged region2."
);
assertFalse(sh.getMergedRegions().contains(region3));
@@ -504,9 +504,9 @@ public abstract class BaseTestSheet {
// validation methods should detect a problem with previously added merged regions (runs in O(n^2) time)
assertThrows(
- "Sheet contains merged regions A1:B2 and B2:C3, which overlap at B2.",
IllegalStateException.class,
- sh::validateMergedRegions
+ sh::validateMergedRegions,
+ "Sheet contains merged regions A1:B2 and B2:C3, which overlap at B2."
);
}
}
@@ -640,9 +640,10 @@ public abstract class BaseTestSheet {
r.createCell(1).setCellFormula("A1*2");
Sheet s1 = wb.cloneSheet(0);
r = s1.getRow(0);
- assertEquals("double", r.getCell(0).getNumericCellValue(), 1, 0); // sanity check
+ // sanity check
+ assertEquals(r.getCell(0).getNumericCellValue(), 1, 0, "double");
assertNotNull(r.getCell(1));
- assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2");
+ assertEquals(r.getCell(1).getCellFormula(), "A1*2", "formula");
}
}
@@ -660,7 +661,7 @@ public abstract class BaseTestSheet {
Cell cell = row.createCell(0);
CellStyle style2 = cell.getCellStyle();
assertNotNull(style2);
- assertEquals("style should match", style.getIndex(), style2.getIndex());
+ assertEquals(style.getIndex(), style2.getIndex(), "style should match");
}
}
@@ -1187,15 +1188,15 @@ public abstract class BaseTestSheet {
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(5).createCell(1);
- assertEquals("list size before add", 0, sheet.getHyperlinkList().size());
+ assertEquals(0, sheet.getHyperlinkList().size(), "list size before add");
cell.setHyperlink(hyperlink);
- assertEquals("list size after add", 1, sheet.getHyperlinkList().size());
+ assertEquals(1, sheet.getHyperlinkList().size(), "list size after add");
- assertEquals("list", hyperlink, sheet.getHyperlinkList().get(0));
+ assertEquals(hyperlink, sheet.getHyperlinkList().get(0), "list");
CellAddress B6 = new CellAddress(5, 1);
- assertEquals("row, col", hyperlink, sheet.getHyperlink(5, 1));
- assertEquals("addr", hyperlink, sheet.getHyperlink(B6));
- assertNull("no hyperlink at A1", sheet.getHyperlink(CellAddress.A1));
+ assertEquals(hyperlink, sheet.getHyperlink(5, 1), "row, col");
+ assertEquals(hyperlink, sheet.getHyperlink(B6), "addr");
+ assertNull(sheet.getHyperlink(CellAddress.A1), "no hyperlink at A1");
}
}
@@ -1302,9 +1303,8 @@ public abstract class BaseTestSheet {
// active cell behavior is undefined if not set.
// HSSFSheet defaults to A1 active cell, while XSSFSheet defaults to null.
- if (sheet.getActiveCell() != null && !sheet.getActiveCell().equals(CellAddress.A1)) {
- fail("If not set, active cell should default to null or A1");
- }
+ CellAddress ac = sheet.getActiveCell();
+ assertTrue(ac == null || CellAddress.A1.equals(ac), "If not set, active cell should default to null or A1");
sheet.setActiveCell(B42);
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java Thu Dec 24 18:42:29 2020
@@ -17,8 +17,8 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Calendar;
import java.util.Date;
@@ -27,9 +27,9 @@ import java.util.Locale;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* Common superclass for testing automatic sizing of sheet columns
@@ -42,13 +42,13 @@ public abstract class BaseTestSheetAutos
private static Locale userLocale;
- @BeforeClass
+ @BeforeAll
public static void initLocale() {
userLocale = LocaleUtil.getUserLocale();
LocaleUtil.setUserLocale(Locale.ROOT);
}
- @AfterClass
+ @AfterAll
public static void resetLocale() {
LocaleUtil.setUserLocale(userLocale);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org