org.fest.swing.driver
Class JTableDriver

java.lang.Object
  extended by org.fest.swing.driver.ComponentDriver
      extended by org.fest.swing.driver.ContainerDriver
          extended by org.fest.swing.driver.JComponentDriver
              extended by org.fest.swing.driver.JTableDriver

public class JTableDriver
extends JComponentDriver

Understands functional testing of JTables:

This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.driver.ComponentDriver
robot
 
Constructor Summary
JTableDriver(Robot robot)
          Creates a new JTableDriver.
 
Method Summary
 Color 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 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 cellReader(JTableCellReader newCellReader)
          Updates the implementation of JTableCellReader to use when comparing internal values of a JTable and the values expected in a test.
 void cellWriter(JTableCellWriter newCellWriter)
          Updates the implementation of JTableCellWriter to use to edit cell values in a 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 JTable whose id matches the given one.
 String[][] contents(JTable table)
          Returns the String representation of the cells in the JTable, using this driver's JTableCellReader.
 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 color of the given table cell.
 Point pointAt(JTable table, TableCell cell)
          Converts the given table cell into a coordinate pair.
 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 validate(JTable table, TableCell cell)
          Validates that the given table cell is non null and its indices are not out of bounds.
 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.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTableDriver

public JTableDriver(Robot robot)
Creates a new JTableDriver.

Parameters:
robot - the robot to use to simulate user events.
Method Detail

tableHeaderOf

@RunsInEDT
public JTableHeader tableHeaderOf(JTable table)
Returns the JTableHeader of the given JTable.

Parameters:
table - the given JTable.
Returns:
the JTableHeader of the given JTable.

selectionValue

@RunsInEDT
public String selectionValue(JTable table)
Returns the String representation of the value of the selected cell, using this driver's JTableCellReader.

Parameters:
table - the target JTable.
Returns:
the String representation of the value of the selected cell.
See Also:
cellReader(JTableCellReader)

cell

@RunsInEDT
public TableCell cell(JTable table,
                                TableCellFinder cellFinder)
Returns a cell from the given JTable using the given cell finder.

Parameters:
table - the target JTable.
cellFinder - knows how to find a cell.
Returns:
the found cell, if any.
Throws:
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.

cell

@RunsInEDT
public TableCell cell(JTable table,
                                String value)
Returns a cell from the given JTable whose value matches the given one.

Parameters:
table - the target JTable.
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

@RunsInEDT
public TableCell cell(JTable table,
                                Pattern pattern)
Returns a cell from the given JTable whose value matches the given regular expression pattern.

Parameters:
table - the target JTable.
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 is null.
ActionFailedException - if a cell with a matching value cannot be found.
Since:
1.2

value

@RunsInEDT
public String value(JTable table,
                              TableCell cell)
Returns the String representation of the value at the given cell, using this driver's JTableCellReader.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the String representation of the value at the given cell.
Throws:
NullPointerException - if the cell is null.
IndexOutOfBoundsException - if any of the indices (row and column) is out of bounds.
See Also:
cellReader(JTableCellReader)

value

@RunsInEDT
public 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.

Parameters:
table - the target JTable.
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:
cellReader(JTableCellReader)

font

@RunsInEDT
public Font font(JTable table,
                           TableCell cell)
Returns the font of the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the font of the given table cell.
Throws:
NullPointerException - if the cell is null.
IndexOutOfBoundsException - if any of the indices (row and column) is out of bounds.

background

@RunsInEDT
public Color background(JTable table,
                                  TableCell cell)
Returns the background color of the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the background color of the given table cell.
Throws:
ActionFailedException - if the cell is null.
ActionFailedException - if any of the indices (row and column) is out of bounds.

foreground

@RunsInEDT
public Color foreground(JTable table,
                                  TableCell cell)
Returns the foreground color of the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the foreground color of the given table cell.
Throws:
NullPointerException - if the cell is null.
IndexOutOfBoundsException - if any of the indices (row and column) is out of bounds.

selectCells

public void selectCells(JTable table,
                        TableCell[] cells)
