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
This commit is contained in:
Javen O'Neal 2016-06-10 18:45:14 +00:00
parent 71e3aa52fd
commit c8627bb8b2
3 changed files with 105 additions and 2 deletions

View File

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

View File

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

View File

@ -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();
}
}