org.fest.swing.fixture
Class JTableCellFixture

java.lang.Object
  extended by org.fest.swing.fixture.JTableCellFixture
All Implemented Interfaces:
ItemFixture, MouseInputSimulationFixture

public class JTableCellFixture
extends Object
implements ItemFixture

Understands functional testing of single cells in JTables:

Example:

 // import static org.fest.swing.data.TableCell.row;
 JTableCellFixture cell = dialog.table("records").cell(row(3).column(0));
 cell.select().showPopupMenu();
 

Author:
Alex Ruiz, Yvonne Wang
See Also:
TableCell

Constructor Summary
protected JTableCellFixture(JTableFixture table, TableCell cell)
          Creates a new JTableCellFixture.
 
Method Summary
 ColorFixture background()
          Returns a fixture that verifies the background color of this fixture's table cell.
 JTableCellFixture cancelEditing()
          Cancels editing this fixture's table cell.
 JTableCellFixture click()
          Simulates a user clicking this fixture's table cell.
 JTableCellFixture click(MouseButton button)
          Simulates a user clicking a cell in this fixture's table cell once, using the specified mouse button.
 JTableCellFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's table cell.
 int column()
          Returns the column index of this fixture's table cell.
 JTableCellFixture doubleClick()
          Simulates a user double-clicking this fixture's table cell.
 JTableCellFixture drag()
          Simulates a user dragging this fixture's table cell.
 JTableCellFixture drop()
          Simulates a user dropping into this fixture's table cell.
 Component editor()
          Returns the editor of this fixture's table cell.
 JTableCellFixture enterValue(String value)
          Enters the given value to this fixture's table cell.
 FontFixture font()
          Returns a fixture that verifies the font of this fixture's table cell.
 ColorFixture foreground()
          Returns a fixture that verifies the foreground color of this fixture's table cell.
 JTableCellFixture requireEditable()
          Asserts that this fixture's table cell is editable.
 JTableCellFixture requireNotEditable()
          Asserts that this fixture's table cell is not editable.
 JTableCellFixture requireValue(Pattern pattern)
          Asserts that the value of this fixture's table cell matches the given regular expression pattern.
 JTableCellFixture requireValue(String value)
          Asserts that the value of this fixture's table cell matches the given value.
 JTableCellFixture rightClick()
          Simulates a user right-clicking this fixture's table cell.
 int row()
          Returns the row index of this fixture's table cell.
 JTableCellFixture select()
          Simulates a user selecting this fixture's table cell.
 JPopupMenuFixture showPopupMenu()
          Shows a pop-up menu using this fixture's table cell as the invoker of the pop-up menu.
 JTableCellFixture startEditing()
          Starts editing this fixture's table cell.
 JTableCellFixture stopEditing()
          Stops editing this fixture's table cell.
 String value()
          Returns the String representation of the value of this fixture's table cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTableCellFixture

protected JTableCellFixture(JTableFixture table,
                            TableCell cell)
Creates a new JTableCellFixture.

Parameters:
table - handles the JTable containing the cell in this fixture.
cell - row and column indices of the table cell to be managed by this fixture.
Throws:
NullPointerException - if table is null.
NullPointerException - if cell is null.
Method Detail

select

public JTableCellFixture select()
Simulates a user selecting this fixture's table cell.

Specified by:
select in interface ItemFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

click

public JTableCellFixture click()
Simulates a user clicking this fixture's table cell.

Specified by:
click in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

click

public JTableCellFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's table cell.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
mouseClickInfo - specifies the button to click and the times the button should be clicked.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

doubleClick

public JTableCellFixture doubleClick()
Simulates a user double-clicking this fixture's table cell.

Specified by:
doubleClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

rightClick

public JTableCellFixture rightClick()
Simulates a user right-clicking this fixture's table cell.

Specified by:
rightClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

click

public JTableCellFixture click(MouseButton button)
Simulates a user clicking a cell in this fixture's table cell once, using the specified mouse button.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
button - the mouse button to use.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseButton is null.
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.

startEditing

public JTableCellFixture startEditing()
Starts editing this fixture's table cell. This method should be called before manipulating the Component returned by editor().

This method uses the JTableCellWriter from the JTableFixture that created this fixture.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.
IllegalStateException - if this 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:
JTableFixture.cellWriter(JTableCellWriter), JTableCellWriter, editor()

stopEditing

public JTableCellFixture stopEditing()
Stops editing this fixture's table cell. This method should be called after manipulating the Component returned by editor().

This method uses the JTableCellWriter from the JTableFixture that created this fixture.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.
IllegalStateException - if this 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:
JTableFixture.cellWriter(JTableCellWriter), JTableCellWriter, editor()

cancelEditing

public JTableCellFixture cancelEditing()
Cancels editing this fixture's table cell. This method should be called after manipulating the Component returned by editor().

 TableCellFixture cell = table.cell(row(6).column(8));
 Component editor = cell.editor();
 // assume editor is a JTextField
 JTextComponentFixture editorFixture = new JTextComponentFixture(robot, (JTextField) editor);
 cell.startEditing();
 editorFixture.enterText("Hello");
 // discard any entered value
 cell.cancelEditing();
 

