Package org.fest.assertions
Class StringAssert
Understands assertion methods for
Strings. To create a new instance of this class use the
method Assertions.assertThat(String).-
Field Summary
Fields inherited from class org.fest.assertions.GenericAssert
actual -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Stringactual()protected intReturns the number of elements in the actualString.Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErroras(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrorVerifies that the actualStringcontains the given one.containsIgnoringCase(String text) Verifies that the actualStringcontains the given text regardless of the case.describedAs(String description) Alias for, since "as" is a keyword in Groovy.GenericAssert.as(String)describedAs(Description description) Alias for, since "as" is a keyword in Groovy.GenericAssert.as(Description)doesNotContain(String text) Verifies that the actualStringdoes not contain the given text.doesNotMatch(String regex) Verifies that the actualStringdoes not match the given one.doesNotSatisfy(Condition<String> condition) Verifies that the actualStringdoes not satisfy the given condition.Verifies that the actualStringends with the given one.Verifies that the actualStringdoes not contains the given one.hasSize(int expected) Verifies that the number of characters in the actualStringis equal to the given one.Alias for.satisfies(Condition)Verifies that the actualStringis equal to the given one.isEqualToIgnoringCase(String expected) Verifies that the actualStringis equal to the given one ignoring case.Alias for.doesNotSatisfy(Condition)Verifies that the actualStringcontains at least on character.isNotEqualTo(String other) Verifies that the actualStringis not equal to the given one.Verifies that the actualStringis notnull.isNotSameAs(String other) Verifies that the actualStringis not the same as the given one.Verifies that the actualStringis the same as the given one.Verifies that the actualStringmatches the given one.overridingErrorMessage(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualStringsatisfies the given condition.startsWith(String expected) Verifies that the actualStringstarts with the given one.private static voidvalidateNotNull(String text) Methods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, isEmpty, isNullOrEmptyMethods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNullMethods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Constructor Details
-
StringAssert
Creates a newStringAssert.- Parameters:
actual- the target to verify.
-
-
Method Details
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- Specified by:
asin classGroupAssert<String>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(String)For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");- Specified by:
describedAsin classGroupAssert<String>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
asin classGroupAssert<String>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(Description)For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
describedAsin classGroupAssert<String>- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
satisfies
Verifies that the actualStringsatisfies the given condition.- Specified by:
satisfiesin classGenericAssert<String>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualStringdoes not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualStringdoes not satisfy the given condition.- Specified by:
doesNotSatisfyin classGenericAssert<String>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualStringsatisfies the given condition.- See Also:
-
is
Alias for.satisfies(Condition)- Specified by:
isin classGenericAssert<String>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualStringdoes not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for.doesNotSatisfy(Condition)- Specified by:
isNotin classGenericAssert<String>- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualStringsatisfies the given condition.- Since:
- 1.2
-
isNotEmpty
Verifies that the actualStringcontains at least on character.- Specified by:
isNotEmptyin classGroupAssert<String>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnullor empty.
-
isEqualTo
Verifies that the actualStringis equal to the given one.- Specified by:
isEqualToin classGenericAssert<String>- Parameters:
expected- the givenStringto compare the actualStringto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringis not equal to the given one.
-
isEqualToIgnoringCase
Verifies that the actualStringis equal to the given one ignoring case.- Parameters:
expected- the givenStringto compare the actualStringto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringis not equal to the given one ignoring case.
-
isNotEqualTo
Verifies that the actualStringis not equal to the given one.- Specified by:
isNotEqualToin classGenericAssert<String>- Parameters:
other- the givenStringto compare the actualStringto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringis equal to the given one.
-
isNotNull
Verifies that the actualStringis notnull.- Specified by:
isNotNullin classGenericAssert<String>- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.
-
isNotSameAs
Verifies that the actualStringis not the same as the given one.- Specified by:
isNotSameAsin classGenericAssert<String>- Parameters:
other- the givenStringto compare the actualStringto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringis the same as the given one.
-
isSameAs
Verifies that the actualStringis the same as the given one.- Specified by:
isSameAsin classGenericAssert<String>- Parameters:
expected- the givenStringto compare the actualStringto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringis not the same as the given one.
-
hasSize
Verifies that the number of characters in the actualStringis equal to the given one.- Specified by:
hasSizein classGroupAssert<String>- Parameters:
expected- the expected number of characters in the actualString.- Returns:
- this assertion object.
- Throws:
AssertionError- if the number of characters of the actualStringis not equal to the given one.
-
actualGroupSize
protected int actualGroupSize()Returns the number of elements in the actualString.- Specified by:
actualGroupSizein classGroupAssert<String>- Returns:
- the number of elements in the actual
String.
-
contains
Verifies that the actualStringcontains the given one.- Parameters:
expected- the givenStringexpected to be contained in the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes not contain the given one.
-
endsWith
Verifies that the actualStringends with the given one.- Parameters:
expected- the givenStringexpected to be at the end of the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes not end with the given one.
-
startsWith
Verifies that the actualStringstarts with the given one.- Parameters:
expected- the givenStringexpected to be at the beginning of the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes not start with the given one.
-
excludes
Verifies that the actualStringdoes not contains the given one.- Parameters:
s- the givenStringexpected not to be contained in the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes contain the given one.
-
matches
Verifies that the actualStringmatches the given one.- Parameters:
regex- the given regular expression expected to be matched by the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes not match the given regular expression.
-
doesNotMatch
Verifies that the actualStringdoes not match the given one.- Parameters:
regex- the given regular expression expected not to be matched by the actual one.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringmatches the given regular expression.
-
actual
-
overridingErrorMessage
Replaces the default message displayed in case of a failure with the given one.For example, the following assertion:
assertThat("Hello").isEqualTo("Bye");will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."We can replace this message with our own:
assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".- Specified by:
overridingErrorMessagein classGroupAssert<String>- Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-
containsIgnoringCase
Verifies that the actualStringcontains the given text regardless of the case.- Parameters:
text- the given text.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringdoes not contain the given text.NullPointerException- if the givenStringisnull.- Since:
- 1.3
-
doesNotContain
Verifies that the actualStringdoes not contain the given text.- Parameters:
text- the given text.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualStringisnull.AssertionError- if the actualStringcontains the given text.NullPointerException- if the givenStringisnull.- Since:
- 1.3
-
validateNotNull
-