Class MatchesTextCondition

java.lang.Object
uk.org.webcompere.modelassert.json.condition.MatchesTextCondition
All Implemented Interfaces:
Condition

public class MatchesTextCondition extends Object implements Condition
A text node matches a regular expression
  • Constructor Details

    • MatchesTextCondition

      public MatchesTextCondition(Pattern pattern)
      Create a condition which requires the text to meet the pattern
      Parameters:
      pattern - regex that must match
    • MatchesTextCondition

      public MatchesTextCondition(Pattern pattern, String conditionName)
      Create a condition which requires the text to meet the pattern
      Parameters:
      pattern - regex that must match
      conditionName - the name of the condition for the description
    • MatchesTextCondition

      public MatchesTextCondition(String conditionName, Predicate<String> predicate)
      Create a custom text condition
      Parameters:
      conditionName - the name of the condition
      predicate - the predicate to meet on the text
  • Method Details

    • textContains

      public static MatchesTextCondition textContains(String contains)
      Build a text contains condition
      Parameters:
      contains - the substring to search
      Returns:
      a new MatchesTextCondition condition
    • textStartsWith

      public static MatchesTextCondition textStartsWith(String substring)
      Build a text starts with condition
      Parameters:
      substring - the substring to search
      Returns:
      a new MatchesTextCondition condition
    • textMatches

      public static MatchesTextCondition textMatches(Pattern pattern)
      Build a matcher condition
      Parameters:
      pattern - the pattern to match
      Returns:
      a new MatchesTextCondition condition
    • test

      public Result test(com.fasterxml.jackson.databind.JsonNode json)
      Execute the test of the condition
      Specified by:
      test in interface Condition
      Parameters:
      json - the json to test
      Returns:
      a Result explaining whether the condition was met and if not, why not
    • describe

      public String describe()
      Describe the condition
      Specified by:
      describe in interface Condition
      Returns:
      description of the condition