Class TextFlowMatchers

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

public class TextFlowMatchers extends Object
TestFX matchers for TextFlow controls.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.hamcrest.Matcher<javafx.scene.text.TextFlow>
    hasColoredText(String coloredTextMarkup)
    Allows one to verify both the content and color of the text that makes up a TextFlow.
    static org.hamcrest.Matcher<javafx.scene.text.TextFlow>
    hasExactlyColoredText(String coloredTextMarkup)
    Allows one to verify both the content and color of the text that makes up a TextFlow.
    static org.hamcrest.Matcher<javafx.scene.text.TextFlow>
    hasText(String string)
    Creates a matcher that matches all (TextFlows whose "text" (the result of combining all of its Text children's text together) equals the given string.

    Methods inherited from class Object

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

    • hasText

      public static org.hamcrest.Matcher<javafx.scene.text.TextFlow> hasText(String string)
      Creates a matcher that matches all (TextFlows whose "text" (the result of combining all of its Text children's text together) equals the given string.
      Parameters:
      string - the text that matching TextFlows should have
      Returns:
      a match if the text contained in the TextFlow has the same text as the given string
    • hasColoredText

      public static org.hamcrest.Matcher<javafx.scene.text.TextFlow> hasColoredText(String coloredTextMarkup)
      Allows one to verify both the content and color of the text that makes up a TextFlow. The color is matched by using the closest named color, as described below.

      Colors are specified using the following markup:

      <COLOR>text</COLOR>

      Where COLOR is one of JavaFX's named colors.

      Here is an example for verifying that a TextFlow contains the text "hello" and that the named color that has the closest value to the color of the text is Colors.RED:

        Text text = new Text("hello");
        text.setFill(Colors.RED);
        TextFlow textFlow = new TextFlow(text);
        assertThat(textFlow, TextFlowMatchers.hasColoredText("<RED>hello</RED>"));
      
      Parameters:
      coloredTextMarkup - the text contained in the TextFlow with color markup that specifies the expected color of the text
      Returns:
      a match if the text contained in the TextFlow has the same content and colors that match by the "closest named color" criteria
      See Also:
    • hasExactlyColoredText

      public static org.hamcrest.Matcher<javafx.scene.text.TextFlow> hasExactlyColoredText(String coloredTextMarkup)
      Allows one to verify both the content and color of the text that makes up a TextFlow. The color is matched in an exact way, as described below.

      Colors are specified using the following markup:

      <COLOR>text</COLOR>

      Where COLOR is one of JavaFX's named colors.

      Here is an example for verifying that a TextFlow contains the text "hello" and that the color of the text is exactly Colors.BLUE (that is, it has an RGB value of (0, 0, 255)).

        Text text = new Text("hello");
        text.setFill(Colors.BLUE); // or: text.setFill(Colors.rgb(0, 0, 255));
        TextFlow textFlow = new TextFlow(text);
        assertThat(textFlow, TextFlowMatchers.hasExactlyColoredText("hello"));
      
      Parameters:
      coloredTextMarkup - the text contained in the TextFlow with color markup that specifies the expected color of the text
      Returns:
      a match if the text contained in the TextFlow has the same content and the exactly matching colors
      See Also: