From b7bd08760b067ddf52e7aa5bbd0c8c08dc4c3732 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 10 Jun 2016 18:45:14 +0000 Subject: [PATCH] bug 57840: add unit tests for XSSFTable methods; rename XSSFTable.getNumerOfMappedColumns() to getNumberOfMappedColumn() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747771 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFTable.java | 14 ++- .../poi/xssf/usermodel/TestXSSFSheet.java | 2 +- .../poi/xssf/usermodel/TestXSSFTable.java | 91 +++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java index f0cc0c61b5..f4b5ee9067 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -243,15 +243,25 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) */ - public long getNumerOfMappedColumns() { + public long getNumberOfMappedColumns() { return ctTable.getTableColumns().getCount(); } + + /** + * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) + * @deprecated 3.15 beta 2. Use {@link #getNumberOfMappedColumns}. + */ + public long getNumerOfMappedColumns() { + return getNumberOfMappedColumns(); + } + /** * @return The reference for the cell in the top-left part of the table * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) * + * Does not track updates to underlying changes to CTTable */ public CellReference getStartCellReference() { if (startCellReference==null) { @@ -269,6 +279,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * @return The reference for the cell in the bottom-right part of the table * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) * + * Does not track updates to underlying changes to CTTable */ public CellReference getEndCellReference() { if (endCellReference==null) { @@ -284,6 +295,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { /** * @return the total number of rows in the selection. (Note: in this version autofiltering is ignored) * + * Does not track updates to underlying changes to CTTable */ public int getRowCount() { CellReference from = getStartCellReference(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 868557ae15..70df48c2df 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -1273,7 +1273,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { for(XSSFTable table : tables) { System.out.println("XPath: " + table.getCommonXpath()); System.out.println("Name: " + table.getName()); - System.out.println("Mapped Cols: " + table.getNumerOfMappedColumns()); + System.out.println("Mapped Cols: " + table.getNumberOfMappedColumns()); System.out.println("Rowcount: " + table.getRowCount()); System.out.println("End Cell: " + table.getEndCellReference()); System.out.println("Start Cell: " + table.getStartCellReference()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java index 534cfd92de..c5ecd440f9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java @@ -18,7 +18,9 @@ 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.assertTrue; import java.io.File; @@ -29,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.streaming.SXSSFWorkbook; @@ -134,4 +137,92 @@ public final class TestXSSFTable { wb.close(); } + @Test + public void getSheetName() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals("Table", table.getSheetName()); + wb.close(); + } + + @Test + public void isHasTotalsRow() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertFalse(table.isHasTotalsRow()); + wb.close(); + } + + @Test + public void getStartColIndex() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(0, table.getStartColIndex()); + wb.close(); + } + + @Test + public void getEndColIndex() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(2, table.getEndColIndex()); + wb.close(); + } + + @Test + public void getStartRowIndex() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(0, table.getStartRowIndex()); + wb.close(); + } + + @Test + public void getEndRowIndex() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(6, table.getEndRowIndex()); + wb.close(); + } + + @Test + public void getStartCellReference() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(new CellReference("A1"), table.getStartCellReference()); + wb.close(); + } + + @Test + public void getEndCellReference() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(new CellReference("C7"), table.getEndCellReference()); + wb.close(); + } + + @Test + public void getNumberOfMappedColumns() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals(3, table.getNumberOfMappedColumns()); + wb.close(); + } + + @Test + public void getAndSetDisplayName() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx"); + XSSFTable table = wb.getTable("\\_Prime.1"); + assertEquals("\\_Prime.1", table.getDisplayName()); + + table.setDisplayName(null); + assertNull(table.getDisplayName()); + assertEquals("\\_Prime.1", table.getName()); // name and display name are different + + table.setDisplayName("Display name"); + assertEquals("Display name", table.getDisplayName()); + assertEquals("\\_Prime.1", table.getName()); // name and display name are different + + wb.close(); + } } -- 2.39.5