Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java Thu Dec 24 18:42:29 2020 @@ -17,11 +17,12 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertEquals; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Arrays; @@ -62,7 +63,7 @@ import org.apache.poi.ss.usermodel.Sheet import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class TestXSSFFormulaParser { private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla) { @@ -80,38 +81,31 @@ public final class TestXSSFFormulaParser ptgs = parse(fpb, "ABC10"); assertEquals(1, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); + assertTrue(ptgs[0] instanceof RefPtg, "Had " + Arrays.toString(ptgs)); ptgs = parse(fpb, "A500000"); assertEquals(1, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); + assertTrue(ptgs[0] instanceof RefPtg, "Had " + Arrays.toString(ptgs)); ptgs = parse(fpb, "ABC500000"); assertEquals(1, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); + assertTrue(ptgs[0] instanceof RefPtg, "Had " + Arrays.toString(ptgs)); //highest allowed rows and column (XFD and 0x100000) ptgs = parse(fpb, "XFD1048576"); assertEquals(1, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); + assertTrue(ptgs[0] instanceof RefPtg, "Had " + Arrays.toString(ptgs)); //column greater than XFD - try { - /*ptgs =*/ parse(fpb, "XFE10"); - fail("expected exception"); - } catch (FormulaParseException e){ - assertEquals("Specified named range 'XFE10' does not exist in the current workbook.", e.getMessage()); - } + FormulaParseException e; + e = assertThrows(FormulaParseException.class, () -> parse(fpb, "XFE10")); + assertEquals("Specified named range 'XFE10' does not exist in the current workbook.", e.getMessage()); //row greater than 0x100000 - try { - /*ptgs =*/ parse(fpb, "XFD1048577"); - fail("expected exception"); - } catch (FormulaParseException e){ - assertEquals("Specified named range 'XFD1048577' does not exist in the current workbook.", e.getMessage()); - } - + e = assertThrows(FormulaParseException.class, () -> parse(fpb, "XFD1048577")); + assertEquals("Specified named range 'XFD1048577' does not exist in the current workbook.", e.getMessage()); + // Formula referencing one cell ptgs = parse(fpb, "ISEVEN(A1)"); assertEquals(3, ptgs.length); @@ -121,7 +115,7 @@ public final class TestXSSFFormulaParser assertEquals("ISEVEN", ptgs[0].toFormulaString()); assertEquals("A1", ptgs[1].toFormulaString()); assertEquals("#external#", ptgs[2].toFormulaString()); - + // Formula referencing an area ptgs = parse(fpb, "SUM(A1:B3)"); assertEquals(2, ptgs.length); @@ -129,7 +123,7 @@ public final class TestXSSFFormulaParser assertEquals(AttrPtg.class, ptgs[1].getClass()); assertEquals("A1:B3", ptgs[0].toFormulaString()); assertEquals("SUM", ptgs[1].toFormulaString()); - + // Formula referencing one cell in a different sheet ptgs = parse(fpb, "SUM(Sheet1!A1)"); assertEquals(2, ptgs.length); @@ -137,7 +131,7 @@ public final class TestXSSFFormulaParser assertEquals(AttrPtg.class, ptgs[1].getClass()); assertEquals("Sheet1!A1", ptgs[0].toFormulaString()); assertEquals("SUM", ptgs[1].toFormulaString()); - + // Formula referencing an area in a different sheet ptgs = parse(fpb, "SUM(Sheet1!A1:B3)"); assertEquals(2, ptgs.length); @@ -157,16 +151,16 @@ public final class TestXSSFFormulaParser ptgs = parse(fpb, "LOG10"); assertEquals(1, ptgs.length); - assertTrue("",(ptgs[0] instanceof RefPtg)); + assertTrue(ptgs[0] instanceof RefPtg); ptgs = parse(fpb, "LOG10(100)"); assertEquals(2, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof IntPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof FuncPtg); + assertTrue(ptgs[0] instanceof IntPtg); + assertTrue(ptgs[1] instanceof FuncPtg); wb.close(); } - + @Test public void formulaReferencesSameWorkbook() throws IOException { // Use a test file with "other workbook" style references @@ -187,7 +181,7 @@ public final class TestXSSFFormulaParser wb.close(); } - + @Test public void formulaReferencesOtherSheets() throws IOException { // Use a test file with the named ranges in place @@ -202,7 +196,7 @@ public final class TestXSSFFormulaParser assertEquals(-1, ((Ref3DPxg)ptgs[0]).getExternalWorkbookNumber()); assertEquals("A1", ((Ref3DPxg)ptgs[0]).format2DRefAsString()); assertEquals("Uses!A1", ptgs[0].toFormulaString()); - + // Reference to a single cell in a different sheet, which needs quoting ptgs = parse(fpb, "'Testing 47100'!A1"); assertEquals(1, ptgs.length); @@ -211,7 +205,7 @@ public final class TestXSSFFormulaParser assertEquals("Testing 47100", ((Ref3DPxg)ptgs[0]).getSheetName()); assertEquals("A1", ((Ref3DPxg)ptgs[0]).format2DRefAsString()); assertEquals("'Testing 47100'!A1", ptgs[0].toFormulaString()); - + // Reference to a sheet scoped named range from another sheet ptgs = parse(fpb, "Defines!NR_To_A1"); assertEquals(1, ptgs.length); @@ -220,7 +214,7 @@ public final class TestXSSFFormulaParser assertEquals("Defines", ((NameXPxg)ptgs[0]).getSheetName()); assertEquals("NR_To_A1",((NameXPxg)ptgs[0]).getNameName()); assertEquals("Defines!NR_To_A1", ptgs[0].toFormulaString()); - + // Reference to a workbook scoped named range ptgs = parse(fpb, "NR_Global_B2"); assertEquals(1, ptgs.length); @@ -229,7 +223,7 @@ public final class TestXSSFFormulaParser wb.close(); } - + @Test public void formulaReferencesOtherWorkbook() throws IOException { // Use a test file with the external linked table in place @@ -245,7 +239,7 @@ public final class TestXSSFFormulaParser assertEquals("Uses",((Ref3DPxg)ptgs[0]).getSheetName()); assertEquals("$A$1",((Ref3DPxg)ptgs[0]).format2DRefAsString()); assertEquals("[1]Uses!$A$1", ptgs[0].toFormulaString()); - + // Reference to a sheet-scoped named range in a different workbook ptgs = parse(fpb, "[1]Defines!NR_To_A1"); assertEquals(1, ptgs.length); @@ -254,7 +248,7 @@ public final class TestXSSFFormulaParser assertEquals("Defines", ((NameXPxg)ptgs[0]).getSheetName()); assertEquals("NR_To_A1",((NameXPxg)ptgs[0]).getNameName()); assertEquals("[1]Defines!NR_To_A1", ptgs[0].toFormulaString()); - + // Reference to a global named range in a different workbook ptgs = parse(fpb, "[1]!NR_Global_B2"); assertEquals(1, ptgs.length); @@ -266,15 +260,15 @@ public final class TestXSSFFormulaParser wb.close(); } - + /** * A handful of functions (such as SUM, COUNTA, MIN) support * multi-sheet references (eg Sheet1:Sheet3!A1 = Cell A1 from - * Sheets 1 through Sheet 3) and multi-sheet area references + * Sheets 1 through Sheet 3) and multi-sheet area references * (eg Sheet1:Sheet3!A1:B2 = Cells A1 through B2 from Sheets * 1 through Sheet 3). * This test, based on common test files for HSSF and XSSF, checks - * that we can read and parse these kinds of references + * that we can read and parse these kinds of references * (but not evaluate - that's elsewhere in the test suite) */ @Test @@ -286,42 +280,42 @@ public final class TestXSSFFormulaParser for (Workbook wb : wbs) { Sheet s1 = wb.getSheetAt(0); Ptg[] ptgs; - + // Check the contents Cell sumF = s1.getRow(2).getCell(0); assertNotNull(sumF); assertEquals("SUM(Sheet1:Sheet3!A1)", sumF.getCellFormula()); - + Cell avgF = s1.getRow(2).getCell(1); assertNotNull(avgF); assertEquals("AVERAGE(Sheet1:Sheet3!A1)", avgF.getCellFormula()); - + Cell countAF = s1.getRow(2).getCell(2); assertNotNull(countAF); assertEquals("COUNTA(Sheet1:Sheet3!C1)", countAF.getCellFormula()); - + Cell maxF = s1.getRow(4).getCell(1); assertNotNull(maxF); assertEquals("MAX(Sheet1:Sheet3!A$1)", maxF.getCellFormula()); - - + + Cell sumFA = s1.getRow(2).getCell(7); assertNotNull(sumFA); assertEquals("SUM(Sheet1:Sheet3!A1:B2)", sumFA.getCellFormula()); - + Cell avgFA = s1.getRow(2).getCell(8); assertNotNull(avgFA); assertEquals("AVERAGE(Sheet1:Sheet3!A1:B2)", avgFA.getCellFormula()); - + Cell maxFA = s1.getRow(4).getCell(8); assertNotNull(maxFA); assertEquals("MAX(Sheet1:Sheet3!A$1:B$2)", maxFA.getCellFormula()); - + Cell countFA = s1.getRow(5).getCell(8); assertNotNull(countFA); assertEquals("COUNT(Sheet1:Sheet3!$A$1:$B$2)", countFA.getCellFormula()); - - + + // Create a formula parser final FormulaParsingWorkbook fpb; if (wb instanceof HSSFWorkbook) @@ -395,7 +389,7 @@ public final class TestXSSFFormulaParser Cell newF = s1.getRow(0).createCell(10, CellType.FORMULA); newF.setCellFormula("SUM(Sheet2:Sheet3!A1)"); assertEquals("SUM(Sheet2:Sheet3!A1)", newF.getCellFormula()); - + // Check we can round-trip - try to set a new one to a cell range newF = s1.getRow(0).createCell(11, CellType.FORMULA); newF.setCellFormula("MIN(Sheet1:Sheet2!A1:B2)"); @@ -414,17 +408,15 @@ public final class TestXSSFFormulaParser @Test public void test58648Single() throws IOException { - XSSFWorkbook wb = new XSSFWorkbook(); - XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); - Ptg[] ptgs; - - ptgs = parse(fpb, "(ABC10 )"); - assertEquals("Had: " + Arrays.toString(ptgs), - 2, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); + Ptg[] ptgs; - wb.close(); + ptgs = parse(fpb, "(ABC10 )"); + assertEquals(2, ptgs.length, "Had: " + Arrays.toString(ptgs)); + assertTrue(ptgs[0] instanceof RefPtg, "Had " + Arrays.toString(ptgs)); + assertTrue(ptgs[1] instanceof ParenthesisPtg, "Had " + Arrays.toString(ptgs)); + } } @Test @@ -435,43 +427,37 @@ public final class TestXSSFFormulaParser // verify whitespaces in different places ptgs = parse(fpb, "(ABC10)"); - assertEquals("Had: " + Arrays.toString(ptgs), - 2, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); + assertEquals(2, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); ptgs = parse(fpb, "( ABC10)"); - assertEquals("Had: " + Arrays.toString(ptgs), - 2, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); + assertEquals(2, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); ptgs = parse(fpb, "(ABC10 )"); - assertEquals("Had: " + Arrays.toString(ptgs), - 2, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); + assertEquals(2, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); ptgs = parse(fpb, "((ABC10))"); - assertEquals("Had: " + Arrays.toString(ptgs), - 3, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof ParenthesisPtg); + assertEquals(3, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); + assertTrue(ptgs[2] instanceof ParenthesisPtg); ptgs = parse(fpb, "((ABC10) )"); - assertEquals("Had: " + Arrays.toString(ptgs), - 3, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof ParenthesisPtg); + assertEquals(3, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); + assertTrue(ptgs[2] instanceof ParenthesisPtg); ptgs = parse(fpb, "( (ABC10))"); - assertEquals("Had: " + Arrays.toString(ptgs), - 3, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof ParenthesisPtg); + assertEquals(3, ptgs.length); + assertTrue(ptgs[0] instanceof RefPtg); + assertTrue(ptgs[1] instanceof ParenthesisPtg); + assertTrue(ptgs[2] instanceof ParenthesisPtg); wb.close(); } @@ -515,41 +501,36 @@ public final class TestXSSFFormulaParser // verify whitespaces in different places ptgs = parse(fpb, "INTERCEPT(A2:A5, B2:B5)"); - assertEquals("Had: " + Arrays.toString(ptgs), - 3, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof FuncPtg); + assertEquals(3, ptgs.length); + assertTrue(ptgs[0] instanceof AreaPtg); + assertTrue(ptgs[1] instanceof AreaPtg); + assertTrue(ptgs[2] instanceof FuncPtg); ptgs = parse(fpb, " INTERCEPT ( \t \r A2 : \nA5 , B2 : B5 ) \t"); - assertEquals("Had: " + Arrays.toString(ptgs), - 3, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof FuncPtg); + assertEquals(3, ptgs.length); + assertTrue(ptgs[0] instanceof AreaPtg); + assertTrue(ptgs[1] instanceof AreaPtg); + assertTrue(ptgs[2] instanceof FuncPtg); ptgs = parse(fpb, "(VLOOKUP(\"item1\", A2:B3, 2, FALSE) - VLOOKUP(\"item2\", A2:B3, 2, FALSE) )"); - assertEquals("Had: " + Arrays.toString(ptgs), - 12, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof StringPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof IntPtg); + assertEquals(12, ptgs.length); + assertTrue(ptgs[0] instanceof StringPtg); + assertTrue(ptgs[1] instanceof AreaPtg); + assertTrue(ptgs[2] instanceof IntPtg); ptgs = parse(fpb, "A1:B1 B1:B2"); - assertEquals("Had: " + Arrays.toString(ptgs), - 4, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof MemAreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof IntersectionPtg); + assertEquals(4, ptgs.length); + assertTrue(ptgs[0] instanceof MemAreaPtg); + assertTrue(ptgs[1] instanceof AreaPtg); + assertTrue(ptgs[2] instanceof AreaPtg); + assertTrue(ptgs[3] instanceof IntersectionPtg); ptgs = parse(fpb, "A1:B1 B1:B2"); - assertEquals("Had: " + Arrays.toString(ptgs), - 4, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof MemAreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof IntersectionPtg); + assertEquals(4, ptgs.length); + assertTrue(ptgs[0] instanceof MemAreaPtg); + assertTrue(ptgs[1] instanceof AreaPtg); + assertTrue(ptgs[2] instanceof AreaPtg); + assertTrue(ptgs[3] instanceof IntersectionPtg); wb.close(); } @@ -562,20 +543,18 @@ public final class TestXSSFFormulaParser // verify whitespaces in different places ptgs = parse(fpb, "SUM(A1:INDEX(1:1048576,MAX(IFERROR(MATCH(99^99,B:B,1),0),IFERROR(MATCH(\"zzzz\",B:B,1),0)),MAX(IFERROR(MATCH(99^99,1:1,1),0),IFERROR(MATCH(\"zzzz\",1:1,1),0))))"); - assertEquals("Had: " + Arrays.toString(ptgs), - 40, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof MemFuncPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof NameXPxg); + assertEquals(40, ptgs.length); + assertTrue(ptgs[0] instanceof MemFuncPtg); + assertTrue(ptgs[1] instanceof RefPtg); + assertTrue(ptgs[2] instanceof AreaPtg); + assertTrue(ptgs[3] instanceof NameXPxg); ptgs = parse(fpb, "SUM ( A1 : INDEX( 1 : 1048576 , MAX( IFERROR ( MATCH ( 99 ^ 99 , B : B , 1 ) , 0 ) , IFERROR ( MATCH ( \"zzzz\" , B:B , 1 ) , 0 ) ) , MAX ( IFERROR ( MATCH ( 99 ^ 99 , 1 : 1 , 1 ) , 0 ) , IFERROR ( MATCH ( \"zzzz\" , 1 : 1 , 1 ) , 0 ) ) ) )"); - assertEquals("Had: " + Arrays.toString(ptgs), - 40, ptgs.length); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof MemFuncPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof RefPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg); - assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof NameXPxg); + assertEquals(40, ptgs.length); + assertTrue(ptgs[0] instanceof MemFuncPtg); + assertTrue(ptgs[1] instanceof RefPtg); + assertTrue(ptgs[2] instanceof AreaPtg); + assertTrue(ptgs[3] instanceof NameXPxg); wb.close(); } @@ -632,42 +611,42 @@ public final class TestXSSFFormulaParser ////// Case 1: Evaluate "Table1[col]" //////// ptgs = parse(fpb, tbl+"[Name]"); assertEquals(1, ptgs.length); - assertEquals("Table1[col]", "Table!B2:B7", ptgs[0].toFormulaString()); + assertEquals("Table!B2:B7", ptgs[0].toFormulaString(), "Table1[col]"); ////// Case 2: Evaluate "Table1[[#Totals],[col]]" //////// ptgs = parse(fpb, tbl+"[[#Totals],[col]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Totals],[col]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]); + assertEquals(ErrPtg.REF_INVALID, ptgs[0], "Table1[[#Totals],[col]]" + noTotalsRowReason); ////// Case 3: Evaluate "Table1[#Totals]" //////// ptgs = parse(fpb, tbl+"[#Totals]"); assertEquals(1, ptgs.length); - assertEquals("Table1[#Totals]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]); + assertEquals(ErrPtg.REF_INVALID, ptgs[0], "Table1[#Totals]" + noTotalsRowReason); ////// Case 4: Evaluate "Table1[#All]" //////// ptgs = parse(fpb, tbl+"[#All]"); assertEquals(1, ptgs.length); - assertEquals("Table1[#All]", "Table!A1:C7", ptgs[0].toFormulaString()); + assertEquals("Table!A1:C7", ptgs[0].toFormulaString(), "Table1[#All]"); ////// Case 5: Evaluate "Table1[#Data]" (excludes Header and Data rows) //////// ptgs = parse(fpb, tbl+"[#Data]"); assertEquals(1, ptgs.length); - assertEquals("Table1[#Data]", "Table!A2:C7", ptgs[0].toFormulaString()); + assertEquals("Table!A2:C7", ptgs[0].toFormulaString(), "Table1[#Data]"); ////// Case 6: Evaluate "Table1[#Headers]" //////// ptgs = parse(fpb, tbl+"[#Headers]"); assertEquals(1, ptgs.length); - assertEquals("Table1[#Headers]", "Table!A1:C1", ptgs[0].toFormulaString()); + assertEquals("Table!A1:C1", ptgs[0].toFormulaString(), "Table1[#Headers]"); ////// Case 7: Evaluate "Table1[#Totals]" //////// ptgs = parse(fpb, tbl+"[#Totals]"); assertEquals(1, ptgs.length); - assertEquals("Table1[#Totals]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]); + assertEquals(ErrPtg.REF_INVALID, ptgs[0], "Table1[#Totals]" + noTotalsRowReason); ////// Case 8: Evaluate "Table1[#This Row]" //////// ptgs = parse(fpb, tbl+"[#This Row]", 2); assertEquals(1, ptgs.length); - assertEquals("Table1[#This Row]", "Table!A3:C3", ptgs[0].toFormulaString()); + assertEquals("Table!A3:C3", ptgs[0].toFormulaString(), "Table1[#This Row]"); ////// Evaluate "Table1[@]" (equivalent to "Table1[#This Row]") //////// ptgs = parse(fpb, tbl+"[@]", 2); @@ -677,70 +656,70 @@ public final class TestXSSFFormulaParser ////// Evaluate "Table1[#This Row]" when rowIndex is outside Table //////// ptgs = parse(fpb, tbl+"[#This Row]", 10); assertEquals(1, ptgs.length); - assertEquals("Table1[#This Row]", ErrPtg.VALUE_INVALID, ptgs[0]); + assertEquals(ErrPtg.VALUE_INVALID, ptgs[0], "Table1[#This Row]"); ////// Evaluate "Table1[@]" when rowIndex is outside Table //////// ptgs = parse(fpb, tbl+"[@]", 10); assertEquals(1, ptgs.length); - assertEquals("Table1[@]", ErrPtg.VALUE_INVALID, ptgs[0]); + assertEquals(ErrPtg.VALUE_INVALID, ptgs[0], "Table1[@]"); ////// Evaluate "Table1[[#Data],[col]]" //////// ptgs = parse(fpb, tbl+"[[#Data], [Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Data],[col]]", "Table!C2:C7", ptgs[0].toFormulaString()); + assertEquals("Table!C2:C7", ptgs[0].toFormulaString(), "Table1[[#Data],[col]]"); ////// Case 9: Evaluate "Table1[[#All],[col]]" //////// ptgs = parse(fpb, tbl+"[[#All], [Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#All],[col]]", "Table!C1:C7", ptgs[0].toFormulaString()); + assertEquals("Table!C1:C7", ptgs[0].toFormulaString(), "Table1[[#All],[col]]"); ////// Case 10: Evaluate "Table1[[#Headers],[col]]" //////// ptgs = parse(fpb, tbl+"[[#Headers], [Number]]"); assertEquals(1, ptgs.length); // also acceptable: Table1!B1 - assertEquals("Table1[[#Headers],[col]]", "Table!C1:C1", ptgs[0].toFormulaString()); + assertEquals("Table!C1:C1", ptgs[0].toFormulaString(), "Table1[[#Headers],[col]]"); ////// Case 11: Evaluate "Table1[[#Totals],[col]]" //////// ptgs = parse(fpb, tbl+"[[#Totals],[Name]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Totals],[col]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]); + assertEquals(ErrPtg.REF_INVALID, ptgs[0], "Table1[[#Totals],[col]]" + noTotalsRowReason); ////// Case 12: Evaluate "Table1[[#All],[col1]:[col2]]" //////// ptgs = parse(fpb, tbl+"[[#All], [Name]:[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#All],[col1]:[col2]]", "Table!B1:C7", ptgs[0].toFormulaString()); + assertEquals("Table!B1:C7", ptgs[0].toFormulaString(), "Table1[[#All],[col1]:[col2]]"); ////// Case 13: Evaluate "Table1[[#Data],[col]:[col2]]" //////// ptgs = parse(fpb, tbl+"[[#Data], [Name]:[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Data],[col]:[col2]]", "Table!B2:C7", ptgs[0].toFormulaString()); + assertEquals("Table!B2:C7", ptgs[0].toFormulaString(), "Table1[[#Data],[col]:[col2]]"); ////// Case 14: Evaluate "Table1[[#Headers],[col1]:[col2]]" //////// ptgs = parse(fpb, tbl+"[[#Headers], [Name]:[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Headers],[col1]:[col2]]", "Table!B1:C1", ptgs[0].toFormulaString()); + assertEquals("Table!B1:C1", ptgs[0].toFormulaString(), "Table1[[#Headers],[col1]:[col2]]"); ////// Case 15: Evaluate "Table1[[#Totals],[col]:[col2]]" //////// ptgs = parse(fpb, tbl+"[[#Totals], [Name]:[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Totals],[col]:[col2]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]); + assertEquals(ErrPtg.REF_INVALID, ptgs[0], "Table1[[#Totals],[col]:[col2]]" + noTotalsRowReason); ////// Case 16: Evaluate "Table1[[#Headers],[#Data],[col]]" //////// ptgs = parse(fpb, tbl+"[[#Headers],[#Data],[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[#Headers],[#Data],[col]]", "Table!C1:C7", ptgs[0].toFormulaString()); + assertEquals("Table!C1:C7", ptgs[0].toFormulaString(), "Table1[[#Headers],[#Data],[col]]"); ////// Case 17: Evaluate "Table1[[#This Row], [col1]]" //////// ptgs = parse(fpb, tbl+"[[#This Row], [Number]]", 2); assertEquals(1, ptgs.length); // also acceptable: Table!C3 - assertEquals("Table1[[#This Row], [col1]]", "Table!C3:C3", ptgs[0].toFormulaString()); + assertEquals("Table!C3:C3", ptgs[0].toFormulaString(), "Table1[[#This Row], [col1]]"); ////// Case 18: Evaluate "Table1[[col]:[col2]]" //////// ptgs = parse(fpb, tbl+"[[Name]:[Number]]"); assertEquals(1, ptgs.length); - assertEquals("Table1[[col]:[col2]]", "Table!B2:C7", ptgs[0].toFormulaString()); + assertEquals("Table!B2:C7", ptgs[0].toFormulaString(), "Table1[[col]:[col2]]"); wb.close(); }
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooterProperties.java Thu Dec 24 18:42:29 2020 @@ -17,27 +17,27 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestXSSFHeaderFooterProperties { - + private XSSFWorkbook wb; private XSSFSheet sheet; private XSSFHeaderFooterProperties hfProp; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); hfProp = sheet.getHeaderFooterProperties(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Thu Dec 24 18:42:29 2020 @@ -27,11 +27,11 @@ import org.apache.poi.ss.util.CellAddres import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public final class TestXSSFHyperlink extends BaseTestHyperlink { public TestXSSFHyperlink() { @@ -98,23 +98,19 @@ public final class TestXSSFHyperlink ext @Test public void testInvalidURLs() throws IOException { - XSSFWorkbook workbook = new XSSFWorkbook(); - XSSFCreationHelper createHelper = workbook.getCreationHelper(); + try (XSSFWorkbook workbook = new XSSFWorkbook()) { + XSSFCreationHelper createHelper = workbook.getCreationHelper(); - String[] invalidURLs = { + String[] invalidURLs = { "http:\\apache.org", "www.apache .org", "c:\\temp", "\\poi"}; - for(String s : invalidURLs){ - try { - createHelper.createHyperlink(HyperlinkType.URL).setAddress(s); - fail("expected IllegalArgumentException: " + s); - } catch (IllegalArgumentException e){ - // expected here + for (String s : invalidURLs) { + assertThrows(IllegalArgumentException.class, + () -> createHelper.createHyperlink(HyperlinkType.URL).setAddress(s)); } } - workbook.close(); } @Test @@ -312,24 +308,24 @@ public final class TestXSSFHyperlink ext CellAddress A7 = new CellAddress("A7"); XSSFHyperlink link = sh.getHyperlink(A2); - assertEquals("address", "A2", link.getCellRef()); - assertEquals("link type", HyperlinkType.URL, link.getType()); - assertEquals("link target", "http://twitter.com/#!/apacheorg", link.getAddress()); + assertEquals("A2", link.getCellRef(), "address"); + assertEquals(HyperlinkType.URL, link.getType(), "link type"); + assertEquals("http://twitter.com/#!/apacheorg", link.getAddress(), "link target"); link = sh.getHyperlink(A3); - assertEquals("address", "A3", link.getCellRef()); - assertEquals("link type", HyperlinkType.URL, link.getType()); - assertEquals("link target", "http://www.bailii.org/databases.html#ie", link.getAddress()); + assertEquals("A3", link.getCellRef(), "address"); + assertEquals(HyperlinkType.URL, link.getType(), "link type"); + assertEquals("http://www.bailii.org/databases.html#ie", link.getAddress(), "link target"); link = sh.getHyperlink(A4); - assertEquals("address", "A4", link.getCellRef()); - assertEquals("link type", HyperlinkType.URL, link.getType()); - assertEquals("link target", "https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress()); + assertEquals("A4", link.getCellRef(), "address"); + assertEquals(HyperlinkType.URL, link.getType(), "link type"); + assertEquals("https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress(), "link target"); link = sh.getHyperlink(A7); - assertEquals("address", "A7", link.getCellRef()); - assertEquals("link type", HyperlinkType.DOCUMENT, link.getType()); - assertEquals("link target", "Sheet1", link.getAddress()); + assertEquals("A7", link.getCellRef(), "address"); + assertEquals(HyperlinkType.DOCUMENT, link.getType(), "link type"); + assertEquals("Sheet1", link.getAddress(), "link target"); wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java Thu Dec 24 18:42:29 2020 @@ -17,16 +17,16 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.Arrays; -import org.junit.Test; import org.apache.poi.ss.usermodel.BaseTestNamedRange; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFITestDataProvider; +import org.junit.jupiter.api.Test; /** * @author Yegor Kozlov @@ -76,7 +76,7 @@ public final class TestXSSFName extends // Save and re-open XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb); wb.close(); - + assertEquals(1, nwb.getNumberOfNames()); nr1 = nwb.getName(XSSFName.BUILTIN_PRINT_TITLE); @@ -142,12 +142,8 @@ public final class TestXSSFName extends // Cell addresses/references are not allowed for (String ref : Arrays.asList("A1", "$A$1", "A1:B2")) { - try { - name.setNameName(ref); - fail("cell addresses are not allowed: " + ref); - } catch (final IllegalArgumentException e) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> name.setNameName(ref), + "cell addresses are not allowed: " + ref); } // Name that looks similar to a cell reference but is outside the cell reference row and column limits Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddFooter.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestXSSFOddFooter { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFOddHeader.java Thu Dec 24 18:42:29 2020 @@ -17,24 +17,24 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestXSSFOddHeader { - + private XSSFWorkbook wb; private XSSFSheet sheet; - - @Before + + @BeforeEach public void before() { wb = new XSSFWorkbook(); sheet = wb.createSheet(); } - - @After + + @AfterEach public void after() throws Exception { wb.close(); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.xssf.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.io.IOException; import java.util.List; @@ -29,7 +29,7 @@ import org.apache.poi.ss.usermodel.Clien import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs; Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java Thu Dec 24 18:42:29 2020 @@ -17,17 +17,17 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +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 static org.junit.jupiter.api.Assertions.assertSame; import java.io.IOException; import java.util.List; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yegor Kozlov @@ -129,7 +129,7 @@ public final class TestXSSFPictureData { List<XSSFShape> shapes1 = sheet1.createDrawingPatriarch().getShapes(); assertNotNull(shapes1); assertEquals(5, shapes1.size()); - + for(int i = 0; i < wb.getNumberOfSheets(); i++){ XSSFSheet sheet = wb.getSheetAt(i); XSSFDrawing drawing = sheet.createDrawingPatriarch(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableName.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableName.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableName.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableName.java Thu Dec 24 18:42:29 2020 @@ -20,7 +20,7 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.CellReference; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; /** * Test pivot tables created by named range @@ -28,7 +28,7 @@ import org.junit.Before; public class TestXSSFPivotTableName extends BaseTestXSSFPivotTable { @Override - @Before + @BeforeEach public void setUp(){ wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); @@ -67,9 +67,9 @@ public class TestXSSFPivotTableName exte XSSFName namedRange = sheet.getWorkbook().createName(); namedRange.setRefersToFormula(sheet.getSheetName() + "!" + "A1:C2"); pivotTable = sheet.createPivotTable(namedRange, new CellReference("H5")); - + XSSFSheet offsetSheet = wb.createSheet(); - + Row tableRow_1 = offsetSheet.createRow(1); offsetOuterCell = tableRow_1.createCell(1); offsetOuterCell.setCellValue(-1); @@ -79,7 +79,7 @@ public class TestXSSFPivotTableName exte tableCell_1_2.setCellValue("Exponent"); Cell tableCell_1_3 = tableRow_1.createCell(4); tableCell_1_3.setCellValue("10^Exponent"); - + Row tableRow_2 = offsetSheet.createRow(2); Cell tableCell_2_1 = tableRow_2.createCell(2); tableCell_2_1.setCellValue(0); @@ -87,7 +87,7 @@ public class TestXSSFPivotTableName exte tableCell_2_2.setCellValue(0); Cell tableCell_2_3 = tableRow_2.createCell(4); tableCell_2_3.setCellValue(1); - + Row tableRow_3= offsetSheet.createRow(3); Cell tableCell_3_1 = tableRow_3.createCell(2); tableCell_3_1.setCellValue(1); @@ -95,7 +95,7 @@ public class TestXSSFPivotTableName exte tableCell_3_2.setCellValue(1); Cell tableCell_3_3 = tableRow_3.createCell(4); tableCell_3_3.setCellValue(10); - + Row tableRow_4 = offsetSheet.createRow(4); Cell tableCell_4_1 = tableRow_4.createCell(2); tableCell_4_1.setCellValue(2); @@ -103,7 +103,7 @@ public class TestXSSFPivotTableName exte tableCell_4_2.setCellValue(2); Cell tableCell_4_3 = tableRow_4.createCell(4); tableCell_4_3.setCellValue(100); - + namedRange = sheet.getWorkbook().createName(); namedRange.setRefersToFormula("C2:E4"); namedRange.setSheetIndex(sheet.getWorkbook().getSheetIndex(sheet)); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableRef.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableRef.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableRef.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTableRef.java Thu Dec 24 18:42:29 2020 @@ -21,15 +21,15 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellReference; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; /** * Test pivot tables created by area reference */ public class TestXSSFPivotTableRef extends BaseTestXSSFPivotTable { - + @Override - @Before + @BeforeEach public void setUp(){ wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); @@ -67,9 +67,9 @@ public class TestXSSFPivotTableRef exten AreaReference source = wb.getCreationHelper().createAreaReference("A1:C2"); pivotTable = sheet.createPivotTable(source, new CellReference("H5")); - + XSSFSheet offsetSheet = wb.createSheet(); - + Row tableRow_1 = offsetSheet.createRow(1); offsetOuterCell = tableRow_1.createCell(1); offsetOuterCell.setCellValue(-1); @@ -79,7 +79,7 @@ public class TestXSSFPivotTableRef exten tableCell_1_2.setCellValue("Exponent"); Cell tableCell_1_3 = tableRow_1.createCell(4); tableCell_1_3.setCellValue("10^Exponent"); - + Row tableRow_2 = offsetSheet.createRow(2); Cell tableCell_2_1 = tableRow_2.createCell(2); tableCell_2_1.setCellValue(0); @@ -87,7 +87,7 @@ public class TestXSSFPivotTableRef exten tableCell_2_2.setCellValue(0); Cell tableCell_2_3 = tableRow_2.createCell(4); tableCell_2_3.setCellValue(1); - + Row tableRow_3= offsetSheet.createRow(3); Cell tableCell_3_1 = tableRow_3.createCell(2); tableCell_3_1.setCellValue(1); @@ -95,7 +95,7 @@ public class TestXSSFPivotTableRef exten tableCell_3_2.setCellValue(1); Cell tableCell_3_3 = tableRow_3.createCell(4); tableCell_3_3.setCellValue(10); - + Row tableRow_4 = offsetSheet.createRow(4); Cell tableCell_4_1 = tableRow_4.createCell(2); tableCell_4_1.setCellValue(2); @@ -103,7 +103,7 @@ public class TestXSSFPivotTableRef exten tableCell_4_2.setCellValue(2); Cell tableCell_4_3 = tableRow_4.createCell(4); tableCell_4_3.setCellValue(100); - + AreaReference offsetSource = wb.getCreationHelper().createAreaReference( new CellReference("C2"), new CellReference("E4")); offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6")); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java Thu Dec 24 18:42:29 2020 @@ -22,7 +22,7 @@ import org.apache.poi.ss.usermodel.Paper import org.apache.poi.ss.usermodel.PrintCellComments; import org.apache.poi.ss.usermodel.PrintOrientation; import org.apache.poi.xssf.XSSFITestDataProvider; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; @@ -30,9 +30,9 @@ import org.openxmlformats.schemas.spread import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder; -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; /** * Tests for {@link XSSFPrintSetup} @@ -254,23 +254,23 @@ public class TestXSSFPrintSetup { XSSFSheet s1 = wb.createSheet(); assertFalse(s1.getCTWorksheet().isSetPageSetup()); assertTrue(s1.getCTWorksheet().isSetPageMargins()); - + XSSFPrintSetup print = s1.getPrintSetup(); assertTrue(s1.getCTWorksheet().isSetPageSetup()); assertTrue(s1.getCTWorksheet().isSetPageMargins()); - + print.setCopies((short)3); print.setLandscape(true); assertEquals(3, print.getCopies()); assertTrue(print.getLandscape()); - + XSSFSheet s2 = wb.createSheet(); assertFalse(s2.getCTWorksheet().isSetPageSetup()); assertTrue(s2.getCTWorksheet().isSetPageMargins()); - + // Round trip and check XSSFWorkbook wbBack = XSSFITestDataProvider.instance.writeOutAndReadBack(wb); - + s1 = wbBack.getSheetAt(0); s2 = wbBack.getSheetAt(1); @@ -278,11 +278,11 @@ public class TestXSSFPrintSetup { assertTrue(s1.getCTWorksheet().isSetPageMargins()); assertFalse(s2.getCTWorksheet().isSetPageSetup()); assertTrue(s2.getCTWorksheet().isSetPageMargins()); - + print = s1.getPrintSetup(); assertEquals(3, print.getCopies()); assertTrue(print.getLandscape()); - + wb.close(); } @@ -298,12 +298,12 @@ public class TestXSSFPrintSetup { @Test public void testSetLandscapeFalse() { XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance()); - + assertFalse(ps.getLandscape()); - + ps.setLandscape(true); assertTrue(ps.getLandscape()); - + ps.setLandscape(false); assertFalse(ps.getLandscape()); } @@ -311,12 +311,12 @@ public class TestXSSFPrintSetup { @Test public void testSetLeftToRight() { XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance()); - + assertFalse(ps.getLeftToRight()); - + ps.setLeftToRight(true); assertTrue(ps.getLeftToRight()); - + ps.setLeftToRight(false); assertFalse(ps.getLeftToRight()); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java Thu Dec 24 18:42:29 2020 @@ -17,13 +17,14 @@ package org.apache.poi.xssf.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.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.Assertions.fail; import java.io.IOException; import java.util.TreeMap; @@ -33,7 +34,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.StylesTable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; @@ -124,13 +125,7 @@ public final class TestXSSFRichTextStrin StylesTable tbl = new StylesTable(); rt.setStylesTableReference(tbl); - - try { - rt.applyFont(0, 10, (short)1); - fail("Fails without styles in the table"); - } catch (IndexOutOfBoundsException e) { - // expected - } + assertThrows(IndexOutOfBoundsException.class, () -> rt.applyFont(0, 10, (short)1), "Fails without styles in the table"); tbl.putFont(new XSSFFont()); rt.applyFont(0, 10, (short)1); @@ -142,27 +137,15 @@ public final class TestXSSFRichTextStrin XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); rt.applyFont(0, 0, (short)1); + IllegalArgumentException e; + e = assertThrows(IllegalArgumentException.class, () -> rt.applyFont(11, 10, (short)1)); + assertTrue(e.getMessage().contains("11")); + + e = assertThrows(IllegalArgumentException.class, () -> rt.applyFont(-1, 10, (short)1)); + assertTrue(e.getMessage().contains("-1")); - try { - rt.applyFont(11, 10, (short)1); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("11")); - } - - try { - rt.applyFont(-1, 10, (short)1); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("-1")); - } - - try { - rt.applyFont(0, 555, (short)1); - fail("Should catch Exception here"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("555")); - } + e = assertThrows(IllegalArgumentException.class, () -> rt.applyFont(0, 555, (short)1)); + assertTrue(e.getMessage().contains("555")); } @Test Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java Thu Dec 24 18:42:29 2020 @@ -17,9 +17,9 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; import java.io.IOException; @@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for XSSFRow @@ -96,38 +96,38 @@ public final class TestXSSFRow extends B col = 0; Cell cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("RefPtg", "B6", cell.getCellFormula()); + assertEquals("B6", cell.getCellFormula(), "RefPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "src!B6", cell.getCellFormula()); + assertEquals("src!B6", cell.getCellFormula(), "Ref3DPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "dest!B6", cell.getCellFormula()); + assertEquals("dest!B6", cell.getCellFormula(), "Ref3DPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "other!B6", cell.getCellFormula()); + assertEquals("other!B6", cell.getCellFormula(), "Ref3DPtg"); ///////////////////////////////////////////// //Test 2D and 3D Ref Ptgs with absolute row (Ptg row number shouldn't change) cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("RefPtg", "B$5", cell.getCellFormula()); + assertEquals("B$5", cell.getCellFormula(), "RefPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "src!B$5", cell.getCellFormula()); + assertEquals("src!B$5", cell.getCellFormula(), "Ref3DPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "dest!B$5", cell.getCellFormula()); + assertEquals("dest!B$5", cell.getCellFormula(), "Ref3DPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Ref3DPtg", "other!B$5", cell.getCellFormula()); + assertEquals("other!B$5", cell.getCellFormula(), "Ref3DPtg"); ////////////////////////////////////////// @@ -136,19 +136,19 @@ public final class TestXSSFRow extends B // to maintain topLeft:bottomRight order cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Area2DPtg", "SUM(B$5:D6)", cell.getCellFormula()); + assertEquals("SUM(B$5:D6)", cell.getCellFormula(), "Area2DPtg"); cell = destRow.getCell(col++); assertNotNull(cell); - assertEquals("Area3DPtg", "SUM(src!B$5:D6)", cell.getCellFormula()); + assertEquals("SUM(src!B$5:D6)", cell.getCellFormula(), "Area3DPtg"); cell = destRow.getCell(col++); assertNotNull(destRow.getCell(6)); - assertEquals("Area3DPtg", "SUM(dest!B$5:D6)", cell.getCellFormula()); + assertEquals("SUM(dest!B$5:D6)", cell.getCellFormula(), "Area3DPtg"); cell = destRow.getCell(col++); assertNotNull(destRow.getCell(7)); - assertEquals("Area3DPtg", "SUM(other!B$5:D6)", cell.getCellFormula()); + assertEquals("SUM(other!B$5:D6)", cell.getCellFormula(), "Area3DPtg"); workbook.close(); } @@ -179,19 +179,19 @@ public final class TestXSSFRow extends B // to the new row (and allow the old row to be garbage collected) // this is mostly so existing references to rows that are overwritten are updated // rather than allowing users to continue updating rows that are no longer part of the sheet - assertSame("existing references to srcRow are still valid", srcRow, sheet1.getRow(0)); - assertSame("existing references to destRow are still valid", destRow, sheet1.getRow(1)); - assertSame("existing references to observerRow are still valid", observerRow, sheet1.getRow(2)); - assertSame("existing references to externObserverRow are still valid", externObserverRow, sheet2.getRow(0)); + assertSame(srcRow, sheet1.getRow(0), "existing references to srcRow are still valid"); + assertSame(destRow, sheet1.getRow(1), "existing references to destRow are still valid"); + assertSame(observerRow, sheet1.getRow(2), "existing references to observerRow are still valid"); + assertSame(externObserverRow, sheet2.getRow(0), "existing references to externObserverRow are still valid"); // Make sure copyRowFrom actually copied row (this is tested elsewhere) assertEquals(CellType.STRING, destRow.getCell(0).getCellType()); assertEquals("hello", destRow.getCell(0).getStringCellValue()); // We don't want #REF! errors if we copy a row that contains cells that are referred to by other cells outside of copied region - assertEquals("references to overwritten cells are unmodified", "A2", observerRow.getCell(0).getCellFormula()); - assertEquals("references to overwritten cells are unmodified", "B2", observerRow.getCell(1).getCellFormula()); - assertEquals("references to overwritten cells are unmodified", "Sheet1!A2", externObserverRow.getCell(0).getCellFormula()); + assertEquals("A2", observerRow.getCell(0).getCellFormula(), "references to overwritten cells are unmodified"); + assertEquals("B2", observerRow.getCell(1).getCellFormula(), "references to overwritten cells are unmodified"); + assertEquals("Sheet1!A2", externObserverRow.getCell(0).getCellFormula(), "references to overwritten cells are unmodified"); workbook.close(); } @@ -220,19 +220,15 @@ public final class TestXSSFRow extends B XSSFTestDataSamples.writeOutAndReadBack(wb1); assertEquals("hello", srcRow.getCell(0).getStringCellValue()); - assertEquals("hello", - wb1.getSheet("Sheet1").getRow(0).getCell(0).getStringCellValue()); + assertEquals("hello", wb1.getSheet("Sheet1").getRow(0).getCell(0).getStringCellValue()); assertEquals("cruel", srcRow.getCell(1).getStringCellValue()); - assertEquals("cruel", - wb1.getSheet("Sheet1").getRow(0).getCell(1).getStringCellValue()); + assertEquals("cruel", wb1.getSheet("Sheet1").getRow(0).getCell(1).getStringCellValue()); assertEquals("world", srcRow.getCell(3).getStringCellValue()); - assertEquals("world", - wb1.getSheet("Sheet1").getRow(0).getCell(3).getStringCellValue()); + assertEquals("world", wb1.getSheet("Sheet1").getRow(0).getCell(3).getStringCellValue()); srcRow.getCell(1).setCellValue((RichTextString) null); XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb1); - assertEquals("Cell should be blank", CellType.BLANK, - wb3.getSheet("Sheet1").getRow(0).getCell(1).getCellType()); + assertEquals(CellType.BLANK, wb3.getSheet("Sheet1").getRow(0).getCell(1).getCellType(), "Cell should be blank"); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFShape.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFShape.java?rev=1884783&r1=1884782&r2=1884783&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFShape.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFShape.java Thu Dec 24 18:42:29 2020 @@ -17,14 +17,14 @@ package org.apache.poi.xssf.usermodel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.List; import org.apache.poi.xssf.XSSFTestDataSamples; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for XSSFShape @@ -64,8 +64,7 @@ public final class TestXSSFShape { str.append(", Row1:").append(((XSSFClientAnchor) shape.getAnchor()).getRow1()); str.append(", Row2:").append(((XSSFClientAnchor) shape.getAnchor()).getRow2()); } - - assertEquals("Having shapes: " + str, - expectedShapes, shapes.size()); + + assertEquals(expectedShapes, shapes.size(), "Having shapes: " + str); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org