Class FluentStringAssertion<R>

Type Parameters:
R - The return type.
Direct Known Subclasses:
FluentRequestFormParamAssertion, FluentRequestHeaderAssertion, FluentRequestQueryParamAssertion, FluentResponseHeaderAssertion, StringAssertion

  • Constructor Details

    • FluentStringAssertion

      public FluentStringAssertion(String value, R returns)
      Constructor.
      Parameters:
      value - The object being tested.
      Can be null.
      returns - The object to return after a test method is called.
      If null, the test method returns this object allowing multiple test method calls to be used on the same assertion.
    • FluentStringAssertion

      public FluentStringAssertion(Assertion creator, String value, R returns)
      Chained constructor.

      Used when transforming one assertion into another so that the assertion config can be used by the new assertion.

      Parameters:
      creator - The assertion that created this assertion.
      Should be null if this is the top-level assertion.
      value - The object being tested.
      Can be null.
      returns - The object to return after a test method is called.
      If null, the test method returns this object allowing multiple test method calls to be used on the same assertion.
  • Method Details

    • asJavaStrings

      When enabled, text in the message is converted to valid Java strings.

      value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n", "\\\\n").replaceAll("\t", "\\\\t");

      Returns:
      This object.
    • asTransformed

      Description copied from class: FluentObjectAssertion
      Applies a transform on the inner object and returns a new inner object.
      Overrides:
      asTransformed in class FluentObjectAssertion<String,R>
      Parameters:
      function - The function to apply.
      Returns:
      This object.
    • asReplaceAll

      public FluentStringAssertion<R> asReplaceAll(String regex, String replacement)
      Performs the specified regular expression replacement on the underlying string.
      Parameters:
      regex - The regular expression to which this string is to be matched.
      replacement - The string to be substituted for each match.
      Returns:
      This object.
    • asReplace

      public FluentStringAssertion<R> asReplace(String target, String replacement)
      Performs the specified substring replacement on the underlying string.
      Parameters:
      target - The sequence of char values to be replaced.
      replacement - The replacement sequence of char values.
      Returns:
      This object.
    • asUrlDecode

      URL-decodes the text in this assertion.
      Returns:
      This object.
    • asLc

      Converts the text to lowercase.
      Returns:
      This object.
    • asUc

      Converts the text to uppercase.
      Returns:
      This object.
    • asLines

      Splits the string into lines.
      Returns:
      This object.
    • asSplit

      Splits the string into lines using the specified regular expression.
      Parameters:
      regex - The delimiting regular expression
      Returns:
      This object.
    • asLength

      Returns the length of this string as an integer assertion.
      Returns:
      This object.
    • asOneLine

      Removes any newlines from the string.
      Returns:
      This object.
    • asTrimmed

      Removes any leading/trailing whitespace from the string.
      Returns:
      This object.
    • is

      public R is(String value) throws AssertionError
      Asserts that the text equals the specified value.

      Similar to is(String) except error message states diff position.

      Example:

      // Validates the response body of an HTTP call is the text "OK". client .get(URL) .run() .assertContent().is("OK");

      Overrides:
      is in class FluentObjectAssertion<String,R>
      Parameters:
      value - The value to check against.
      If multiple values are specified, they are concatenated with newlines.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isNot

      public R isNot(String value) throws AssertionError
      Asserts that the text equals the specified value.
      Overrides:
      isNot in class FluentObjectAssertion<String,R>
      Parameters:
      value - The value to check against.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isLines

      public R isLines(String... lines) throws AssertionError
      Asserts that the lines of text equals the specified value.
      Example:

      // Validates the response body of an HTTP call is the text "OK". client .get(URL) .run() .assertContent().isLines( "Line 1", "Line 2", "Line 3" );

      Parameters:
      lines - The value to check against.
      If multiple values are specified, they are concatenated with newlines.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isSortedLines

      public R isSortedLines(String... lines)
      Asserts that the text equals the specified value after splitting both by newlines and sorting the rows.
      Example:

      // Validates the response body of an HTTP call is the text "OK". client .get(URL) .run() .assertContent().isSortedLines( "Line 1", "Line 2", "Line 3" );

      Parameters:
      lines - The value to check against.
      If multiple values are specified, they are concatenated with newlines.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isIc

      public R isIc(String value) throws AssertionError
      Asserts that the text equals the specified value ignoring case.
      Parameters:
      value - The value to check against.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isNotIc

      public R isNotIc(String value) throws AssertionError
      Asserts that the text does not equal the specified value ignoring case.
      Parameters:
      value - The value to check against.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isContains

      public R isContains(String... values) throws AssertionError
      Asserts that the text contains all of the specified substrings.
      Parameters:
      values - The values to check against.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isNotContains

      public R isNotContains(String... values) throws AssertionError
      Asserts that the text doesn't contain any of the specified substrings.
      Parameters:
      values - The values to check against.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isEmpty

      public R isEmpty() throws AssertionError
      Asserts that the text is empty.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isNotEmpty

      public R isNotEmpty() throws AssertionError
      Asserts that the text is not null or empty.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isMatches

      public R isMatches(String searchPattern) throws AssertionError
      Asserts that the text matches the specified pattern containing "*" meta characters.

      The "*" meta character can be used to represent zero or more characters..

      Parameters:
      searchPattern - The search pattern.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isPattern

      public R isPattern(String regex) throws AssertionError
      Asserts that the text matches the specified regular expression.
      Parameters:
      regex - The pattern to test for.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isPattern

      public R isPattern(String regex, int flags) throws AssertionError
      Asserts that the text matches the specified regular expression.
      Parameters:
      regex - The pattern to test for.
      flags - Pattern match flags. See Pattern.compile(String, int).
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isPattern

      public R isPattern(Pattern pattern) throws AssertionError
      Asserts that the text matches the specified regular expression pattern.
      Parameters:
      pattern - The pattern to test for.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isStartsWith

      public R isStartsWith(String string)
      Asserts that the text starts with the specified string.
      Parameters:
      string - The string to test for.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isEndsWith

      public R isEndsWith(String string)
      Asserts that the text ends with the specified string.
      Parameters:
      string - The string to test for.
      Returns:
      The fluent return object.
      Throws:
      AssertionError - If assertion failed.
    • isString

      public R isString(Object value)
      Asserts that the text equals the specified object after calling FluentObjectAssertion.toString() on the object.
      Parameters:
      value - The value to check against.
      Returns:
      The fluent return object.
    • setMsg

      public FluentStringAssertion<R> setMsg(String msg, Object... args)
      Description copied from class: Assertion
      Allows you to override the assertion failure message.

      String can contain "{msg}" to represent the original message.

      Example:

      import static org.apache.juneau.assertions.Assertions.*; // Throws an assertion with a custom message instead of the default "Value was null." assertString(myString) .setMsg("My string was bad: {msg}") .isNotNull();

      Overrides:
      setMsg in class FluentObjectAssertion<String,R>
      Parameters:
      msg - The assertion failure message.
      args - Optional message arguments.
      Returns:
      This object.
    • setOut

      Description copied from class: Assertion
      If an error occurs, send the error message to the specified stream instead of STDERR.
      Overrides:
      setOut in class FluentObjectAssertion<String,R>
      Parameters:
      value - The output stream. Can be null to suppress output.
      Returns:
      This object.
    • setSilent

      Description copied from class: Assertion
      Suppresses output to STDERR.

      This is the equivalent to calling out(null).

      Overrides:
      setSilent in class FluentObjectAssertion<String,R>
      Returns:
      This object.
    • setStdOut

      Description copied from class: Assertion
      If an error occurs, send the error message to STDOUT instead of STDERR.
      Overrides:
      setStdOut in class FluentObjectAssertion<String,R>
      Returns:
      This object.
    • setThrowable

      Description copied from class: Assertion
      If an error occurs, throw this exception instead of the standard AssertionError.

      The throwable class must have a public constructor that takes in any of the following parameters:

      • Throwable - The caused-by exception (if there is one).
      • String - The assertion failure message.

      If the throwable cannot be instantiated, a RuntimeException is thrown instead.

      Example:

      import static org.apache.juneau.assertions.Assertions.*; // Throws a BadRequest instead of an AssertionError if the string is null. assertString(myString) .setThrowable(BadRequest.class) .isNotNull();

      Overrides:
      setThrowable in class FluentObjectAssertion<String,R>
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.