@InternalApi public class JTableDriver extends JComponentDriver
Supports functional testing of JTable
s.
Note: This class is intended for internal use only. Please use the classes in the package
org.assertj.swing.fixture
in your tests.
robot
Constructor and Description |
---|
JTableDriver(Robot robot)
Creates a new
JTableDriver . |
Modifier and Type | Method and Description |
---|---|
Color |
background(JTable table,
TableCell cell)
Returns the background colour of the given table cell.
|
void |
cancelCellEditing(JTable table,
TableCell cell)
Cancels editing the given cell of the
JTable , using this driver's JTableCellWriter . |
TableCell |
cell(JTable table,
Pattern pattern)
Returns a cell from the given
JTable whose value matches the given regular expression pattern. |
TableCell |
cell(JTable table,
String value)
Returns a cell from the given
JTable whose value matches the given one. |
TableCell |
cell(JTable table,
TableCellFinder cellFinder)
Returns a cell from the given
JTable using the given cell finder. |
Component |
cellEditor(JTable table,
TableCell cell)
Returns the editor in the given cell of the
JTable , using this driver's JTableCellWriter . |
void |
checkCellIndicesInBounds(JTable table,
TableCell cell)
Validates that the given table cell is non
null and its indices are not out of bounds. |
void |
click(JTable table,
TableCell cell,
MouseButton mouseButton,
int times)
Clicks the given cell, using the specified mouse button, the given number of times.
|
int |
columnIndex(JTable table,
Object columnId)
Returns the index of the column in the given
JTable whose id matches the given one. |
String[][] |
contents(JTable table)
|
void |
drag(JTable table,
TableCell cell)
Starts a drag operation at the location of the given table cell.
|
void |
drop(JTable table,
TableCell cell)
Starts a drop operation at the location of the given table cell.
|
void |
enterValueInCell(JTable table,
TableCell cell,
String value)
Enters the given value in the given cell of the
JTable , using this driver's JTableCellWriter . |
Font |
font(JTable table,
TableCell cell)
Returns the font of the given table cell.
|
Color |
foreground(JTable table,
TableCell cell)
Returns the foreground colour of the given table cell.
|
Point |
pointAt(JTable table,
TableCell cell)
Converts the given table cell into a coordinate pair.
|
void |
replaceCellReader(JTableCellReader newCellReader)
Updates the implementation of
JTableCellReader to use when comparing internal values of a JTable
and the values expected in a test. |
void |
replaceCellWriter(JTableCellWriter newCellWriter)
Updates the implementation of
JTableCellWriter to use to edit cell values in a JTable . |
void |
requireCellValue(JTable table,
TableCell cell,
Pattern pattern)
Asserts that the value of the given cell matches the given regular expression pattern.
|
void |
requireCellValue(JTable table,
TableCell cell,
String value)
Asserts that the value of the given cell matches the given value.
|
void |
requireColumnCount(JTable table,
int columnCount)
Asserts that the given
JTable has the given number of columns. |
void |
requireContents(JTable table,
String[][] contents)
Asserts that the
String representation of the cell values in the JTable is equal to the given
String array. |
void |
requireEditable(JTable table,
TableCell cell)
Asserts that the given table cell is editable.
|
void |
requireNoSelection(JTable table)
Verifies that the
JTable does not have any selection. |
void |
requireNotEditable(JTable table,
TableCell cell)
Asserts that the given table cell is not editable.
|
void |
requireRowCount(JTable table,
int rowCount)
Asserts that the given
JTable has the given number of rows. |
void |
requireSelectedRows(JTable table,
int... rows)
Asserts that the set of selected rows in the given
JTable contains to the given row indices. |
int |
rowCountOf(JTable table)
Returns the number of rows that can be shown in the given
JTable , given unlimited space. |
void |
selectCell(JTable table,
TableCell cell)
Selects the given cell, if it is not selected already.
|
void |
selectCells(JTable table,
TableCell[] cells)
Selects the given cells of the
JTable . |
String |
selectionValue(JTable table)
Returns the
String representation of the value of the selected cell, using this driver's
JTableCellReader . |
void |
selectRows(JTable table,
int... rows)
Simulates a user selecting the given rows in the given
JTable . |
JPopupMenu |
showPopupMenuAt(JTable table,
TableCell cell)
Shows a pop-up menu at the given table cell.
|
void |
startCellEditing(JTable table,
TableCell cell)
Starts editing the given cell of the
JTable , using this driver's JTableCellWriter . |
void |
stopCellEditing(JTable table,
TableCell cell)
Stops editing the given cell of the
JTable , using this driver's JTableCellWriter . |
JTableHeader |
tableHeaderOf(JTable table)
Returns the
JTableHeader of the given JTable . |
void |
unselectCell(JTable table,
TableCell cell)
Unselects the given cell, if it is selected.
|
void |
unselectCells(JTable table,
TableCell[] cells)
Unselects the given cells of the
JTable . |
void |
unselectRows(JTable table,
int... rows)
Simulates a user unselecting the given rows in the given
JTable . |
String |
value(JTable table,
int row,
int column)
Returns the
String representation of the value at the given row and column, using this driver's
JTableCellReader . |
String |
value(JTable table,
TableCell cell)
Returns the
String representation of the value at the given cell, using this driver's
JTableCellReader . |
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
doResizeHeight, doResizeWidth, isResizable, move, resize
backgroundOf, checkClickAllowed, checkInEdtEnabledAndShowing, checkInEdtShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, drop, focus, focusAndWaitForFocusGain, fontOf, foregroundOf, invokePopupMenu, invokePopupMenu, moveMouseIgnoringAnyError, moveMouseIgnoringAnyError, performAccessibleActionOf, pressAndReleaseKey, pressAndReleaseKey, pressAndReleaseKeys, pressKey, pressKeyWhileRunning, propertyName, releaseKey, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireSize, requireVisible, rightClick, settings, waitForShowing
public JTableDriver(@Nonnull Robot robot)
JTableDriver
.robot
- the robot to use to simulate user events.@RunsInEDT @Nullable public JTableHeader tableHeaderOf(@Nonnull JTable table)
JTableHeader
of the given JTable
.table
- the given JTable
.JTableHeader
of the given JTable
.@RunsInEDT @Nullable public String selectionValue(@Nonnull JTable table)
String
representation of the value of the selected cell, using this driver's
JTableCellReader
.table
- the target JTable
.String
representation of the value of the selected cell.replaceCellReader(JTableCellReader)
@RunsInEDT @Nonnull public TableCell cell(@Nonnull JTable table, @Nonnull TableCellFinder cellFinder)
JTable
using the given cell finder.table
- the target JTable
.cellFinder
- knows how to find a cell.NullPointerException
- if cellFinder
is null
.IndexOutOfBoundsException
- if the row or column indices in the found cell are out of bounds.ActionFailedException
- if a matching cell could not be found.@RunsInEDT @Nonnull public TableCell cell(@Nonnull JTable table, @Nullable String value)
JTable
whose value matches the given one.table
- the target JTable
.value
- the value of the cell to look for. It can be a regular expression.JTable
whose value matches the given one.ActionFailedException
- if a cell with a matching value cannot be found.@RunsInEDT @Nonnull public TableCell cell(@Nonnull JTable table, @Nonnull Pattern pattern)
JTable
whose value matches the given regular expression pattern.table
- the target JTable
.pattern
- the regular expression pattern to matchJTable
whose value matches the given one.NullPointerException
- if the given regular expression is null
.ActionFailedException
- if a cell with a matching value cannot be found.@RunsInEDT @Nullable public String value(@Nonnull JTable table, @Nonnull TableCell cell)
String
representation of the value at the given cell, using this driver's
JTableCellReader
.table
- the target JTable
.cell
- the table cell.String
representation of the value at the given cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.replaceCellReader(JTableCellReader)
@RunsInEDT @Nullable public String value(@Nonnull JTable table, int row, int column)
String
representation of the value at the given row and column, using this driver's
JTableCellReader
.table
- the target JTable
.row
- the given row.column
- the given column.String
representation of the value at the given row and column.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.replaceCellReader(JTableCellReader)
@RunsInEDT @Nullable public Font font(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public Color background(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.ActionFailedException
- if the cell is null
.ActionFailedException
- if any of the indices (row and column) is out of bounds.@RunsInEDT @Nullable public Color foreground(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.public void selectCells(@Nonnull JTable table, @Nonnull TableCell[] cells)
JTable
.table
- the target JTable
.cells
- the cells to select.NullPointerException
- if cells
is null
or empty.IllegalArgumentException
- if cells
is null
or empty.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.NullPointerException
- if any element in cells
is null
.IndexOutOfBoundsException
- if any of the indices of any of the cells
are out of bounds.public void unselectCells(@Nonnull JTable table, @Nonnull TableCell[] cells)
JTable
.table
- the target JTable
.cells
- the cells to select.NullPointerException
- if cells
is null
or empty.IllegalArgumentException
- if cells
is null
or empty.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.NullPointerException
- if any element in cells
is null
.IndexOutOfBoundsException
- if any of the indices of any of the cells
are out of bounds.@RunsInEDT public void requireNoSelection(@Nonnull JTable table)
JTable
does not have any selection.table
- the target JTable
.AssertionError
- is the JTable
has a selection.@RunsInEDT public void selectCell(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the cell to select.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public void unselectCell(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the cell to unselect.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public void click(@Nonnull JTable table, @Nonnull TableCell cell, @Nonnull MouseButton mouseButton, @Nonnegative int times)
table
- the target JTable
.cell
- the table cell.mouseButton
- the mouse button to use.times
- the number of times to click the cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public void drag(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public void drop(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT @Nonnull public JPopupMenu showPopupMenuAt(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled. Or if the JTable
is not showing on the
screen.ComponentLookupException
- if a pop-up menu cannot be found.@RunsInEDT @Nonnull public Point pointAt(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the table cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.@RunsInEDT public void requireContents(@Nonnull JTable table, @Nonnull String[][] contents)
String
representation of the cell values in the JTable
is equal to the given
String
array. This method uses this driver's JTableCellReader
to read the values of the table cells
as String
s.table
- the target JTable
.contents
- the expected String
representation of the cell values in the JTable
.replaceCellReader(JTableCellReader)
@RunsInEDT @Nonnull public String[][] contents(@Nonnull JTable table)
table
- the target JTable
.String
representation of the cells in the JTable
.replaceCellReader(JTableCellReader)
@RunsInEDT public void requireCellValue(@Nonnull JTable table, @Nonnull TableCell cell, @Nullable String value)
table
- the target JTable
.cell
- the given table cell.value
- the expected value. It can be a regular expression.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.AssertionError
- if the value of the given cell does not match the given value.@RunsInEDT public void requireCellValue(@Nonnull JTable table, @Nonnull TableCell cell, @Nonnull Pattern pattern)
table
- the target JTable
.cell
- the given table cell.pattern
- the regular expression pattern to match.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.NullPointerException
- if the given regular expression pattern is null
.AssertionError
- if the value of the given cell does not match the given regular expression pattern.@RunsInEDT public void enterValueInCell(@Nonnull JTable table, @Nonnull TableCell cell, @Nonnull String value)
JTable
, using this driver's JTableCellWriter
.table
- the target JTable
.cell
- the given cell.value
- the given value.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IllegalStateException
- if the JTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.ActionFailedException
- if this driver's JTableCellValueReader
is unable to enter the given value.replaceCellWriter(JTableCellWriter)
@RunsInEDT public void requireEditable(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the given table cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.AssertionError
- if the given table cell is not editable.@RunsInEDT public void requireNotEditable(@Nonnull JTable table, @Nonnull TableCell cell)
table
- the target JTable
.cell
- the given table cell.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.AssertionError
- if the given table cell is editable.@RunsInEDT public Component cellEditor(@Nonnull JTable table, @Nonnull TableCell cell)
JTable
, using this driver's JTableCellWriter
.table
- the target JTable
.cell
- the given cell.JTable
.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.replaceCellWriter(JTableCellWriter)
@RunsInEDT public void startCellEditing(@Nonnull JTable table, @Nonnull TableCell cell)
JTable
, using this driver's JTableCellWriter
. This method
should be called before manipulating the Component
returned by cellEditor(JTable, TableCell)
.table
- the target JTable
.cell
- the given cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IllegalStateException
- if the JTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.ActionFailedException
- if this writer is unable to handle the underlying cell editor.replaceCellWriter(JTableCellWriter)
@RunsInEDT public void stopCellEditing(@Nonnull JTable table, @Nonnull TableCell cell)
JTable
, using this driver's JTableCellWriter
. This method
should be called after manipulating the Component
returned by cellEditor(JTable, TableCell)
.table
- the target JTable
.cell
- the given cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IllegalStateException
- if the JTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.ActionFailedException
- if this writer is unable to handle the underlying cell editor.replaceCellWriter(JTableCellWriter)
@RunsInEDT public void cancelCellEditing(@Nonnull JTable table, @Nonnull TableCell cell)
JTable
, using this driver's JTableCellWriter
. This method
should be called after manipulating the Component
returned by cellEditor(JTable, TableCell)
.table
- the target JTable
.cell
- the given cell.NullPointerException
- if the cell is null
.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IllegalStateException
- if the JTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.ActionFailedException
- if this writer is unable to handle the underlying cell editor.replaceCellWriter(JTableCellWriter)
@RunsInEDT public void checkCellIndicesInBounds(@Nonnull JTable table, @Nonnull TableCell cell)
null
and its indices are not out of bounds.table
- the target JTable
.cell
- to validate.NullPointerException
- if the cell is null
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.public void replaceCellReader(@Nonnull JTableCellReader newCellReader)
JTableCellReader
to use when comparing internal values of a JTable
and the values expected in a test.newCellReader
- the new JTableCellValueReader
to use.NullPointerException
- if newCellReader
is null
.public void replaceCellWriter(JTableCellWriter newCellWriter)
JTableCellWriter
to use to edit cell values in a JTable
.newCellWriter
- the new JTableCellWriter
to use.NullPointerException
- if newCellWriter
is null
.@RunsInEDT public int rowCountOf(@Nonnull JTable table)
JTable
, given unlimited space.table
- the target JTable
.JTable
.JTable.getRowCount()
@RunsInEDT public int columnIndex(@Nonnull JTable table, @Nonnull Object columnId)
JTable
whose id matches the given one.table
- the target JTable
.columnId
- the id of the column to look for.ActionFailedException
- if a column with a matching id could not be found.@RunsInEDT public void requireRowCount(@Nonnull JTable table, int rowCount)
JTable
has the given number of rows.table
- the target JTable
.rowCount
- the expected number of rows.AssertionError
- if the given JTable
does not have the given number of rows.@RunsInEDT public void requireColumnCount(@Nonnull JTable table, int columnCount)
JTable
has the given number of columns.table
- the target JTable
.columnCount
- the expected number of columns.AssertionError
- if the given JTable
does not have the given number of columns.@RunsInEDT public void selectRows(@Nonnull JTable table, @Nonnull int... rows)
JTable
.table
- the target JTable
.rows
- the indices of the row to select.NullPointerException
- if the given array of indices is null
.IllegalArgumentException
- if the given array of indices is empty.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the given indices is negative, or equal to or greater than the number
of rows in the JTable
.@RunsInEDT public void unselectRows(@Nonnull JTable table, @Nonnull int... rows)
JTable
.table
- the target JTable
.rows
- the indices of the row to unselect.NullPointerException
- if the given array of indices is null
.IllegalArgumentException
- if the given array of indices is empty.IllegalStateException
- if the JTable
is disabled.IllegalStateException
- if the JTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the given indices is negative, or equal to or greater than the number
of rows in the JTable
.@RunsInEDT public void requireSelectedRows(@Nonnull JTable table, @Nonnull int... rows)
JTable
contains to the given row indices.table
- the target JTable
.rows
- the indices of the rows expected to be selected.AssertionError
- if the sets of selected rows in the given JTable
(if any) do not contain the given
row indices.Copyright © 2014–2019 AssertJ. All rights reserved.