Class JListDriver


public class JListDriver extends JComponentDriver
Understands functional testing of JLists:
  • user input simulation
  • state verification
  • property value query
This class is intended for internal use only. Please use the classes in the package org.fest.swing.fixture in your tests.
  • Field Details

  • Constructor Details

    • JListDriver

      public JListDriver(Robot robot)
      Creates a new JListDriver.
      Parameters:
      robot - the robot to use to simulate user input.
  • Method Details

    • contentsOf

      @RunsInEDT public String[] contentsOf(JList list)
      Returns an array of Strings that represents the contents of the given JList, using this driver's JListCellReader.
      Parameters:
      list - the target JList.
      Returns:
      an array of Strings that represents the contents of the given JList.
      See Also:
    • selectItems

      @RunsInEDT public void selectItems(JList list, String[] values)
      Selects the items matching the given values.
      Parameters:
      list - the target JList.
      values - the values to match. Each String can be a regular expression.
      Throws:
      NullPointerException - if the given array is null.
      IllegalArgumentException - if the given array is empty.
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the any of the given values cannot be found.
    • selectItems

      @RunsInEDT public void selectItems(JList list, Pattern[] patterns)
      Selects the items matching the given regular expression patterns.
      Parameters:
      list - the target JList.
      patterns - the regular expression patterns to match.
      Throws:
      NullPointerException - if the given array is null.
      NullPointerException - if any of the regular expression patterns is null.
      IllegalArgumentException - if the given array is empty.
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the any of the given regular expression patterns cannot be found.
      Since:
      1.2
    • selectItems

      @RunsInEDT private void selectItems(JList list, TextMatcher matcher)
    • selectItem

      @RunsInEDT public void selectItem(JList list, String value)
      Selects the item in the given JList whose value matches the given one.
      Parameters:
      list - the target JList.
      value - the value to match.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the given value cannot be found.
    • selectItem

      @RunsInEDT public void selectItem(JList list, Pattern pattern)
      Selects the item in the given JList whose value matches the given regular expression pattern.
      Parameters:
      list - the target JList.
      pattern - the regular expression to match.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the given value cannot be found.
      NullPointerException - if the given regular expression pattern is null.
      Since:
      1.2
    • selectItem

      @RunsInEDT private void selectItem(JList list, TextMatcher matcher)
    • clickItem

      public void clickItem(JList list, String value, MouseButton button, int times)
      Clicks the first item matching the given value, using the specified mouse button, the given number times.
      Parameters:
      list - the target JList.
      value - the value to match.
      button - the button to use.
      times - the number of times to click.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the given value cannot be found.
    • clickItem

      public void clickItem(JList list, Pattern pattern, MouseButton button, int times)
      Clicks the first item matching the given regular expression pattern, using the specified mouse button, the given number times.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      button - the button to use.
      times - the number of times to click.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      NullPointerException - if the given regular expression pattern is null.
      LocationUnavailableException - if an element matching the given regular expression pattern cannot be found.
      Since:
      1.2
    • clickItem

      private void clickItem(JList list, TextMatcher matcher, MouseButton button, int times)
    • selectItems

      public void selectItems(JList list, int[] indices)
      Selects the items under the given indices.
      Parameters:
      list - the target JList.
      indices - the indices of the items to select.
      Throws:
      NullPointerException - if the given array is null.
      IllegalArgumentException - if the given array is empty.
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if any of the indices is negative or greater than the index of the last item in the JList.
    • clearSelection

      public void clearSelection(JList list)
      Clears the selection in the given JList. Since this method does not simulate user input, it does not verifies that the JList is enabled and showing.
      Parameters:
      list - the target JList.
      Since:
      1.2
    • clearSelectionOf

      @RunsInEDT private static void clearSelectionOf(JList list)
    • selectItems

      @RunsInEDT public void selectItems(JList list, Range.From from, Range.To to)
      Selects the items in the specified range.
      Parameters:
      list - the target JList.
      from - the starting point of the selection.
      to - the last item to select.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the any index is negative or greater than the index of the last item in the JList.
    • selectItems

      @RunsInEDT public void selectItems(JList list, int start, int end)
      Selects the items in the specified range.
      Parameters:
      list - the target JList.
      start - the starting point of the selection.
      end - the last item to select (inclusive.)
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the any index is negative or greater than the index of the last item in the JList.
    • validateIndicesAndClearSelection

      @RunsInEDT private static void validateIndicesAndClearSelection(JList list, int... indices)
    • selectItem

      @RunsInEDT public void selectItem(JList list, int index)
      Selects the item under the given index using left mouse button once.
      Parameters:
      list - the target JList.
      index - the index of the item to click.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
    • clickItem

      @RunsInEDT public void clickItem(JList list, int index, MouseButton button, int times)
      Clicks the item under the given index, using the specified mouse button, the given number times.
      Parameters:
      list - the target JList.
      index - the index of the item to click.
      button - the button to use.
      times - the number of times to click.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
    • requireSelection

      @RunsInEDT public void requireSelection(JList list, String value)
      Verifies that the selected item in the JList matches the given value.
      Parameters:
      list - the target JList.
      value - the value to match. It can be a regular expression pattern.
      Throws:
      AssertionError - if the selected item does not match the value.
      See Also:
    • requireSelection

      @RunsInEDT public void requireSelection(JList list, Pattern pattern)
      Verifies that the selected item in the JList matches the given regular expression pattern.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      Throws:
      AssertionError - if the selected item does not match the given regular expression pattern.
      NullPointerException - if the given regular expression pattern is null.
      Since:
      1.2
      See Also:
    • requiredSelection

      private String requiredSelection(JList list)
    • requireSelection

      @RunsInEDT public void requireSelection(JList list, int index)
      Verifies that the selected index in the JList matches the given value.
      Parameters:
      list - the target JList.
      index - the selection index to match.
      Throws:
      AssertionError - if the selected index does not match the value.
      Since:
      1.2
    • selectionOf

      @RunsInEDT public String[] selectionOf(JList list)
      Returns an array of Strings that represents the selection in the given JList, using this driver's JListCellReader.
      Parameters:
      list - the target JList.
      Returns:
      an array of Strings that represents the selection in the given JList.
      See Also:
    • requireSelectedItems

      @RunsInEDT public void requireSelectedItems(JList list, String... items)
      Verifies that the selected items in the JList match the given values.
      Parameters:
      list - the target JList.
      items - the values to match. Each value can be a regular expression pattern.
      Throws:
      NullPointerException - if the given array is null.
      IllegalArgumentException - if the given array is empty.
      AssertionError - if the selected items do not match the given values.
    • requireSelectedItems

      @RunsInEDT public void requireSelectedItems(JList list, Pattern... patterns)
      Verifies that the selected items in the JList match the given regular expression patterns.
      Parameters:
      list - the target JList.
      patterns - the regular expression patterns to match.
      Throws:
      NullPointerException - if the given array is null.
      IllegalArgumentException - if the given array is empty.
      NullPointerException - if any of the patterns in the array is null.
      AssertionError - if the selected items do not match the given values.
      Since:
      1.2
      See Also:
    • requireSelectedItems

      @RunsInEDT private void requireSelectedItems(JList list, TextMatcher matcher)
    • requireSelectedItems

      @RunsInEDT public void requireSelectedItems(JList list, int... indices)
      Verifies that the given item indices are selected in the JList.
      Parameters:
      list - the target JList.
      indices - the expected indices of the selected items.
      Throws:
      NullPointerException - if the given array is null.
      IllegalArgumentException - if the given array is empty.
      AssertionError - if the selection in the JList does not match the given one.
    • validateArrayOfIndices

      private void validateArrayOfIndices(int[] indices)
    • requireNoSelection

      @RunsInEDT public void requireNoSelection(JList list)
      Verifies that the JList does not have a selection.
      Parameters:
      list - the target JList.
      Throws:
      AssertionError - if the JList has a selection.
    • failNoSelection

      @RunsInEDT private void failNoSelection(JList list)
    • selectedIndexProperty

      @RunsInEDT private org.fest.assertions.Description selectedIndexProperty(JList list)
    • drag

      @RunsInEDT public void drag(JList list, String value)
      Starts a drag operation at the location of the first item matching the given value.
      Parameters:
      list - the target JList.
      value - the value to match. It can be a regular expression.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the given value cannot be found.
      See Also:
    • drag

      @RunsInEDT public void drag(JList list, Pattern pattern)
      Starts a drag operation at the location of the first item matching the given regular expression pattern.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      NullPointerException - if the regular expression pattern is null.
      LocationUnavailableException - if an element matching the given regular expression pattern cannot be found.
      Since:
      1.2
      See Also:
    • drag

      private void drag(JList list, TextMatcher matcher)
    • drop

      @RunsInEDT public void drop(JList list, String value)
      Ends a drag operation at the location of the first item matching the given value.
      Parameters:
      list - the target JList.
      value - the value to match. It can be a regular expression.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      LocationUnavailableException - if an element matching the given value cannot be found.
      ActionFailedException - if there is no drag action in effect.
    • drop

      public void drop(JList list, Pattern pattern)
      Ends a drag operation at the location of the first item matching the given regular expression pattern.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      NullPointerException - if the given regular expression pattern is null.
      LocationUnavailableException - if an element matching the given value cannot be found.
      ActionFailedException - if there is no drag action in effect.
      Since:
      1.2
    • drop

      private void drop(JList list, TextMatcher matcher)
    • verify

      private void verify(JList list, Pair<Integer,Point> scrollInfo, TextMatcher matcher)
    • drag

      @RunsInEDT public void drag(JList list, int index)
      Starts a drag operation at the location of the given index.
      Parameters:
      list - the target JList.
      index - the given index.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
    • drop

      @RunsInEDT public void drop(JList list, int index)
      Ends a drag operation at the location of the given index.
      Parameters:
      list - the target JList.
      index - the given index.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
      ActionFailedException - if there is no drag action in effect.
    • drop

      @RunsInEDT public void drop(JList list)
      Ends a drag operation at the center of the JList.
      Parameters:
      list - the target JList.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      ActionFailedException - if there is no drag action in effect.
    • showPopupMenu

      @RunsInEDT public JPopupMenu showPopupMenu(JList list, String value)
      Shows a pop-up menu at the location of the specified item in the JList.
      Parameters:
      list - the target JList.
      value - the value to match. It can be a regular expression pattern.
      Returns:
      a fixture that manages the displayed pop-up menu.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      ComponentLookupException - if a pop-up menu cannot be found.
      LocationUnavailableException - if an element matching the given value cannot be found.
    • showPopupMenu

      @RunsInEDT public JPopupMenu showPopupMenu(JList list, Pattern pattern)
      Shows a pop-up menu at the location of the specified item in the JList.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      Returns:
      a fixture that manages the displayed pop-up menu.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      NullPointerException - if the regular expression pattern is null.
      ComponentLookupException - if a pop-up menu cannot be found.
      LocationUnavailableException - if an element matching the given value cannot be found.
      Since:
      1.2
    • showPopupMenu

      @RunsInEDT private JPopupMenu showPopupMenu(JList list, TextMatcher matcher)
    • cellCenterIn

      private Point cellCenterIn(Pair<Integer,Point> scrollInfo)
    • showPopupMenu

      @RunsInEDT public JPopupMenu showPopupMenu(JList list, int index)
      Shows a pop-up menu at the location of the specified item in the JList.
      Parameters:
      list - the target JList.
      index - the index of the item.
      Returns:
      a driver that manages the displayed pop-up menu.
      Throws:
      IllegalStateException - if the JList is disabled.
      IllegalStateException - if the JList is not showing on the screen.
      ComponentLookupException - if a pop-up menu cannot be found.
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
    • pointAt

      @RunsInEDT public Point pointAt(JList list, String value)
      Returns the coordinates of the first item matching the given value.
      Parameters:
      list - the target JList.
      value - the value to match.
      Returns:
      the coordinates of the item at the given item.
      Throws:
      LocationUnavailableException - if an element matching the given value cannot be found.
    • indexOf

      @RunsInEDT public int indexOf(JList list, String value)
      Returns the index of the first item matching the given value.
      Parameters:
      list - the target JList
      value - the value to match. It can be a regular expression.
      Returns:
      the index of the first item matching the given value.
      Throws:
      LocationUnavailableException - if an element matching the given value cannot be found.
    • indexOf

      @RunsInEDT public int indexOf(JList list, Pattern pattern)
      Returns the index of the first item matching the given regular expression pattern.
      Parameters:
      list - the target JList.
      pattern - the regular expression pattern to match.
      Returns:
      the index of the first item matching the given regular expression pattern.
      Throws:
      LocationUnavailableException - if an element matching the given value cannot be found.
      NullPointerException - if the given regular expression pattern is null.
      Since:
      1.2
    • indexOf

      @RunsInEDT private int indexOf(JList list, TextMatcher matcher)
    • itemIndex

      @RunsInEDT private static int itemIndex(JList list, TextMatcher matcher, JListCellReader cellReader)
    • failMatchingNotFound

      private LocationUnavailableException failMatchingNotFound(JList list, TextMatcher matcher)
    • value

      @RunsInEDT public String value(JList list, int index)
      Returns the String representation of the element under the given index, using this driver's JListCellReader.
      Parameters:
      list - the target JList.
      index - the given index.
      Returns:
      the value of the element under the given index.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or greater than the index of the last item in the JList.
      See Also:
    • cellReader

      public void cellReader(JListCellReader newCellReader)
      Updates the implementation of JListCellReader to use when comparing internal values of a JList and the values expected in a test.
      Parameters:
      newCellReader - the new JListCellValueReader to use.
      Throws:
      NullPointerException - if newCellReader is null.
    • requireItemCount

      @RunsInEDT public void requireItemCount(JList list, int expected)
      Verifies that number of items in the given JList is equal to the expected one.
      Parameters:
      list - the target JList.
      expected - the expected number of items.
      Throws:
      AssertionError - if the number of items in the given JList is not equal to the expected one.
      Since:
      1.2