Selects the given cells of the JTable.

Parameters:
table - the target JTable.
cells - the cells to select.
Throws:
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.

requireNoSelection

@RunsInEDT
public void requireNoSelection(JTable table)
Verifies that the JTable does not have any selection.

Parameters:
table - the target JTable.
Throws:
AssertionError - is the JTable has a selection.

selectCell

@RunsInEDT
public void selectCell(JTable table,
                                 TableCell cell)
Selects the given cell, if it is not selected already.

Parameters:
table - the target JTable.
cell - the cell to select.
Throws:
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.

click

@RunsInEDT
public void click(JTable table,
                            TableCell cell,
                            MouseButton mouseButton,
                            int times)
Clicks the given cell, using the specified mouse button, the given number of times.

Parameters:
table - the target JTable.
cell - the table cell.
mouseButton - the mouse button to use.
times - the number of times to click the cell.
Throws:
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.

drag

@RunsInEDT
public void drag(JTable table,
                           TableCell cell)
Starts a drag operation at the location of the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Throws:
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.

drop

@RunsInEDT
public void drop(JTable table,
                           TableCell cell)
Starts a drop operation at the location of the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Throws:
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.

showPopupMenuAt

@RunsInEDT
public JPopupMenu showPopupMenuAt(JTable table,
                                            TableCell cell)
Shows a pop-up menu at the given table cell.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the displayed pop-up menu.
Throws:
NullPointerException - if the cell is null.
IllegalStateException - if the JTable is disabled.
IllegalStateException - if the JTable is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.

pointAt

@RunsInEDT
public Point pointAt(JTable table,
                               TableCell cell)
Converts the given table cell into a coordinate pair.

Parameters:
table - the target JTable.
cell - the table cell.
Returns:
the coordinates of the given row and column.
Throws:
NullPointerException - if the cell is null.
IndexOutOfBoundsException - if any of the indices (row and column) is out of bounds.

requireContents

@RunsInEDT
public 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. This method uses this driver's JTableCellReader to read the values of the table cells as Strings.

Parameters:
table - the target JTable.
contents - the expected String representation of the cell values in the JTable.
See Also:
cellReader(JTableCellReader)

contents

@RunsInEDT
public String[][] contents(JTable table)
Returns the String representation of the cells in the JTable, using this driver's JTableCellReader.

Parameters:
table - the target JTable.
Returns:
the String representation of the cells in the JTable.
See Also:
cellReader(JTableCellReader)

requireCellValue

@RunsInEDT
public void requireCellValue(JTable table,
                                       TableCell cell,
                                       String value)
Asserts that the value of the given cell matches the given value.

Parameters:
table - the target JTable.
cell - the given table cell.
value - the expected value. It can be a regular expression.
Throws:
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.

requireCellValue

@RunsInEDT
public void requireCellValue(JTable table,
                                       TableCell cell,
                                       Pattern pattern)
Asserts that the value of the given cell matches the given regular expression pattern.

Parameters:
table - the target JTable.
cell - the given table cell.
pattern - the regular expression pattern to match.
Throws:
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.
Since:
1.2

enterValueInCell

@RunsInEDT
public void enterValueInCell(JTable table,
                                       TableCell cell,
                                       String value)
Enters the given value in the given cell of the JTable, using this driver's JTableCellWriter.

Parameters:
table - the target JTable.
cell - the given cell.
value - the given value.
Throws:
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.
See Also:
cellWriter(JTableCellWriter)

requireEditable

@RunsInEDT
public void requireEditable(JTable table,
                                      TableCell cell)
Asserts that the given table cell is editable.

Parameters:
table - the target JTable.
cell - the given table cell.
Throws:
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.

requireNotEditable

@RunsInEDT
public void requireNotEditable(JTable table,
                                         TableCell cell)
Asserts that the given table cell is not editable.

Parameters:
table - the target JTable.
cell - the given table cell.
Throws:
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.

cellEditor

@RunsInEDT
public Component cellEditor(JTable table,
                                      TableCell cell)
