public class JTreeFixture extends AbstractJPopupMenuInvokerFixture<JTreeFixture,JTree,JTreeDriver> implements EditableComponentFixture<JTreeFixture>
Supports functional testing of JTree
s.
TreePath
s can be specified using String
s. For example, for the following tree:
root | -- node1 | -- node1.1
we can identify the node "node1.1" as follows:
root/node1/node1.1
The default path separator is "/". It can be changed by calling replaceSeparator(String)
.
The conversion between the values given in tests and the values being displayed by a JTree
renderer is
performed by a JTreeCellReader
. This fixture uses a BasicJTreeCellReader
by
default.
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY
Constructor and Description |
---|
JTreeFixture(Robot robot,
JTree target)
Creates a new
JTreeFixture . |
JTreeFixture(Robot robot,
String treeName)
Creates a new
JTreeFixture . |
Modifier and Type | Method and Description |
---|---|
JTreeFixture |
clickPath(String path)
Clicks the given path, expanding parent nodes if necessary.
|
JTreeFixture |
clickPath(String path,
MouseButton button)
Clicks the given path, expanding parent nodes if necessary.
|
JTreeFixture |
clickPath(String path,
MouseClickInfo mouseClickInfo)
Clicks the given path, expanding parent nodes if necessary.
|
JTreeFixture |
clickRow(int row)
Clicks the given row.
|
JTreeFixture |
clickRow(int row,
MouseButton button)
Clicks the given row.
|
JTreeFixture |
clickRow(int row,
MouseClickInfo mouseClickInfo)
Clicks the given row.
|
JTreeFixture |
collapsePath(String path)
Simulates a user collapsing the tree node at the given path.
|
JTreeFixture |
collapseRow(int row)
Simulates a user collapsing the tree node at the given row.
|
protected JTreeDriver |
createDriver(Robot robot) |
JTreeFixture |
doubleClickPath(String path)
Double-clicks the given path.
|
JTreeFixture |
doubleClickRow(int row)
Double-clicks the given row.
|
JTreeFixture |
drag(int row)
Simulates a user dragging a row from this fixture's
JTree . |
JTreeFixture |
drag(String path)
Simulates a user dragging an item from this fixture's
JTree . |
JTreeFixture |
drop(int row)
Simulates a user dropping an item into this fixture's
JTree . |
JTreeFixture |
drop(String path)
Simulates a user dropping an item into this fixture's
JTree . |
JTreeFixture |
dropAbove(int row)
Simulates a user dropping an item into this fixture's
JTree . |
JTreeFixture |
dropBelow(int row)
Simulates a user dropping an item into this fixture's
JTree . |
JTreeFixture |
expandPath(String path)
Simulates a user expanding the tree node at the given path.
|
JTreeFixture |
expandRow(int row)
Simulates a user expanding the tree node at the given row.
|
JTreeRowFixture |
node(int row)
Returns a fixture that manages the node specified by the given row.
|
JTreePathFixture |
node(String path)
Returns a fixture that manages the node specified by the given path.
|
JTreeFixture |
replaceCellReader(JTreeCellReader cellReader)
Updates the implementation of
JTreeCellReader to use when comparing internal values of a JTree and
the values expected in a test. |
JTreeFixture |
replaceSeparator(String separator)
Updates the separator to use when converting
TreePath s to String s. |
JTreeFixture |
requireEditable()
Asserts that this fixture's
JTree is editable. |
JTreeFixture |
requireNoSelection()
Asserts that this fixture's
JTree 's does not have any selection. |
JTreeFixture |
requireNotEditable()
Asserts that this fixture's
JTree is not editable. |
JTreeFixture |
requireSelection(int... rows)
Asserts that this fixture's
JTree 's selected rows are equal to the given one. |
JTreeFixture |
requireSelection(String... paths)
Asserts that this fixture's
JTree selection is equal to the given paths. |
JTreeFixture |
rightClickPath(String path)
Right-clicks the given path, expanding parent nodes if necessary.
|
JTreeFixture |
rightClickRow(int row)
Right-clicks the given row.
|
JTreeFixture |
selectPath(String path)
Selects the given path, expanding parent nodes if necessary.
|
JTreeFixture |
selectPaths(String... paths)
Select the given paths, expanding parent nodes if necessary.
|
JTreeFixture |
selectRow(int row)
Simulates a user selecting the tree node at the given row.
|
JTreeFixture |
selectRows(int... rows)
Simulates a user selecting the tree nodes at the given rows.
|
String |
separator() |
JPopupMenuFixture |
showPopupMenuAt(int row)
Shows a pop-up menu at the position of the node in the given row.
|
JPopupMenuFixture |
showPopupMenuAt(String path)
Shows a pop-up menu at the position of the last node in the given path.
|
JTreeFixture |
toggleRow(int row)
Simulates a user toggling the open/closed state of the tree node at the given row.
|
JTreeFixture |
unselectPath(String path)
Unselects the given path, expanding parent nodes if necessary.
|
JTreeFixture |
unselectPaths(String... paths)
Unselect the given paths, expanding parent nodes if necessary.
|
JTreeFixture |
unselectRow(int row)
Simulates a user unselecting the tree node at the given row.
|
JTreeFixture |
unselectRows(int... rows)
Simulates a user unselecting the tree nodes at the given rows.
|
String |
valueAt(int row)
Returns the
String representation of the given row. |
String |
valueAt(String path)
Returns the
String representation of the node at the given path. |
showPopupMenu, showPopupMenuAt
clientProperty, requireToolTip, requireToolTip
background, click, click, click, doubleClick, driver, drop, equals, focus, font, foreground, hashCode, isEnabled, myself, pressAndReleaseKey, pressAndReleaseKeys, pressKey, pressKeyWhileRunning, releaseKey, replaceDriverWith, requireDisabled, requireEnabled, requireEnabled, requireFocused, requireNotVisible, requireShowing, requireVisible, rightClick, robot, target, targetCastedTo
public JTreeFixture(@Nonnull Robot robot, @Nonnull JTree target)
JTreeFixture
.robot
- performs simulation of user events on the given JTree
.target
- the JTree
to be managed by this fixture.NullPointerException
- if robot
is null
.NullPointerException
- if target
is null
.public JTreeFixture(@Nonnull Robot robot, @Nullable String treeName)
JTreeFixture
.robot
- performs simulation of user events on a JTree
.treeName
- the name of the JTree
to find using the given Robot
.NullPointerException
- if robot
is null
.ComponentLookupException
- if a matching JTree
could not be found.ComponentLookupException
- if more than one matching JTree
is found.@Nonnull protected JTreeDriver createDriver(@Nonnull Robot robot)
createDriver
in class AbstractComponentFixture<JTreeFixture,JTree,JTreeDriver>
@Nonnull public JTreeFixture clickRow(int row)
row
- the given row.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture clickRow(int row, @Nonnull MouseButton button)
row
- the given row.button
- the mouse button to use.NullPointerException
- if the button is null
.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture clickRow(int row, @Nonnull MouseClickInfo mouseClickInfo)
row
- the given row.mouseClickInfo
- specifies the mouse button to use and how many times to click.NullPointerException
- if the given MouseClickInfo
is null
.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture clickPath(@Nonnull String path)
path
- the given path.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture clickPath(@Nonnull String path, @Nonnull MouseButton button)
path
- the given path.button
- the mouse button to use.NullPointerException
- if the button is null
.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture clickPath(@Nonnull String path, @Nonnull MouseClickInfo mouseClickInfo)
path
- the given path.mouseClickInfo
- specifies the mouse button to use and how many times to click.NullPointerException
- if the given MouseClickInfo
is null
.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture doubleClickRow(int row)
row
- the given row.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture doubleClickPath(@Nonnull String path)
path
- the given path.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture rightClickRow(int row)
row
- the given row.IllegalStateException
- if the JTree
is disabled.IllegalStateException
- if the JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture rightClickPath(@Nonnull String path)
path
- the given path.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture drag(int row)
JTree
.row
- the index of the row to drag.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture drop(int row)
JTree
.row
- the row to drop the item to.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if there is no drag action in effect.@Nonnull public JTreeFixture dropAbove(int row)
JTree
.row
- the row to drop the item below the item to drop.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if there is no drag action in effect.drop(int)
@Nonnull public JTreeFixture dropBelow(int row)
JTree
.row
- the row to drop the item above the item to drop.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if there is no drag action in effect.drop(int)
@Nonnull public JTreeFixture drag(@Nonnull String path)
JTree
.path
- the path corresponding to the item to drag.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture drop(@Nonnull String path)
JTree
.path
- the path corresponding to the item relative to the drop point.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.ActionFailedException
- if there is no drag action in effect.@Nonnull public JTreeFixture selectRow(int row)
row
- the index of the row to select.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture selectRows(@Nonnull int... rows)
rows
- the indices of the rows to select.NullPointerException
- if the array of rows is null
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for any of the given rows cannot be
found.@Nonnull public JTreeFixture selectPath(@Nonnull String path)
clickPath(String)
, this method will
not click the path if it is already selected.path
- the path to select.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture selectPaths(@Nonnull String... paths)
paths
- the paths to select.NullPointerException
- if the array of rows is null
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the any of the given paths cannot be found.@Nonnull public JTreeFixture unselectRow(int row)
row
- the index of the row to unselect.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JTreeFixture unselectRows(@Nonnull int... rows)
rows
- the indices of the rows to unselect.NullPointerException
- if the array of rows is null
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for any of the given rows cannot be
found.@Nonnull public JTreeFixture unselectPath(@Nonnull String path)
clickPath(String)
, this method will
not click the path if it is not selected.path
- the path to unselect.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture unselectPaths(@Nonnull String... paths)
paths
- the paths to unselect.NullPointerException
- if the array of rows is null
.IllegalArgumentException
- if the array of rows is empty.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the any of the given paths cannot be found.@Nonnull public JTreeFixture toggleRow(int row)
row
- the index of the row to toggle.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if this method fails to toggle the row.@Nonnull public JTreeFixture expandRow(int row)
row
- the index of the row to expand.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if this method fails to expand the row.@Nonnull public JTreeFixture collapseRow(int row)
row
- the index of the row to collapse.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.ActionFailedException
- if this method fails to collapse the row.@Nonnull public JTreeFixture expandPath(@Nonnull String path)
path
- the path of the row to expand.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.ActionFailedException
- if this method fails to expand the path.@Nonnull public JTreeFixture collapsePath(@Nonnull String path)
path
- the path of the row to collapse.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.LocationUnavailableException
- if the given path cannot be found.ActionFailedException
- if this method fails to collapse the path.@Nonnull public JPopupMenuFixture showPopupMenuAt(int row)
row
- the index of the row invoking the pop-up menu.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.ComponentLookupException
- if a pop-up menu cannot be found.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nonnull public JPopupMenuFixture showPopupMenuAt(@Nonnull String path)
path
- the path of the node invoking the pop-up menu.IllegalStateException
- if this fixture's JTree
is disabled.IllegalStateException
- if this fixture's JTree
is not showing on the screen.ComponentLookupException
- if a pop-up menu cannot be found.LocationUnavailableException
- if the given path cannot be found.@Nonnull public JTreeFixture requireEditable()
JTree
is editable.requireEditable
in interface EditableComponentFixture<JTreeFixture>
AssertionError
- if this fixture's JTree
is not editable.@Nonnull public JTreeFixture requireNotEditable()
JTree
is not editable.requireNotEditable
in interface EditableComponentFixture<JTreeFixture>
AssertionError
- if this fixture's JTree
is editable.@Nonnull public JTreeFixture requireSelection(@Nonnull int... rows)
JTree
's selected rows are equal to the given one.rows
- the indices of the rows, expected to be selected.NullPointerException
- if the array of row indices is null
.AssertionError
- if this fixture's JTree
selection is not equal to the given rows.@Nonnull public JTreeFixture requireSelection(@Nonnull String... paths)
JTree
selection is equal to the given paths.paths
- the given paths, expected to be selected.NullPointerException
- if the array of paths is null
.LocationUnavailableException
- if any of the given path cannot be found.AssertionError
- if this fixture's JTree
selection is not equal to the given paths.@Nonnull public JTreeFixture requireNoSelection()
JTree
's does not have any selection.AssertionError
- if this fixture's JTree
has a selection.public String separator()
TreePath
s to String
s.@Nonnull public JTreeFixture replaceSeparator(@Nonnull String separator)
TreePath
s to String
s. The default value is "/".separator
- the new separator.NullPointerException
- if the given separator is null
.@Nonnull public JTreeFixture replaceCellReader(@Nonnull JTreeCellReader cellReader)
JTreeCellReader
to use when comparing internal values of a JTree
and
the values expected in a test. The default implementation to use is
BasicJTreeCellReader
.cellReader
- the new JTreeCellValueReader
to use.NullPointerException
- if cellReader
is null
.@Nonnull public JTreeRowFixture node(int row)
row
- the given row.IndexOutOfBoundsException
- if the given index is less than zero or equal than or greater than the number of
visible rows in the JTree
.@Nonnull public JTreePathFixture node(@Nonnull String path)
path
- the given path.LocationUnavailableException
- if the given path cannot be found.@Nullable public String valueAt(int row)
String
representation of the given row.row
- the given row.String
representation of the node at the given path.IndexOutOfBoundsException
- if the given row is less than zero or equal than or greater than the number of
visible rows in the JTree
.LocationUnavailableException
- if a tree path for the given row cannot be found.@Nullable public String valueAt(@Nonnull String path)
String
representation of the node at the given path.path
- the given path.String
representation of the node at the given path.LocationUnavailableException
- if the given path cannot be found.Copyright © 2014–2019 AssertJ. All rights reserved.