Class FluentStringAssertion<R>
- Type Parameters:
R
- The return type.
- Direct Known Subclasses:
FluentRequestFormParamAssertion
,FluentRequestHeaderAssertion
,FluentRequestQueryParamAssertion
,FluentResponseHeaderAssertion
,StringAssertion
Example:
Test Methods:
FluentStringAssertion
is(String)
isNot(String)
isLines(String...)
isSortedLines(String...)
isIc(String)
isNotIc(String)
isContains(String...)
isNotContains(String...)
isEmpty()
isNotEmpty()
isString(Object)
isMatches(String)
isPattern(String)
isPattern(String,int)
isPattern(Pattern)
isStartsWith(String)
isEndsWith(String)
FluentObjectAssertion
Transform Methods:
Configuration Methods:
See Also:
-
Constructor Summary
ConstructorDescriptionFluentStringAssertion
(String value, R returns) Constructor.FluentStringAssertion
(Assertion creator, String value, R returns) Chained constructor. -
Method Summary
Modifier and TypeMethodDescriptionWhen enabled, text in the message is converted to valid Java strings.asLc()
Converts the text to lowercase.asLength()
Returns the length of this string as an integer assertion.asLines()
Splits the string into lines.Removes any newlines from the string.Performs the specified substring replacement on the underlying string.asReplaceAll
(String regex, String replacement) Performs the specified regular expression replacement on the underlying string.Splits the string into lines using the specified regular expression.asTransformed
(Function<String, String> function) Applies a transform on the inner object and returns a new inner object.Removes any leading/trailing whitespace from the string.asUc()
Converts the text to uppercase.URL-decodes the text in this assertion.Asserts that the text equals the specified value.isContains
(String... values) Asserts that the text contains all of the specified substrings.isEmpty()
Asserts that the text is empty.isEndsWith
(String string) Asserts that the text ends with the specified string.Asserts that the text equals the specified value ignoring case.Asserts that the lines of text equals the specified value.Asserts that the text matches the specified pattern containing"*" meta characters.Asserts that the text equals the specified value.isNotContains
(String... values) Asserts that the text doesn't contain any of the specified substrings.Asserts that the text is not null or empty.Asserts that the text does not equal the specified value ignoring case.Asserts that the text matches the specified regular expression.Asserts that the text matches the specified regular expression.Asserts that the text matches the specified regular expression pattern.isSortedLines
(String... lines) Asserts that the text equals the specified value after splitting both by newlines and sorting the rows.isStartsWith
(String string) Asserts that the text starts with the specified string.Asserts that the text equals the specified object after callingFluentObjectAssertion.toString()
on the object.Allows you to override the assertion failure message.setOut
(PrintStream value) If an error occurs, send the error message to the specified stream instead of STDERR.Suppresses output to STDERR.If an error occurs, send the error message to STDOUT instead of STDERR.setThrowable
(Class<? extends RuntimeException> value) If an error occurs, throw this exception instead of the standardAssertionError
.Methods inherited from class org.apache.juneau.assertions.FluentObjectAssertion
asAny, asJson, asJsonSorted, asString, asString, asString, asTransformedTo, equals, getFailureMessage, is, isAny, isExactType, isExists, isJson, isNotAny, isNotNull, isNull, isSame, isSameJsonAs, isSameSerializedAs, isSameSortedJsonAs, isString, isType, map, opt, orElse, toString, value, valueAsString, valueIsNotNull, valueIsNull
Methods inherited from class org.apache.juneau.assertions.FluentAssertion
returns
Methods inherited from class org.apache.juneau.assertions.Assertion
arrayClass, className, error, error
-
Constructor Details
-
FluentStringAssertion
Constructor.- Parameters:
value
- The object being tested.
Can benull .returns
- The object to return after a test method is called.
Ifnull , the test method returns this object allowing multiple test method calls to be used on the same assertion.
-
FluentStringAssertion
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 benull if this is the top-level assertion.value
- The object being tested.
Can benull .returns
- The object to return after a test method is called.
Ifnull , 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 classFluentObjectAssertion<String,
R> - Parameters:
function
- The function to apply.- Returns:
- This object.
-
asReplaceAll
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
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
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 classFluentObjectAssertion<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
Asserts that the text equals the specified value.- Overrides:
isNot
in classFluentObjectAssertion<String,
R> - Parameters:
value
- The value to check against.- Returns:
- The fluent return object.
- Throws:
AssertionError
- If assertion failed.
-
isLines
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
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
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
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
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
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
Asserts that the text is empty.- Returns:
- The fluent return object.
- Throws:
AssertionError
- If assertion failed.
-
isNotEmpty
Asserts that the text is not null or empty.- Returns:
- The fluent return object.
- Throws:
AssertionError
- If assertion failed.
-
isMatches
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
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
Asserts that the text matches the specified regular expression.- Parameters:
regex
- The pattern to test for.flags
- Pattern match flags. SeePattern.compile(String, int)
.- Returns:
- The fluent return object.
- Throws:
AssertionError
- If assertion failed.
-
isPattern
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
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
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
Asserts that the text equals the specified object after callingFluentObjectAssertion.toString()
on the object.- Parameters:
value
- The value to check against.- Returns:
- The fluent return object.
-
setMsg
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 classFluentObjectAssertion<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 classFluentObjectAssertion<String,
R> - Parameters:
value
- The output stream. Can benull 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 classFluentObjectAssertion<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 classFluentObjectAssertion<String,
R> - Returns:
- This object.
-
setThrowable
Description copied from class:Assertion
If an error occurs, throw this exception instead of the standardAssertionError
.The throwable class must have a public constructor that takes in any of the following parameters:
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 classFluentObjectAssertion<String,
R> - Parameters:
value
- The new value for this setting.- Returns:
- This object.
-