Package org.fest.swing.driver
Class JTableDriver
java.lang.Object
org.fest.swing.driver.ComponentDriver
org.fest.swing.driver.ContainerDriver
org.fest.swing.driver.JComponentDriver
org.fest.swing.driver.JTableDriver
Understands functional testing of
JTable
s:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture
in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JTableCellReader
private JTableCellWriter
private static final String
private static final String
private final JTableLocation
private static final String
private static final String
private static final String
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
assertNoSelection
(JTable table) background
(JTable table, TableCell cell) Returns the background color of the given table cell.void
cancelCellEditing
(JTable table, TableCell cell) Cancels editing the given cell of the
, using this driver'sJTable
.JTableCellWriter
Returns a cell from the given
whose value matches the given one.JTable
Returns a cell from the given
whose value matches the given regular expression pattern.JTable
cell
(JTable table, TableCellFinder cellFinder) Returns a cell from the given
using the given cell finder.JTable
private static Color
cellBackground
(JTable table, TableCell cell, JTableCellReader cellReader) cellEditor
(JTable table, TableCell cell) Returns the editor in the given cell of the
, using this driver'sJTable
.JTableCellWriter
private static Font
cellFont
(JTable table, TableCell cell, JTableCellReader cellReader) private static Color
cellForeground
(JTable table, TableCell cell, JTableCellReader cellReader) private static org.fest.assertions.Description
cellProperty
(JTable table, String propertyName) (package private) JTableCellReader
void
cellReader
(JTableCellReader newCellReader) Updates the implementation of
to use when comparing internal values of aJTableCellReader
and the values expected in a test.JTable
cellSelectionInfo
(JTable table, int row, int column, JTableLocation location) private static String
cellValue
(JTable table, int row, int column, JTableCellReader cellReader) private static String
cellValue
(JTable table, TableCell cell, JTableCellReader cellReader) private org.fest.assertions.Description
cellValueProperty
(JTable table, TableCell cell) void
cellWriter
(JTableCellWriter newCellWriter) Updates the implementation of
to use to edit cell values in aJTableCellWriter
.JTable
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
whose id matches the given one.JTable
String[][]
void
Starts a drag operation at the location of the given table cell.void
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
, using this driver'sJTable
.JTableCellWriter
private static ActionFailedException
failColumnIndexNotFound
(Object columnId) private static void
failNotEqual
(String[][] actual, String[][] expected, org.fest.assertions.Description description) private static int
findColumnIndex
(JTable table, Object columnId) Returns the font of the given table cell.foreground
(JTable table, TableCell cell) Returns the foreground color of the given table cell.Converts the given table cell into a coordinate pair.private static Point
pointAtCell
(JTable table, TableCell cell, JTableLocation location) void
requireCellValue
(JTable table, TableCell cell, String value) Asserts that the value of the given cell matches the given value.void
requireCellValue
(JTable table, TableCell cell, Pattern pattern) Asserts that the value of the given cell matches the given regular expression pattern.void
requireColumnCount
(JTable table, int columnCount) Asserts that the given
has the given number of columns.JTable
void
requireContents
(JTable table, String[][] contents) Asserts that theString
representation of the cell values in the
is equal to the givenJTable
String
array.void
requireEditable
(JTable table, TableCell cell) Asserts that the given table cell is editable.private static void
requireEditableEqualTo
(JTable table, TableCell cell, boolean editable) void
requireNoSelection
(JTable table) Verifies that the
does not have any selection.JTable
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
has the given number of rows.JTable
void
requireSelectedRows
(JTable table, int... rows) Asserts that the set of selected rows in the given
contains to the given row indices.JTable
int
rowCountOf
(JTable table) Returns the number of rows that can be shown in the given
, given unlimited space.JTable
private static void
scrollToCell
(JTable table, int row, int column, JTableLocation location) private static void
scrollToCell
(JTable table, TableCell cell, JTableLocation location) private static Point
scrollToPointAtCell
(JTable table, TableCell cell, JTableLocation location) private void
selectCell
(JTable table, int row, int column) 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
private static int[]
selectedRowsOf
(JTable table) selectionValue
(JTable table) Returns theString
representation of the value of the selected cell, using this driver's
.JTableCellReader
private static String
selectionValue
(JTable table, JTableCellReader cellReader) void
selectRows
(JTable table, int... rows) Simulates a user selecting the given rows in the given
.JTable
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
, using this driver'sJTable
.JTableCellWriter
void
stopCellEditing
(JTable table, TableCell cell) Stops editing the given cell of the
, using this driver'sJTable
.JTableCellWriter
tableHeaderOf
(JTable table) Returns the
of the givenJTableHeader
.JTable
void
Validates that the given table cell is nonnull
and its indices are not out of bounds.private static void
validateCellIndexBounds
(JTable table, TableCell cell) private void
validateCellsToSelect
(TableCell[] cells) Returns theString
representation of the value at the given row and column, using this driver's
.JTableCellReader
Returns theString
representation of the value at the given cell, using this driver's
.JTableCellReader
Methods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
Methods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidth
Methods inherited from class org.fest.swing.driver.ComponentDriver
assertIsEnabledAndShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, focus, focusAndWaitForFocusGain, invokePopupMenu, invokePopupMenu, moveMouseIgnoringAnyError, moveMouseIgnoringAnyError, performAccessibleActionOf, pressAndReleaseKey, pressAndReleaseKey, pressAndReleaseKeys, pressKey, propertyName, releaseKey, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireSize, requireVisible, rightClick, settings, waitForShowing
-
Field Details
-
CONTENTS_PROPERTY
- See Also:
-
EDITABLE_PROPERTY
- See Also:
-
SELECTED_ROWS_PROPERTY
- See Also:
-
SELECTION_PROPERTY
- See Also:
-
VALUE_PROPERTY
- See Also:
-
location
-
cellReader
-
cellWriter
-
-
Constructor Details
-
JTableDriver
Creates a newJTableDriver
.- Parameters:
robot
- the robot to use to simulate user events.
-
-
Method Details
-
tableHeaderOf
Returns the
of the givenJTableHeader
.JTable
- Parameters:
table
- the givenJTable
.- Returns:
- the
JTableHeader
of the givenJTable
.
-
selectionValue
Returns theString
representation of the value of the selected cell, using this driver's
.JTableCellReader
- Parameters:
table
- the targetJTable
.- Returns:
- the
String
representation of the value of the selected cell. - See Also:
-
selectionValue
-
cell
Returns a cell from the given
using the given cell finder.JTable
- Parameters:
table
- the targetJTable
.cellFinder
- knows how to find a cell.- Returns:
- the found cell, if any.
- Throws:
NullPointerException
- ifcellFinder
isnull
.IndexOutOfBoundsException
- if the row or column indices in the found cell are out of bounds.ActionFailedException
- if a matching cell could not be found.
-
cell
Returns a cell from the given
whose value matches the given one.JTable
- Parameters:
table
- the targetJTable
.value
- the value of the cell to look for. It can be a regular expression.- Returns:
- a cell from the given
JTable
whose value matches the given one. - Throws:
ActionFailedException
- if a cell with a matching value cannot be found.
-
cell
Returns a cell from the given
whose value matches the given regular expression pattern.JTable
- Parameters:
table
- the targetJTable
.pattern
- the regular expression pattern to match- Returns:
- a cell from the given
JTable
whose value matches the given one. - Throws:
NullPointerException
- if the given regular expression isnull
.ActionFailedException
- if a cell with a matching value cannot be found.- Since:
- 1.2
-
value
Returns theString
representation of the value at the given cell, using this driver's
.JTableCellReader
- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the
String
representation of the value at the given cell. - Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.- See Also:
-
cellValue
@RunsInEDT private static String cellValue(JTable table, TableCell cell, JTableCellReader cellReader) -
value
Returns theString
representation of the value at the given row and column, using this driver's
.JTableCellReader
- Parameters:
table
- the targetJTable
.row
- the given row.column
- the given column.- Returns:
- the
String
representation of the value at the given row and column. - Throws:
IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.- See Also:
-
cellValue
@RunsInEDT private static String cellValue(JTable table, int row, int column, JTableCellReader cellReader) -
font
Returns the font of the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the font of the given table cell.
- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
cellFont
-
background
Returns the background color of the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the background color of the given table cell.
- Throws:
ActionFailedException
- if the cell isnull
.ActionFailedException
- if any of the indices (row and column) is out of bounds.
-
cellBackground
@RunsInEDT private static Color cellBackground(JTable table, TableCell cell, JTableCellReader cellReader) -
foreground
Returns the foreground color of the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the foreground color of the given table cell.
- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
cellForeground
@RunsInEDT private static Color cellForeground(JTable table, TableCell cell, JTableCellReader cellReader) -
selectCells
Selects the given cells of the
.JTable
- Parameters:
table
- the targetJTable
.cells
- the cells to select.- Throws:
NullPointerException
- ifcells
isnull
or empty.IllegalArgumentException
- ifcells
isnull
or empty.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.NullPointerException
- if any element incells
isnull
.IndexOutOfBoundsException
- if any of the indices of any of thecells
are out of bounds.
-
validateCellsToSelect
-
requireNoSelection
Verifies that the
does not have any selection.JTable
- Parameters:
table
- the targetJTable
.- Throws:
AssertionError
- is theJTable
has a selection.
-
assertNoSelection
-
selectCell
Selects the given cell, if it is not selected already.- Parameters:
table
- the targetJTable
.cell
- the cell to select.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
click
Clicks the given cell, using the specified mouse button, the given number of times.- Parameters:
table
- the targetJTable
.cell
- the table cell.mouseButton
- the mouse button to use.times
- the number of times to click the cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
drag
Starts a drag operation at the location of the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
drop
Starts a drop operation at the location of the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
showPopupMenuAt
Shows a pop-up menu at the given table cell.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the displayed pop-up menu.
- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.
-
scrollToPointAtCell
@RunsInEDT private static Point scrollToPointAtCell(JTable table, TableCell cell, JTableLocation location) -
scrollToCell
@RunsInCurrentThread private static void scrollToCell(JTable table, TableCell cell, JTableLocation location) -
pointAt
Converts the given table cell into a coordinate pair.- Parameters:
table
- the targetJTable
.cell
- the table cell.- Returns:
- the coordinates of the given row and column.
- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
pointAtCell
-
requireContents
Asserts that theString
representation of the cell values in the
is equal to the givenJTable
String
array. This method uses this driver's
to read the values of the table cells asJTableCellReader
String
s.- Parameters:
table
- the targetJTable
.contents
- the expectedString
representation of the cell values in theJTable
.- See Also:
-
failNotEqual
-
contents
- Parameters:
table
- the targetJTable
.- Returns:
- the
String
representation of the cells in theJTable
. - See Also:
-
requireCellValue
Asserts that the value of the given cell matches the given value.- Parameters:
table
- the targetJTable
.cell
- the given table cell.value
- the expected value. It can be a regular expression.- Throws:
NullPointerException
- if the cell isnull
.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.
-
requireCellValue
Asserts that the value of the given cell matches the given regular expression pattern.- Parameters:
table
- the targetJTable
.cell
- the given table cell.pattern
- the regular expression pattern to match.- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.NullPointerException
- if the given regular expression pattern isnull
.AssertionError
- if the value of the given cell does not match the given regular expression pattern.- Since:
- 1.2
-
cellValueProperty
-
enterValueInCell
Enters the given value in the given cell of the
, using this driver'sJTable
.JTableCellWriter
- Parameters:
table
- the targetJTable
.cell
- the given cell.value
- the given value.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IllegalStateException
- if theJTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.ActionFailedException
- if this driver'sJTableCellValueReader
is unable to enter the given value.- See Also:
-
requireEditable
Asserts that the given table cell is editable.- Parameters:
table
- the targetJTable
.cell
- the given table cell.- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.AssertionError
- if the given table cell is not editable.
-
requireNotEditable
Asserts that the given table cell is not editable.- Parameters:
table
- the targetJTable
.cell
- the given table cell.- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.AssertionError
- if the given table cell is editable.
-
requireEditableEqualTo
@RunsInEDT private static void requireEditableEqualTo(JTable table, TableCell cell, boolean editable) -
cellProperty
@RunsInEDT private static org.fest.assertions.Description cellProperty(JTable table, String propertyName) -
cellEditor
Returns the editor in the given cell of the
, using this driver'sJTable
.JTableCellWriter
- Parameters:
table
- the targetJTable
.cell
- the given cell.- Returns:
- the editor in the given cell of the
JTable
. - Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
cell is not editable.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.- See Also:
-
startCellEditing
Starts editing the given cell of the
, using this driver'sJTable
. This method should be called before manipulating theJTableCellWriter
returned byComponent
.cellEditor(JTable, TableCell)
- Parameters:
table
- the targetJTable
.cell
- the given cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IllegalStateException
- if theJTable
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.- See Also:
-
stopCellEditing
Stops editing the given cell of the
, using this driver'sJTable
. This method should be called after manipulating theJTableCellWriter
returned byComponent
.cellEditor(JTable, TableCell)
- Parameters:
table
- the targetJTable
.cell
- the given cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IllegalStateException
- if theJTable
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.- See Also:
-
cancelCellEditing
Cancels editing the given cell of the
, using this driver'sJTable
. This method should be called after manipulating theJTableCellWriter
returned byComponent
.cellEditor(JTable, TableCell)
- Parameters:
table
- the targetJTable
.cell
- the given cell.- Throws:
NullPointerException
- if the cell isnull
.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
is not showing on the screen.IllegalStateException
- if theJTable
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.- See Also:
-
validate
Validates that the given table cell is nonnull
and its indices are not out of bounds.- Parameters:
table
- the targetJTable
.cell
- to validate.- Throws:
NullPointerException
- if the cell isnull
.IndexOutOfBoundsException
- if any of the indices (row and column) is out of bounds.
-
validateCellIndexBounds
-
cellReader
Updates the implementation of
to use when comparing internal values of aJTableCellReader
and the values expected in a test.JTable
- Parameters:
newCellReader
- the newJTableCellValueReader
to use.- Throws:
NullPointerException
- ifnewCellReader
isnull
.
-
cellWriter
Updates the implementation of
to use to edit cell values in aJTableCellWriter
.JTable
- Parameters:
newCellWriter
- the newJTableCellWriter
to use.- Throws:
NullPointerException
- ifnewCellWriter
isnull
.
-
rowCountOf
Returns the number of rows that can be shown in the given
, given unlimited space.JTable
- Parameters:
table
- the targetJTable
.- Returns:
- the number of rows shown in the given
JTable
. - See Also:
-
columnIndex
Returns the index of the column in the given
whose id matches the given one.JTable
- Parameters:
table
- the targetJTable
.columnId
- the id of the column to look for.- Returns:
- the index of the column whose id matches the given one.
- Throws:
ActionFailedException
- if a column with a matching id could not be found.
-
findColumnIndex
-
failColumnIndexNotFound
-
requireRowCount
Asserts that the given
has the given number of rows.JTable
- Parameters:
table
- the targetJTable
.rowCount
- the expected number of rows.- Throws:
AssertionError
- if the givenJTable
does not have the given number of rows.
-
requireColumnCount
Asserts that the given
has the given number of columns.JTable
- Parameters:
table
- the targetJTable
.columnCount
- the expected number of columns.- Throws:
AssertionError
- if the givenJTable
does not have the given number of columns.
-
selectRows
Simulates a user selecting the given rows in the given
.JTable
- Parameters:
table
- the targetJTable
.rows
- the indices of the row to select.- Throws:
NullPointerException
- if the given array of indices isnull
.IllegalArgumentException
- if the given array of indices is empty.IllegalStateException
- if theJTable
is disabled.IllegalStateException
- if theJTable
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 theJTable
.- Since:
- 1.2
-
selectCell
-
cellSelectionInfo
@RunsInEDT private static Pair<Boolean,Point> cellSelectionInfo(JTable table, int row, int column, JTableLocation location) -
scrollToCell
@RunsInCurrentThread private static void scrollToCell(JTable table, int row, int column, JTableLocation location) -
requireSelectedRows
Asserts that the set of selected rows in the given
contains to the given row indices.JTable
- Parameters:
table
- the targetJTable
.rows
- the indices of the rows expected to be selected.- Throws:
AssertionError
- if the sets of selected rows in the givenJTable
(if any) do not contain the given row indices.- Since:
- 1.2
-
selectedRowsOf
-
cellReader
JTableCellReader cellReader()
-