org.assertj.swing.driver
Class JTreeDriver

java.lang.Object
  extended by org.assertj.swing.driver.ComponentDriver
      extended by org.assertj.swing.driver.ContainerDriver
          extended by org.assertj.swing.driver.JComponentDriver
              extended by org.assertj.swing.driver.JTreeDriver

@InternalApi
public class JTreeDriver
extends JComponentDriver

Supports functional testing of JTrees.

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

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.assertj.swing.driver.ComponentDriver
robot
 
Constructor Summary
JTreeDriver(Robot robot)
          Creates a new JTreeDriver.
 
Method Summary
 void checkPathExists(JTree tree, String path)
          Verifies that the given node path exists.
 void checkRowInBounds(JTree tree, int row)
          Verifies that the given row index is valid.
 void clickPath(JTree tree, String path)
          Clicks the given path, expanding parent nodes if necessary.
 void clickPath(JTree tree, String path, MouseButton button)
          Clicks the given path, expanding parent nodes if necessary.
 void clickPath(JTree tree, String path, MouseClickInfo mouseClickInfo)
          Clicks the given path, expanding parent nodes if necessary.
 void clickRow(JTree tree, int row)
          Clicks the given row.
 void clickRow(JTree tree, int row, MouseButton button)
          Clicks the given row.
 void clickRow(JTree tree, int row, MouseClickInfo mouseClickInfo)
          Clicks the given row.
 void collapsePath(JTree tree, String path)
          Collapses the given path, is possible.
 void collapseRow(JTree tree, int row)
          Collapses the given row, is possible.
 void doubleClickPath(JTree tree, String path)
          Double-clicks the given path.
 void doubleClickRow(JTree tree, int row)
          Double-clicks the given row.
 void drag(JTree tree, int row)
          Starts a drag operation at the location of the given row.
 void drag(JTree tree, String path)
          Starts a drag operation at the location of the given TreePath.
 void drop(JTree tree, int row)
          Ends a drag operation at the location of the given row.
 void drop(JTree tree, String path)
          Ends a drag operation at the location of the given TreePath.
 void expandPath(JTree tree, String path)
          Expands the given path, is possible.
 void expandRow(JTree tree, int row)
          Expands the given row, is possible.
 String nodeValue(JTree tree, int row)
          Returns the String representation of the node at the given row index.
 String nodeValue(JTree tree, String path)
          Returns the String representation of the node at the given path.
 void replaceCellReader(JTreeCellReader newCellReader)
          Updates the implementation of JTreeCellReader to use when comparing internal values of a JTree and the values expected in a test.
 void replaceSeparator(String newSeparator)
          Updates the separator to use when converting TreePaths to Strings.
 void requireEditable(JTree tree)
          Asserts that the given JTree is editable.
 void requireNoSelection(JTree tree)
          Asserts that the given JTree does not have any selection.
 void requireNotEditable(JTree tree)
          Asserts that the given JTree is not editable.
 void requireSelection(JTree tree, int[] rows)
          Asserts that the given JTree's selected rows are equal to the given one.
 void requireSelection(JTree tree, String[] paths)
          Asserts that the given JTree's selected paths are equal to the given one.
 void rightClickPath(JTree tree, String path)
          Right-clicks the given path, expanding parent nodes if necessary.
 void rightClickRow(JTree tree, int row)
          Right-clicks the given row.
 void selectPath(JTree tree, String path)
          Selects the given path, expanding parent nodes if necessary.
 void selectPaths(JTree tree, String[] paths)
          Selects the given paths, expanding parent nodes if necessary.
 void selectRow(JTree tree, int row)
          Selects the given row.
 void selectRows(JTree tree, int[] rows)
          Selects the given rows.
 String separator()
           
 JPopupMenu showPopupMenu(JTree tree, int row)
          Shows a pop-up menu at the position of the node in the given row.
 JPopupMenu showPopupMenu(JTree tree, String path)
          Shows a pop-up menu at the position of the last node in the given path.
 void toggleRow(JTree tree, int row)
          Change the open/closed state of the given row, if possible.
 
Methods inherited from class org.assertj.swing.driver.JComponentDriver
clientProperty, invokeAction, isVisible, isVisible, requireToolTip, requireToolTip, scrollToVisible
 
Methods inherited from class org.assertj.swing.driver.ContainerDriver
doResizeHeight, doResizeWidth, isResizable, move, resize
 
Methods inherited from class org.assertj.swing.driver.ComponentDriver
backgroundOf, checkInEdtEnabledAndShowing, click, click, click, click, click, doubleClick, drag, dragOver, drop, focus, focusAndWaitForFocusGain, fontOf, foregroundOf, 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

JTreeDriver

public JTreeDriver(@Nonnull
                   Robot robot)
Creates a new JTreeDriver.

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

clickRow

@RunsInEDT
public void clickRow(@Nonnull
                               JTree tree,
                               int row)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.

clickRow

@RunsInEDT
public void clickRow(@Nonnull
                               JTree tree,
                               int row,
                               @Nonnull
                               MouseButton button)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
