Class TableViewMatchers

java.lang.Object
org.testfx.matcher.control.TableViewMatchers

public class TableViewMatchers extends Object
TestFX matchers for TableView controls.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.hamcrest.Matcher<javafx.scene.control.TableView>
    containsRow(Object... cells)
    Creates a matcher that matches all TableViews that have at least one row that contains the given values for each column of a TableView.
    private static <T> boolean
    containsRow(javafx.scene.control.TableView<T> tableView, Object... cells)
     
    static org.hamcrest.Matcher<javafx.scene.control.TableView>
    containsRowAtIndex(int rowIndex, Object... cells)
    Creates a matcher that matches all TableViews that have a row at the given index that contains the given values for each column of a TableView.
    private static <T> boolean
    containsRowAtIndex(javafx.scene.control.TableView<T> tableView, int rowIndex, Object... cells)
     
    private static List<javafx.beans.value.ObservableValue<?>>
    getRowValues(javafx.scene.control.TableView<?> tableView, int rowIndex)
     
    private static boolean
    hasCellValue(javafx.scene.control.Cell cell, Object value)
     
    static org.hamcrest.Matcher<javafx.scene.control.TableView>
    hasItems(int rows)
    Deprecated.
    private static boolean
    hasItemValue(Object item, Object value)
     
    static org.hamcrest.Matcher<javafx.scene.control.TableView>
    hasNumRows(int rows)
    Creates a matcher that matches all TableViews that have exactly amount rows.
    static org.hamcrest.Matcher<javafx.scene.control.TableView>
    Creates a matcher that matches all TableViews that has a TableCell whose value or value.toString() equals the given value.
    private static boolean
    hasTableCell(javafx.scene.control.TableView tableView, Object value)
     
    private static String
    toText(javafx.scene.control.TableView<?> tableView)
    Returns a textual representation of all rows of the given tableView.
    private static String
    toText(javafx.scene.control.TableView<?> tableView, int rowIndex)
    Returns a textual representation of one row (specified by rowIndex) of the given tableView.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • TableViewMatchers

      private TableViewMatchers()
  • Method Details

    • hasTableCell

      public static org.hamcrest.Matcher<javafx.scene.control.TableView> hasTableCell(Object value)
      Creates a matcher that matches all TableViews that has a TableCell whose value or value.toString() equals the given value.

      Test code must ensure that the cell is visible by scrolling it into the viewport before using the matcher:

      
       int row = ...
       int col = ...
       tableView.scrollTo(row);
       tableView.scrollToColumn(col);
       verifyThat(tableView, hasTableCell(contentOfCell);
       
    • hasItems

      @Deprecated public static org.hamcrest.Matcher<javafx.scene.control.TableView> hasItems(int rows)
      Deprecated.
      Creates a matcher that matches all TableViews that have exactly amount items.
    • hasNumRows

      public static org.hamcrest.Matcher<javafx.scene.control.TableView> hasNumRows(int rows)
      Creates a matcher that matches all TableViews that have exactly amount rows.
    • containsRowAtIndex

      public static org.hamcrest.Matcher<javafx.scene.control.TableView> containsRowAtIndex(int rowIndex, Object... cells)
      Creates a matcher that matches all TableViews that have a row at the given index that contains the given values for each column of a TableView.

      For example, given a TableView that has three columns:

      
       TableColumn<RegularPolygon, String> nameColumn = new TableColumn<>("Name");
       TableColumn<RegularPolygon, Integer> numSidesColumn = new TableColumn<>("Number of Sides");
       TableColumn<RegularPolygon, Double> unitAreaColumn = new TableColumn<>("Area when Side = 1");
       polygonsTable.getColumns().setAll(nameColumn, numSidesColumn, unitAreaColumn);
       
      Then to verify that such a TableView, contains, at index 3, a row for a RegularPolygon that has the name "Pentagon", the number of sides 5, and a unit area of 1.720477401 one would use:
      
       verifyThat("#polygonsTable", TableViewMatchers.containsRowAtIndex(3, "Pentagon", 5, 1.720477401);
       
      Where the types of each argument, after the row index, correspond to the types of the TableColumns which in our example is (String, Integer, Double).
      Parameters:
      rowIndex - the row number (starting from 0) that must contains the given cell values
      cells - The values or String representations of the values (e.g. the result of calling toString()) contained in the row at a given index you want to verify a TableView contains - one such value for each column of that TableView. Use null if the value is expected to not be set or if no cell value factory has been set.
    • containsRow

      public static org.hamcrest.Matcher<javafx.scene.control.TableView> containsRow(Object... cells)
      Creates a matcher that matches all TableViews that have at least one row that contains the given values for each column of a TableView.

      For example, given a TableView that has three columns:

      
       TableColumn<Person, String> nameColumn = new TableColumn<>("Name");
       TableColumn<Person, Double> bmiColumn = new TableColumn<>("Body Mass Index");
       TableColumn<Person, Boolean> membershipColumn = new TableColumn<>("Gym Membership Valid");
       fitnessTable.getColumns().setAll(nameColumn, bmiColumn, membershipColumn);
       
      Then to verify that such a TableView, contains at least one row with a Person that has the name "Dan Anderson", the body mass index 28.83, and a valid gym membership (true) one would use:
      
       verifyThat("#fitnessTable", TableViewMatchers.containsRow("Dan Anderson", 28.83, true);
       
      Where the types of each argument correspond to the types of the TableColumns which in our example is (String, Double, Boolean).
      Parameters:
      cells - The values or String representations of the values (e.g. the result of calling toString()) contained in the row you want to verify a TableView contains - one such value for each column of that TableView. Use null if the value is expected to not be set or if no cell value factory has been set.
    • hasTableCell

      private static boolean hasTableCell(javafx.scene.control.TableView tableView, Object value)
    • containsRowAtIndex

      private static <T> boolean containsRowAtIndex(javafx.scene.control.TableView<T> tableView, int rowIndex, Object... cells)
    • getRowValues

      private static List<javafx.beans.value.ObservableValue<?>> getRowValues(javafx.scene.control.TableView<?> tableView, int rowIndex)
    • toText

      private static String toText(javafx.scene.control.TableView<?> tableView)
      Returns a textual representation of all rows of the given tableView.
    • toText

      private static String toText(javafx.scene.control.TableView<?> tableView, int rowIndex)
      Returns a textual representation of one row (specified by rowIndex) of the given tableView.
    • containsRow

      private static <T> boolean containsRow(javafx.scene.control.TableView<T> tableView, Object... cells)
    • hasCellValue

      private static boolean hasCellValue(javafx.scene.control.Cell cell, Object value)
    • hasItemValue

      private static boolean hasItemValue(Object item, Object value)