This method uses the JTableCellWriter from the JTableFixture that created this fixture.

Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.
IllegalStateException - if this 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:
JTableFixture.cellWriter(JTableCellWriter), JTableCellWriter, editor()

editor

public Component editor()
Returns the editor of this fixture's table cell. To manipulate the editor (e.g. wrapping it with a ComponentFixture,) the method startEditing() should be called first. To apply any changes back to the table cell, the method stopEditing() should be called. This method uses the JTableCellWriter from the JTableFixture that created this fixture.

Example:

 TableCellFixture cell = table.cell(row(6).column(8));
 Component editor = cell.editor();
 // assume editor is a JTextField
 JTextComponentFixture editorFixture = new JTextComponentFixture(robot, (JTextField) editor);
 cell.startEditing();
 editorFixture.enterText("Hello");
 cell.stopEditing();
 

Returns:
the editor of this fixture's table cell.
See Also:
JTableFixture.cellWriter(JTableCellWriter), JTableCellWriter

enterValue

public JTableCellFixture enterValue(String value)
Enters the given value to this fixture's table cell. This method starts cell edition, enters the given value and stops cell edition. To change the value of a cell, only a call to this method is necessary. If you need more flexibility, you can retrieve the cell editor with editor().

This method uses the JTableCellWriter from the JTableFixture that created this fixture.

Parameters:
value - the value to enter in the cell.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JTable is disabled.
IllegalStateException - if this fixture's JTable is not showing on the screen.
IllegalStateException - if this 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:
JTableFixture.cellWriter(JTableCellWriter), JTableCellWriter

requireValue

public JTableCellFixture requireValue(String value)
Asserts that the value of this fixture's table cell matches the given value.

Parameters:
value - the expected value of this fixture's table cell. It can be a regular expression.
Returns:
this fixture.
Throws:
AssertionError - if the value of this fixture's table cell does not match the expected one.

requireValue

public JTableCellFixture requireValue(Pattern pattern)
Asserts that the value of this fixture's table cell matches the given regular expression pattern.

Parameters:
pattern - the regular expression pattern to match.
Returns:
this fixture.
Throws:
NullPointerException - if the given regular expression pattern is null.
AssertionError - if the value of this fixture's table cell does not match the expected the given regular expression pattern.
Since:
1.2

font

public FontFixture font()
Returns a fixture that verifies the font of this fixture's table cell. This method uses the JTableCellReader from the JTableFixture that created this fixture.

Returns:
a fixture that verifies the font of this fixture's table cell.
See Also:
JTableFixture.cellReader(JTableCellReader), JTableCellReader

background

public ColorFixture background()
Returns a fixture that verifies the background color of this fixture's table cell. This method uses the JTableCellReader from the JTableFixture that created this fixture.

Returns:
a fixture that verifies the background color of this fixture's table cell.
See Also:
JTableFixture.cellReader(JTableCellReader), JTableCellReader

foreground

public ColorFixture foreground()
Returns a fixture that verifies the foreground color of this fixture's table cell. This method uses the JTableCellReader from the JTableFixture that created this fixture.

Returns:
a fixture that verifies the foreground color of this fixture's table cell.
See Also:
JTableFixture.cellReader(JTableCellReader), JTableCellReader

value

public String value()
Returns the String representation of the value of this fixture's table cell. This method uses the JTableCellReader from the JTableFixture that created this fixture.

Specified by:
value in interface ItemFixture
Returns:
the String representation of the value of this fixture's table cell.
See Also:
JTableFixture.cellReader(JTableCellReader), JTableCellReader

drag

public JTableCellFixture drag()
Simulates a user dragging this fixture's table cell.

Specified by:
drag in interface ItemFixture
Returns:
this fixture.

drop

public JTableCellFixture drop()
Simulates a user dropping into this fixture's table cell.

Specified by:
drop in interface ItemFixture
Returns:
this fixture.

showPopupMenu

public JPopupMenuFixture showPopupMenu()
Shows a pop-up menu using this fixture's table cell as the invoker of the pop-up menu.

Specified by:
showPopupMenu in interface ItemFixture
Returns:
a fixture that manages the displayed pop-up menu.
Throws:
ComponentLookupException - if a pop-up menu cannot be found.

requireEditable

public JTableCellFixture requireEditable()
Asserts that this fixture's table cell is editable.

Returns:
this fixture.
Throws:
AssertionError - if this fixture's table cell is not editable.

requireNotEditable

public JTableCellFixture requireNotEditable()
Asserts that this fixture's table cell is not editable.

Returns:
this fixture.
Throws:
AssertionError - if this fixture's table cell is editable.

row

public int row()
Returns the row index of this fixture's table cell.

Returns:
the row index of this fixture's table cell.

column

public int column()
Returns the column index of this fixture's table cell.

Returns:
the column index of this fixture's table cell.


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