Package org.fest.assertions.api
Class StringAssert
- All Implemented Interfaces:
Assert<StringAssert,
,String> Descriptable<StringAssert>
,EnumerableAssert<StringAssert,
,String> ExtensionPoints<StringAssert,
String>
public class StringAssert
extends AbstractAssert<StringAssert,String>
implements EnumerableAssert<StringAssert,String>
Assertion methods for
String
s.
To create a new instance of this class, invoke
.
Assertions.assertThat(String)
- Author:
- Yvonne Wang, David DIDIER, Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas Francois
-
Field Summary
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionVerifies that the actualString
contains the given sequence.containsIgnoringCase
(String sequence) Verifies that the actualString
contains the given sequence, ignoring case considerations.containsOnlyOnce
(String sequence) Verifies that the actualString
contains only once the given sequence.doesNotContain
(String sequence) Verifies that the actualString
does not contain the given sequence.doesNotMatch
(String regex) Verifies that the actualString
does not match the given regular expression.doesNotMatch
(Pattern pattern) Verifies that the actualString
does not match the given regular expression.Verifies that the actualString
ends with the given suffix.hasSameSizeAs
(Iterable<?> other) Verifies that the actual group has the same size as givenIterable
.hasSameSizeAs
(Object[] other) Verifies that the actual group has the same size as given array.hasSize
(int expected) Verifies that the number of values in the actual group is equal to the given one.void
isEmpty()
Verifies that the actual group of values is empty.isEqualToIgnoringCase
(String expected) Verifies that the actualString
is equal to the given one, ignoring case considerations.Verifies that the actual group of values is not empty.void
Verifies that the actual group of values isnull
or empty.Verifies that the actualString
matches the given regular expression.Verifies that the actualString
matches the given regular expression.startsWith
(String prefix) Verifies that the actualString
starts with the given prefix.usingComparator
(Comparator<? super String> customComparator) Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Revert to standard comparison for incoming assertion checks.Revert to standard comparison for incoming assertion group element checks.usingElementComparator
(Comparator<? super String> customComparator) Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage
-
Constructor Details
-
StringAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actual group of values isnull
or empty.- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<StringAssert,
String>
-
isEmpty
public void isEmpty()Verifies that the actual group of values is empty.- Specified by:
isEmpty
in interfaceEnumerableAssert<StringAssert,
String>
-
isNotEmpty
Verifies that the actual group of values is not empty.- Specified by:
isNotEmpty
in interfaceEnumerableAssert<StringAssert,
String> - Returns:
this
assertion object.
-
hasSize
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSize
in interfaceEnumerableAssert<StringAssert,
String> - Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<StringAssert,
String> - Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as givenIterable
.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<StringAssert,
String> - Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
isEqualToIgnoringCase
Verifies that the actualString
is equal to the given one, ignoring case considerations.- Parameters:
expected
- the givenString
to compare the actualString
to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actualString
is not equal to the given one.
-
containsOnlyOnce
Verifies that the actualString
contains only once the given sequence.- Parameters:
sequence
- the sequence to search for.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actualString
does not contain the given one, or contain it multiple times.
-
contains
Verifies that the actualString
contains the given sequence.- Parameters:
sequence
- the sequence to search for.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given sequence isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not contain the given one.
-
containsIgnoringCase
Verifies that the actualString
contains the given sequence, ignoring case considerations.- Parameters:
sequence
- the sequence to search for.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given sequence isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not contain the given one.
-
doesNotContain
Verifies that the actualString
does not contain the given sequence.- Parameters:
sequence
- the sequence to search for.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given sequence isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
contains the given one.
-
startsWith
Verifies that the actualString
starts with the given prefix.- Parameters:
prefix
- the given prefix.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given prefix isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not start with the given prefix.
-
endsWith
Verifies that the actualString
ends with the given suffix.- Parameters:
suffix
- the given suffix.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given suffix isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not end with the given suffix.
-
matches
Verifies that the actualString
matches the given regular expression.- Parameters:
regex
- the regular expression to which the actualString
is to be matched.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given pattern isnull
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not match the given regular expression.
-
doesNotMatch
Verifies that the actualString
does not match the given regular expression.- Parameters:
regex
- the regular expression to which the actualString
is to be matched.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given pattern isnull
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
matches the given regular expression.
-
matches
Verifies that the actualString
matches the given regular expression.- Parameters:
pattern
- the regular expression to which the actualString
is to be matched.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given pattern isnull
.AssertionError
- if the actualString
isnull
.AssertionError
- if the actualString
does not match the given regular expression.
-
doesNotMatch
Verifies that the actualString
does not match the given regular expression.- Parameters:
pattern
- the regular expression to which the actualString
is to be matched.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given pattern isnull
.AssertionError
- if the actualString
does not match the given regular expression.
-
usingElementComparator
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// compares invoices by payee assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList). // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice) // as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceList elements to lowestInvoice. assertThat(invoiceList).contains(lowestInvoice). // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ... assertThat(fellowshipOfTheRing).contains(gandalf) .doesNotContain(sauron); // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator) .contains(sauron);
- Specified by:
usingElementComparator
in interfaceEnumerableAssert<StringAssert,
String> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
Revert to standard comparison for incoming assertion group element checks.This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.- Specified by:
usingDefaultElementComparator
in interfaceEnumerableAssert<StringAssert,
String> - Returns:
this
assertion object.
-
usingComparator
Description copied from class:AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<StringAssert,
String> - Overrides:
usingComparator
in classAbstractAssert<StringAssert,
String> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultComparator
Description copied from class:AbstractAssert
Revert to standard comparison for incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.- Specified by:
usingDefaultComparator
in interfaceAssert<StringAssert,
String> - Overrides:
usingDefaultComparator
in classAbstractAssert<StringAssert,
String> - Returns:
this
assertion object.
-