button - the mouse button to use.
Throws:
NullPointerException - if the given 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.

clickRow

@RunsInEDT
public void clickRow(@Nonnull
                               JTree tree,
                               int row,
                               @Nonnull
                               MouseClickInfo mouseClickInfo)
Clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
mouseClickInfo - specifies the mouse button to use and how many times to click.
Throws:
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.

doubleClickRow

@RunsInEDT
public void doubleClickRow(@Nonnull
                                     JTree tree,
                                     int row)
Double-clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.

rightClickRow

@RunsInEDT
public void rightClickRow(@Nonnull
                                    JTree tree,
                                    int row)
Right-clicks the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.

clickPath

@RunsInEDT
public void clickPath(@Nonnull
                                JTree tree,
                                @Nonnull
                                String path)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

clickPath

@RunsInEDT
public void clickPath(@Nonnull
                                JTree tree,
                                @Nonnull
                                String path,
                                @Nonnull
                                MouseButton button)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
button - the mouse button to use.
Throws:
NullPointerException - if the given button is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

clickPath

@RunsInEDT
public void clickPath(@Nonnull
                                JTree tree,
                                @Nonnull
                                String path,
                                @Nonnull
                                MouseClickInfo mouseClickInfo)
Clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
mouseClickInfo - specifies the mouse button to use and how many times to click.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

doubleClickPath

@RunsInEDT
public void doubleClickPath(@Nonnull
                                      JTree tree,
                                      @Nonnull
                                      String path)
Double-clicks the given path.

Parameters:
tree - the target JTree.
path - the path to double-click.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

rightClickPath

@RunsInEDT
public void rightClickPath(@Nonnull
                                     JTree tree,
                                     @Nonnull
                                     String path)
Right-clicks the given path, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
path - the path to path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

expandRow

@RunsInEDT
public void expandRow(@Nonnull
                                JTree tree,
                                int row)
Expands the given row, is possible. If the row is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.
ActionFailedException - if this method fails to expand the row.

collapseRow

@RunsInEDT
public void collapseRow(@Nonnull
                                  JTree tree,
                                  int row)
Collapses the given row, is possible. If the row is already collapsed, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.
ActionFailedException - if this method fails to collapse the row.

toggleRow

@RunsInEDT
public void toggleRow(@Nonnull
                                JTree tree,
                                int row)
Change the open/closed state of the given row, if possible.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.
ActionFailedException - if this method fails to toggle the row.

expandPath

@RunsInEDT
public void expandPath(@Nonnull
                                 JTree tree,
                                 @Nonnull
                                 String path)
Expands the given path, is possible. If the path is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
path - the path to expand.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if this method fails to expand the path.

collapsePath

@RunsInEDT
public void collapsePath(@Nonnull
                                   JTree tree,
                                   @Nonnull
                                   String path)
Collapses the given path, is possible. If the path is already expanded, this method will not do anything.

NOTE: a reasonable assumption is that the toggle control is just to the left of the row bounds and is roughly a square the dimensions of the row height. Clicking in the center of that square should work.

Parameters:
tree - the target JTree.
path - the path to collapse.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if this method fails to collapse the path.

selectRows

@RunsInEDT
public void selectRows(@Nonnull
                                 JTree tree,
                                 @Nonnull
                                 int[] rows)
Selects the given rows.

Parameters:
tree - the target JTree.
rows - the rows to select.
Throws:
NullPointerException - if the array of rows is null.
IllegalArgumentException - if the array of rows is empty.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
IndexOutOfBoundsException - if any of the given rows 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.

selectRow

@RunsInEDT
public void selectRow(@Nonnull
                                JTree tree,
                                int row)
Selects the given row.

Parameters:
tree - the target JTree.
row - the row to select.
Throws:
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.

selectPaths

@RunsInEDT
public void selectPaths(@Nonnull
                                  JTree tree,
                                  @Nonnull
                                  String[] paths)
Selects the given paths, expanding parent nodes if necessary.

Parameters:
tree - the target JTree.
paths - the paths to select.
Throws:
NullPointerException - if the array of rows is null.
IllegalArgumentException - if the array of rows is empty.
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if any the given path cannot be found.

selectPath

@RunsInEDT
public void selectPath(@Nonnull
                                 JTree tree,
                                 @Nonnull
                                 String path)
Selects the given path, expanding parent nodes if necessary. Unlike clickPath(JTree, String), this method will not click the path if it is already selected

Parameters:
tree - the target JTree.
path - the path to select.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.

showPopupMenu

@RunsInEDT
@Nonnull
public JPopupMenu showPopupMenu(@Nonnull
                                                  JTree tree,
                                                  int row)
Shows a pop-up menu at the position of the node in the given row.

Parameters:
tree - the target JTree.
row - the given row.
Returns:
a driver that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.
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.

showPopupMenu

@RunsInEDT
@Nonnull
public JPopupMenu showPopupMenu(@Nonnull
                                                  JTree tree,
                                                  @Nonnull
                                                  String path)
