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
JTables:
- user input simulation
- state verification
- property value query
org.fest.swing.fixture in your tests.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JTableCellReaderprivate JTableCellWriterprivate static final Stringprivate static final Stringprivate final JTableLocationprivate static final Stringprivate static final Stringprivate static final StringFields inherited from class org.fest.swing.driver.ComponentDriver
robot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidassertNoSelection(JTable table) background(JTable table, TableCell cell) Returns the background color of the given table cell.voidcancelCellEditing(JTable table, TableCell cell) Cancels editing the given cell of the, using this driver'sJTable.JTableCellWriterReturns a cell from the givenwhose value matches the given one.JTableReturns a cell from the givenwhose value matches the given regular expression pattern.JTablecell(JTable table, TableCellFinder cellFinder) Returns a cell from the givenusing the given cell finder.JTableprivate static ColorcellBackground(JTable table, TableCell cell, JTableCellReader cellReader) cellEditor(JTable table, TableCell cell) Returns the editor in the given cell of the, using this driver'sJTable.JTableCellWriterprivate static FontcellFont(JTable table, TableCell cell, JTableCellReader cellReader) private static ColorcellForeground(JTable table, TableCell cell, JTableCellReader cellReader) private static org.fest.assertions.DescriptioncellProperty(JTable table, String propertyName) (package private) JTableCellReadervoidcellReader(JTableCellReader newCellReader) Updates the implementation ofto use when comparing internal values of aJTableCellReaderand the values expected in a test.JTablecellSelectionInfo(JTable table, int row, int column, JTableLocation location) private static StringcellValue(JTable table, int row, int column, JTableCellReader cellReader) private static StringcellValue(JTable table, TableCell cell, JTableCellReader cellReader) private org.fest.assertions.DescriptioncellValueProperty(JTable table, TableCell cell) voidcellWriter(JTableCellWriter newCellWriter) Updates the implementation ofto use to edit cell values in aJTableCellWriter.JTablevoidclick(JTable table, TableCell cell, MouseButton mouseButton, int times) Clicks the given cell, using the specified mouse button, the given number of times.intcolumnIndex(JTable table, Object columnId) Returns the index of the column in the givenwhose id matches the given one.JTableString[][]voidStarts a drag operation at the location of the given table cell.voidStarts a drop operation at the location of the given table cell.voidenterValueInCell(JTable table, TableCell cell, String value) Enters the given value in the given cell of the, using this driver'sJTable.JTableCellWriterprivate static ActionFailedExceptionfailColumnIndexNotFound(Object columnId) private static voidfailNotEqual(String[][] actual, String[][] expected, org.fest.assertions.Description description) private static intfindColumnIndex(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 PointpointAtCell(JTable table, TableCell cell, JTableLocation location) voidrequireCellValue(JTable table, TableCell cell, String value) Asserts that the value of the given cell matches the given value.voidrequireCellValue(JTable table, TableCell cell, Pattern pattern) Asserts that the value of the given cell matches the given regular expression pattern.voidrequireColumnCount(JTable table, int columnCount) Asserts that the givenhas the given number of columns.JTablevoidrequireContents(JTable table, String[][] contents) Asserts that theStringrepresentation of the cell values in theis equal to the givenJTableStringarray.voidrequireEditable(JTable table, TableCell cell) Asserts that the given table cell is editable.private static voidrequireEditableEqualTo(JTable table, TableCell cell, boolean editable) voidrequireNoSelection(JTable table) Verifies that thedoes not have any selection.JTablevoidrequireNotEditable(JTable table, TableCell cell) Asserts that the given table cell is not editable.voidrequireRowCount(JTable table, int rowCount) Asserts that the givenhas the given number of rows.JTablevoidrequireSelectedRows(JTable table, int... rows) Asserts that the set of selected rows in the givencontains to the given row indices.JTableintrowCountOf(JTable table) Returns the number of rows that can be shown in the given, given unlimited space.JTableprivate static voidscrollToCell(JTable table, int row, int column, JTableLocation location) private static voidscrollToCell(JTable table, TableCell cell, JTableLocation location) private static PointscrollToPointAtCell(JTable table, TableCell cell, JTableLocation location) private voidselectCell(JTable table, int row, int column) voidselectCell(JTable table, TableCell cell) Selects the given cell, if it is not selected already.voidselectCells(JTable table, TableCell[] cells) Selects the given cells of the.JTableprivate static int[]selectedRowsOf(JTable table) selectionValue(JTable table) Returns theStringrepresentation of the value of the selected cell, using this driver's.JTableCellReaderprivate static StringselectionValue(JTable table, JTableCellReader cellReader) voidselectRows(JTable table, int... rows) Simulates a user selecting the given rows in the given.JTableshowPopupMenuAt(JTable table, TableCell cell) Shows a pop-up menu at the given table cell.voidstartCellEditing(JTable table, TableCell cell) Starts editing the given cell of the, using this driver'sJTable.JTableCellWritervoidstopCellEditing(JTable table, TableCell cell) Stops editing the given cell of the, using this driver'sJTable.JTableCellWritertableHeaderOf(JTable table) Returns theof the givenJTableHeader.JTablevoidValidates that the given table cell is nonnulland its indices are not out of bounds.private static voidvalidateCellIndexBounds(JTable table, TableCell cell) private voidvalidateCellsToSelect(TableCell[] cells) Returns theStringrepresentation of the value at the given row and column, using this driver's.JTableCellReaderReturns theStringrepresentation of the value at the given cell, using this driver's.JTableCellReaderMethods inherited from class org.fest.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisibleMethods inherited from class org.fest.swing.driver.ContainerDriver
move, resize, resizeHeight, resizeWidthMethods 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 theof the givenJTableHeader.JTable- Parameters:
table- the givenJTable.- Returns:
- the
JTableHeaderof the givenJTable.
-
selectionValue
Returns theStringrepresentation of the value of the selected cell, using this driver's.JTableCellReader- Parameters:
table- the targetJTable.- Returns:
- the
Stringrepresentation of the value of the selected cell. - See Also:
-
selectionValue
-
cell
Returns a cell from the givenusing the given cell finder.JTable- Parameters:
table- the targetJTable.cellFinder- knows how to find a cell.- Returns:
- the found cell, if any.
- Throws:
NullPointerException- ifcellFinderisnull.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 givenwhose 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
JTablewhose value matches the given one. - Throws:
ActionFailedException- if a cell with a matching value cannot be found.
-
cell
Returns a cell from the givenwhose 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
JTablewhose 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 theStringrepresentation of the value at the given cell, using this driver's.JTableCellReader- Parameters:
table- the targetJTable.cell- the table cell.- Returns:
- the
Stringrepresentation 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 theStringrepresentation 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
Stringrepresentation 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- ifcellsisnullor empty.IllegalArgumentException- ifcellsisnullor empty.IllegalStateException- if theJTableis disabled.IllegalStateException- if theJTableis not showing on the screen.NullPointerException- if any element incellsisnull.IndexOutOfBoundsException- if any of the indices of any of thecellsare out of bounds.
-
validateCellsToSelect
-
requireNoSelection
Verifies that thedoes not have any selection.JTable- Parameters:
table- the targetJTable.- Throws:
AssertionError- is theJTablehas 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 theJTableis disabled.IllegalStateException- if theJTableis 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 theJTableis disabled.IllegalStateException- if theJTableis 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 theJTableis disabled.IllegalStateException- if theJTableis 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 theJTableis disabled.IllegalStateException- if theJTableis 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 theJTableis disabled.IllegalStateException- if theJTableis 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 theStringrepresentation of the cell values in theis equal to the givenJTableStringarray. This method uses this driver'sto read the values of the table cells asJTableCellReaderStrings.- Parameters:
table- the targetJTable.contents- the expectedStringrepresentation of the cell values in theJTable.- See Also:
-
failNotEqual
-
contents
- Parameters:
table- the targetJTable.- Returns:
- the
Stringrepresentation 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 theJTableis disabled.IllegalStateException- if theJTableis not showing on the screen.IllegalStateException- if theJTablecell is not editable.IndexOutOfBoundsException- if any of the indices (row and column) is out of bounds.ActionFailedException- if this driver'sJTableCellValueReaderis 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 theJTablecell 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 theJTableCellWriterreturned byComponent.cellEditor(JTable, TableCell)- Parameters:
table- the targetJTable.cell- the given cell.- Throws:
NullPointerException- if the cell isnull.IllegalStateException- if theJTableis disabled.IllegalStateException- if theJTableis not showing on the screen.IllegalStateException- if theJTablecell 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 theJTableCellWriterreturned byComponent.cellEditor(JTable, TableCell)- Parameters:
table- the targetJTable.cell- the given cell.- Throws:
NullPointerException- if the cell isnull.IllegalStateException- if theJTableis disabled.IllegalStateException- if theJTableis not showing on the screen.IllegalStateException- if theJTablecell 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 theJTableCellWriterreturned byComponent.cellEditor(JTable, TableCell)- Parameters:
table- the targetJTable.cell- the given cell.- Throws:
NullPointerException- if the cell isnull.IllegalStateException- if theJTableis disabled.IllegalStateException- if theJTableis not showing on the screen.IllegalStateException- if theJTablecell 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 nonnulland 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 ofto use when comparing internal values of aJTableCellReaderand the values expected in a test.JTable- Parameters:
newCellReader- the newJTableCellValueReaderto use.- Throws:
NullPointerException- ifnewCellReaderisnull.
-
cellWriter
Updates the implementation ofto use to edit cell values in aJTableCellWriter.JTable- Parameters:
newCellWriter- the newJTableCellWriterto use.- Throws:
NullPointerException- ifnewCellWriterisnull.
-
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 givenwhose 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 givenhas the given number of rows.JTable- Parameters:
table- the targetJTable.rowCount- the expected number of rows.- Throws:
AssertionError- if the givenJTabledoes not have the given number of rows.
-
requireColumnCount
Asserts that the givenhas the given number of columns.JTable- Parameters:
table- the targetJTable.columnCount- the expected number of columns.- Throws:
AssertionError- if the givenJTabledoes 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 theJTableis disabled.IllegalStateException- if theJTableis 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 givencontains 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()
-