Returns the editor in the given cell of the JTable, using this driver's JTableCellWriter.

Parameters:
table - the target JTable.
cell - the given cell.
Returns:
the editor in the given cell of the JTable.
Throws:
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.
See Also:
cellWriter(JTableCellWriter)

startCellEditing

@RunsInEDT
public void startCellEditing(JTable table,
                                       TableCell cell)
Starts editing the given cell of the JTable, using this driver's JTableCellWriter. This method should be called before manipulating the Component returned by cellEditor(JTable, TableCell).

Parameters:
table - the target JTable.
cell - the given cell.
Throws:
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.
See Also:
cellWriter(JTableCellWriter)

stopCellEditing

@RunsInEDT
public void stopCellEditing(JTable table,
                                      TableCell cell)
Stops editing the given cell of the JTable, using this driver's JTableCellWriter. This method should be called after manipulating the Component returned by cellEditor(JTable, TableCell).

Parameters:
table - the target JTable.
cell - the given cell.
Throws:
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.
See Also:
cellWriter(JTableCellWriter)

cancelCellEditing

@RunsInEDT
public void cancelCellEditing(JTable table,
                                        TableCell cell)
Cancels editing the given cell of the JTable, using this driver's JTableCellWriter. This method should be called after manipulating the Component returned by cellEditor(JTable, TableCell).

Parameters:
table - the target JTable.
cell - the given cell.
Throws:
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.
See Also:
cellWriter(JTableCellWriter)

validate

@RunsInEDT
public void validate(JTable table,
                               TableCell cell)
Validates that the given table cell is non null and its indices are not out of bounds.

Parameters:
table - the target JTable.
cell - to validate.
Throws:
NullPointerException - if the cell is null.
IndexOutOfBoundsException - if any of the indices (row and column) is out of bounds.

cellReader

public void cellReader(JTableCellReader newCellReader)
Updates the implementation of JTableCellReader to use when comparing internal values of a JTable and the values expected in a test.

Parameters:
newCellReader - the new JTableCellValueReader to use.
Throws:
NullPointerException - if newCellReader is null.

cellWriter

public void cellWriter(JTableCellWriter newCellWriter)
Updates the implementation of JTableCellWriter to use to edit cell values in a JTable.

Parameters:
newCellWriter - the new JTableCellWriter to use.
Throws:
NullPointerException - if newCellWriter is null.

rowCountOf

@RunsInEDT
public int rowCountOf(JTable table)
Returns the number of rows that can be shown in the given JTable, given unlimited space.

Parameters:
table - the target JTable.
Returns:
the number of rows shown in the given JTable.
See Also:
JTable.getRowCount()

columnIndex

@RunsInEDT
public int columnIndex(JTable table,
                                 Object columnId)
Returns the index of the column in the given JTable whose id matches the given one.

Parameters:
table - the target JTable.
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.

requireRowCount

@RunsInEDT
public void requireRowCount(JTable table,
                                      int rowCount)
Asserts that the given JTable has the given number of rows.

Parameters:
table - the target JTable.
rowCount - the expected number of rows.
Throws:
AssertionError - if the given JTable does not have the given number of rows.

requireColumnCount

@RunsInEDT
public void requireColumnCount(JTable table,
                                         int columnCount)
Asserts that the given JTable has the given number of columns.

Parameters:
table - the target JTable.
columnCount - the expected number of columns.
Throws:
AssertionError - if the given JTable does not have the given number of columns.

selectRows

@RunsInEDT
public void selectRows(JTable table,
                                 int... rows)
Simulates a user selecting the given rows in the given JTable.

Parameters:
table - the target JTable.
rows - the indices of the row to select.
Throws:
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.
Since:
1.2

requireSelectedRows

@RunsInEDT
public void requireSelectedRows(JTable table,
                                          int... rows)
Asserts that the set of selected rows in the given JTable contains to the given row indices.

Parameters:
table - the target JTable.
rows - the indices of the rows expected to be selected.
Throws:
AssertionError - if the sets of selected rows in the given JTable (if any) do not contain the given row indices.
Since:
1.2


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.