public class Table extends AbstractSwingUIComponent
Wrapper for JTable components.
The contents of the underlying table can be usually checked with String or Boolean values, as in the following example:
assertTrue(table.contentEquals(new String[]{
{"Bart", "Simpson"},
{"Marge", "Simpson"}
}));
The conversion between the values (Strings) given in the test and the values
actually displayed by the table renderer is performed by a dedicated
TableCellValueConverter
, which retrieves the graphical component that draws
the table cells and determines the displayed value accordingly.
A DefaultTableCellValueConverter
is used by default by the Table component.Modifier and Type | Class and Description |
---|---|
class |
Table.Cell
Represents a table cell.
|
class |
Table.Header |
Modifier and Type | Field and Description |
---|---|
static Class[] |
SWING_CLASSES |
static String |
TYPE_NAME |
Modifier and Type | Method and Description |
---|---|
void |
addRowToSelection(int row) |
Assertion |
backgroundEquals(Object[][] colors)
Checks the background color of the table cells using either Color or String objects
|
Assertion |
backgroundNear(int row,
int column,
Object expected) |
Assertion |
blockEquals(int fromRowIndex,
int fromColumnIndex,
int columnCount,
int rowCount,
Object[][] expected) |
Assertion |
borderEquals(Border[][] borders) |
Assertion |
cellEquals(int row,
int column,
Object expectedValue)
Checks the contents of a given cell.
|
Assertion |
cellEquals(int row,
int column,
Object expectedValue,
TableCellValueConverter converter)
Checks the contents of a given cell using a specific data converter.
|
Assertion |
cellIsEditable(int rowIndex,
int columnIndex) |
Assertion |
cellIsSelected(int rowIndex,
int columnIndex) |
void |
clearSelection() |
void |
click(int row,
int column) |
void |
click(int row,
int column,
Key.Modifier modifier) |
Assertion |
columnCountEquals(int count) |
Assertion |
columnEquals(int columnIndex,
Object[] expectedColumn) |
Assertion |
columnIsEditable(int columnIndex,
boolean isEditable) |
Assertion |
columnIsEditable(String columnName,
boolean shouldBeEditable) |
Assertion |
columnSizeEquals(int columnIndex,
int expectedWidth) |
Assertion |
columnSizeEquals(String columnName,
int expectedWidth) |
Assertion |
containsRow(int columnIndex,
Object cellContent)
Checks that the table contains a row with a given cell.
|
Assertion |
containsRow(Object[] expectedRow)
Checks that the table contains a complete row.
|
Assertion |
contentEquals(Object[][] expected)
Checks the values displayed in the table.
|
Assertion |
contentEquals(String[] columnNames,
Object[][] expected)
Checks the values displayed in the table for a given set of columns.
|
void |
doubleClick(int row,
int column) |
Table.Cell |
editCell(int row,
int column)
Returns a
Table.Cell object for interacting with the content of an individual table cell. |
void |
editCell(int row,
int column,
String value,
boolean validateChange)
Inputs some text in a given cell.
|
Assertion |
endsWith(Object[][] expectedEndRows)
Asserts that the contents of the table ends with the specified rows.
|
Assertion |
foregroundEquals(Object[][] colors)
Checks the foreground color of the table cells using either Color or String objects
|
Assertion |
foregroundNear(int row,
int column,
Object expected) |
JTable |
getAwtComponent()
Returns the Java GUI component represented by this object.
|
int |
getColumnCount() |
int |
getColumnIndex(String columnName) |
Object |
getContentAt(int row,
int column)
Returns the object (String or Boolean) displayed in a given cell.
|
Object |
getContentAt(int row,
int column,
TableCellValueConverter converter)
Returns the value displayed in a given cell using a specific converter.
|
String |
getDescriptionTypeName()
Returns the name of the component as it will appear in the XML representation
returned by
UIComponent.getDescription() . |
Table.Header |
getHeader()
Returns a helper interface which gives access to the table header.
|
JTable |
getJTable() |
int |
getRowCount() |
int |
getRowIndex(int column,
Object value) |
int[] |
getRowIndices(int column,
Object value) |
Component |
getSwingEditorComponentAt(int row,
int column) |
Component |
getSwingRendererComponentAt(int row,
int column) |
Assertion |
hasHeader()
Checks whether a header is displayed for this table.
|
Assertion |
isEditable(boolean[][] expected) |
Assertion |
isEmpty() |
void |
removeRowFromSelection(int row) |
void |
resizeColumn(String columnName,
int width) |
void |
rightClick(int row,
int column) |
Assertion |
rowCountEquals(int count) |
Assertion |
rowEquals(int rowIndex,
int fromColumnIndex,
int columnCount,
Object[] expectedRow) |
Assertion |
rowEquals(int rowIndex,
Object[] expectedRow) |
Assertion |
rowEquals(int rowIndex,
String[] columnNames,
Object[] expected) |
Assertion |
rowIsSelected(int rowIndex) |
Assertion |
rowsAreSelected(int... rowIndexes) |
void |
selectAllRows() |
void |
selectBlock(int top,
int left,
int bottom,
int right) |
void |
selectCell(int row,
int column) |
Assertion |
selectionEquals(boolean[][] expected)
Checks the selection on a cell-by-cell basis.
|
Assertion |
selectionIsEmpty() |
void |
selectRow(int row) |
void |
selectRows(int... rowIndexes) |
void |
selectRowSpan(int start,
int end) |
void |
selectRowsWithText(int column,
String... labels)
Selects all rows where the content of the given column is one of the given labels.
|
void |
setCellValueConverter(int column,
TableCellValueConverter tableCellValueConverter)
Sets a new converter for analyzing the cells of a given column.
|
void |
setDefaultCellValueConverter(TableCellValueConverter cellValueConverter)
Sets a new converter for analyzing the table cells content.
|
Assertion |
startsWith(Object[][] expectedFirstRows)
Asserts that the contents of the table starts with the specified rows.
|
String |
toString() |
Trigger |
triggerClick(int row,
int column,
Key.Modifier modifier) |
Trigger |
triggerDoubleClick(int row,
int column) |
Trigger |
triggerRightClick(int row,
int column) |
tooltipContains, tooltipEquals
addAttributes, backgroundEquals, backgroundNear, foregroundEquals, foregroundNear, getContainer, getContainer, getDescription, getDescription, getLabel, getName, getSubDescription, isEnabled, isVisible, pressKey, releaseKey, typeKey
public static final String TYPE_NAME
public static final Class[] SWING_CLASSES
public Table(JTable table)
public String getDescriptionTypeName()
UIComponent
UIComponent.getDescription()
.public JTable getAwtComponent()
UIComponent
getAwtComponent
in interface UIComponent
getAwtComponent
in class AbstractSwingUIComponent
public JTable getJTable()
public Table.Header getHeader()
public void setDefaultCellValueConverter(TableCellValueConverter cellValueConverter)
public void setCellValueConverter(int column, TableCellValueConverter tableCellValueConverter)
public void click(int row, int column)
public void click(int row, int column, Key.Modifier modifier)
public void rightClick(int row, int column)
public void doubleClick(int row, int column)
public Trigger triggerClick(int row, int column, Key.Modifier modifier)
public Trigger triggerRightClick(int row, int column)
public Trigger triggerDoubleClick(int row, int column)
public int getRowCount()
public Assertion rowCountEquals(int count)
public int getColumnCount()
public Assertion columnCountEquals(int count)
public Object getContentAt(int row, int column)
Returns the object (String or Boolean) displayed in a given cell.
The returned object is that returned by the current TableCellValueConverter used by the table.public Object getContentAt(int row, int column, TableCellValueConverter converter)
public Table.Cell editCell(int row, int column)
Returns a Table.Cell
object for interacting with the content of an individual table cell.
ComboBox comboBox = table.editCell(0, 0).getComboBox();
assertTrue(comboBox.contentEquals(choices));
comboBox.select("b");
public int getRowIndex(int column, Object value)
public int[] getRowIndices(int column, Object value)
public void editCell(int row, int column, String value, boolean validateChange)
Inputs some text in a given cell.
This method only works when the underlying editor is a JTextField or a JComboBox -
it will throw an exception if this is not the case, or if the cell is not editable.
Please refer to editCell(int,int)
for a more flexible edition method.
public Assertion hasHeader()
public Assertion contentEquals(Object[][] expected)
Checks the values displayed in the table.
Sample usage:
assertTrue(table.contentEquals(new Object[][]{
{"a", Boolean.TRUE, "3"},
{"c", Boolean.FALSE, "4"}
}));
The conversion between the displayed values and the objects to
be given in the array can be customized with
setCellValueConverter(int,TableCellValueConverter)
public Assertion blockEquals(int fromRowIndex, int fromColumnIndex, int columnCount, int rowCount, Object[][] expected)
public Assertion contentEquals(String[] columnNames, Object[][] expected)
contentEquals(Object[][])
public Assertion cellEquals(int row, int column, Object expectedValue)
setCellValueConverter(int,TableCellValueConverter)
getContentAt(int,int)
public Assertion cellEquals(int row, int column, Object expectedValue, TableCellValueConverter converter)
setCellValueConverter(int,TableCellValueConverter)
public Assertion rowEquals(int rowIndex, int fromColumnIndex, int columnCount, Object[] expectedRow)
public Assertion isEmpty()
public Assertion foregroundEquals(Object[][] colors)
public Assertion backgroundEquals(Object[][] colors)
public int getColumnIndex(String columnName)
public Assertion isEditable(boolean[][] expected)
public Assertion columnIsEditable(int columnIndex, boolean isEditable)
public Assertion cellIsEditable(int rowIndex, int columnIndex)
public Assertion selectionIsEmpty()
public Assertion selectionEquals(boolean[][] expected)
public Assertion rowIsSelected(int rowIndex)
public Assertion cellIsSelected(int rowIndex, int columnIndex)
public Component getSwingEditorComponentAt(int row, int column)
public Component getSwingRendererComponentAt(int row, int column)
public void resizeColumn(String columnName, int width)
public Assertion columnSizeEquals(int columnIndex, int expectedWidth)
public Assertion rowsAreSelected(int... rowIndexes)
public void selectCell(int row, int column)
public void selectAllRows()
public void selectRow(int row)
public void selectRows(int... rowIndexes)
public void selectRowsWithText(int column, String... labels)
public void selectRowSpan(int start, int end)
public void selectBlock(int top, int left, int bottom, int right)
public void addRowToSelection(int row)
public void removeRowFromSelection(int row)
public void clearSelection()
public Assertion startsWith(Object[][] expectedFirstRows)
public Assertion endsWith(Object[][] expectedEndRows)
public Assertion containsRow(Object[] expectedRow)
Copyright © 2004–2016. All rights reserved.