Shows a pop-up menu at the position of the last node in the given path. The last node in the given path will be made visible (by expanding the parent node(s)) if it is not visible.

Parameters:
tree - the target JTree.
path - the given path.
Returns:
a driver that manages the displayed pop-up menu.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
ComponentLookupException - if a pop-up menu cannot be found.
LocationUnavailableException - if the given path cannot be found.
See Also:
replaceSeparator(String)

drag

@RunsInEDT
public void drag(@Nonnull
                           JTree tree,
                           int row)
Starts a drag operation at the location of the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.

drop

@RunsInEDT
public void drop(@Nonnull
                           JTree tree,
                           int row)
Ends a drag operation at the location of the given row.

Parameters:
tree - the target JTree.
row - the given row.
Throws:
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.
ActionFailedException - if there is no drag action in effect.

drag

@RunsInEDT
public void drag(@Nonnull
                           JTree tree,
                           @Nonnull
                           String path)
Starts a drag operation at the location of the given TreePath.

Parameters:
tree - the target JTree.
path - the given path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
See Also:
replaceSeparator(String)

drop

@RunsInEDT
public void drop(@Nonnull
                           JTree tree,
                           @Nonnull
                           String path)
Ends a drag operation at the location of the given TreePath.

Parameters:
tree - the target JTree.
path - the given path.
Throws:
IllegalStateException - if the JTree is disabled.
IllegalStateException - if the JTree is not showing on the screen.
LocationUnavailableException - if the given path cannot be found.
ActionFailedException - if there is no drag action in effect.
See Also:
replaceSeparator(String)

requireSelection

@RunsInEDT
public void requireSelection(@Nonnull
                                       JTree tree,
                                       @Nonnull
                                       int[] rows)
Asserts that the given JTree's selected rows are equal to the given one.

Parameters:
tree - the target JTree.
rows - the indices of the rows, expected to be selected.
Throws:
NullPointerException - if the array of row indices is null.
AssertionError - if the given JTree selection is not equal to the given rows.

requireSelection

@RunsInEDT
public void requireSelection(@Nonnull
                                       JTree tree,
                                       @Nonnull
                                       String[] paths)
Asserts that the given JTree's selected paths are equal to the given one.

Parameters:
tree - the target JTree.
paths - the given paths, expected to be selected.
Throws:
NullPointerException - if the array of paths is null.
LocationUnavailableException - if any of the given paths cannot be found.
AssertionError - if the given JTree selection is not equal to the given paths.
See Also:
replaceSeparator(String)

requireNoSelection

@RunsInEDT
public void requireNoSelection(@Nonnull
                                         JTree tree)
Asserts that the given JTree does not have any selection.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree has a selection.

requireEditable

@RunsInEDT
public void requireEditable(@Nonnull
                                      JTree tree)
Asserts that the given JTree is editable.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree is not editable.

requireNotEditable

@RunsInEDT
public void requireNotEditable(@Nonnull
                                         JTree tree)
Asserts that the given JTree is not editable.

Parameters:
tree - the given JTree.
Throws:
AssertionError - if the JTree is editable.

separator

@Nonnull
public String separator()
Returns:
the separator to use when converting TreePaths to Strings.

replaceSeparator

public void replaceSeparator(@Nonnull
                             String newSeparator)
Updates the separator to use when converting TreePaths to Strings.

Parameters:
newSeparator - the new separator.
Throws:
NullPointerException - if the given separator is null.

replaceCellReader

public void replaceCellReader(@Nonnull
                              JTreeCellReader newCellReader)
Updates the implementation of JTreeCellReader to use when comparing internal values of a JTree and the values expected in a test.

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

checkRowInBounds

@RunsInEDT
public void checkRowInBounds(@Nonnull
                                       JTree tree,
                                       int row)
Verifies that the given row index is valid.

Parameters:
tree - the given JTree.
row - the given index.
Throws:
IndexOutOfBoundsException - if the given index is less than zero or equal than or greater than the number of visible rows in the JTree.

checkPathExists

@RunsInEDT
public void checkPathExists(@Nonnull
                                      JTree tree,
                                      @Nonnull
                                      String path)
Verifies that the given node path exists.

Parameters:
tree - the given JTree.
path - the given path.
Throws:
LocationUnavailableException - if the given path cannot be found.

nodeValue

@RunsInEDT
@Nullable
public String nodeValue(@Nonnull
                                           JTree tree,
                                           @Nonnull
                                           String path)
Returns the String representation of the node at the given path.

Parameters:
tree - the given JTree.
path - the given path.
Returns:
the String representation of the node at the given path.
Throws:
LocationUnavailableException - if the given path cannot be found.

nodeValue

@Nullable
public String nodeValue(@Nonnull
                                 JTree tree,
                                 int row)
Returns the String representation of the node at the given row index.

Parameters:
tree - the given JTree.
row - the given row.
Returns:
the String representation of the node at the given row index.
Throws:
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.


Copyright © 2014–2015 AssertJ. All rights reserved.