public class StringAssert extends AbstractAssert<StringAssert,java.lang.String> implements EnumerableAssert<StringAssert,java.lang.String>
Strings.
To create a new instance of this class, invoke .
Assertions.assertThat(String)
actual, myself| Modifier | Constructor and Description |
|---|---|
protected |
StringAssert(java.lang.String actual) |
| Modifier and Type | Method and Description |
|---|---|
StringAssert |
contains(java.lang.String sequence)
Verifies that the actual
String contains the given sequence. |
StringAssert |
containsIgnoringCase(java.lang.String sequence)
Verifies that the actual
String contains the given sequence, ignoring case considerations. |
StringAssert |
containsOnlyOnce(java.lang.String sequence)
Verifies that the actual
String contains only once the given sequence. |
StringAssert |
doesNotContain(java.lang.String sequence)
Verifies that the actual
String does not contain the given sequence. |
StringAssert |
doesNotMatch(java.util.regex.Pattern pattern)
Verifies that the actual
String does not match the given regular expression. |
StringAssert |
doesNotMatch(java.lang.String regex)
Verifies that the actual
String does not match the given regular expression. |
StringAssert |
endsWith(java.lang.String suffix)
Verifies that the actual
String ends with the given suffix. |
StringAssert |
hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as given
Iterable. |
StringAssert |
hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.
|
StringAssert |
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.
|
StringAssert |
isEqualToIgnoringCase(java.lang.String expected)
Verifies that the actual
String is equal to the given one, ignoring case considerations. |
StringAssert |
isNotEmpty()
Verifies that the actual group of values is not empty.
|
void |
isNullOrEmpty()
Verifies that the actual group of values is
null or empty. |
StringAssert |
matches(java.util.regex.Pattern pattern)
Verifies that the actual
String matches the given regular expression. |
StringAssert |
matches(java.lang.String regex)
Verifies that the actual
String matches the given regular expression. |
StringAssert |
startsWith(java.lang.String prefix)
Verifies that the actual
String starts with the given prefix. |
StringAssert |
usingComparator(java.util.Comparator<? super java.lang.String> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
StringAssert |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
StringAssert |
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.
|
StringAssert |
usingElementComparator(java.util.Comparator<? super java.lang.String> customComparator)
Use given custom comparator instead of relying on actual type A
equals method to compare group elements for
incoming assertion checks. |
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, overridingErrorMessagepublic void isNullOrEmpty()
null or empty.isNullOrEmpty in interface EnumerableAssert<StringAssert,java.lang.String>public void isEmpty()
isEmpty in interface EnumerableAssert<StringAssert,java.lang.String>public StringAssert isNotEmpty()
isNotEmpty in interface EnumerableAssert<StringAssert,java.lang.String>this assertion object.public StringAssert hasSize(int expected)
hasSize in interface EnumerableAssert<StringAssert,java.lang.String>expected - the expected number of values in the actual group.this assertion object.public StringAssert hasSameSizeAs(java.lang.Object[] other)
hasSameSizeAs in interface EnumerableAssert<StringAssert,java.lang.String>other - the array to compare size with actual group.this assertion object.public StringAssert hasSameSizeAs(java.lang.Iterable<?> other)
Iterable.hasSameSizeAs in interface EnumerableAssert<StringAssert,java.lang.String>other - the Iterable to compare size with actual group.this assertion object.public StringAssert isEqualToIgnoringCase(java.lang.String expected)
String is equal to the given one, ignoring case considerations.expected - the given String to compare the actual String to.this assertion object.java.lang.AssertionError - if the actual String is not equal to the given one.public StringAssert containsOnlyOnce(java.lang.String sequence)
String contains only once the given sequence.sequence - the sequence to search for.this assertion object.java.lang.AssertionError - if the actual String does not contain the given one, or contain it multiple times.public StringAssert contains(java.lang.String sequence)
String contains the given sequence.sequence - the sequence to search for.this assertion object.java.lang.NullPointerException - if the given sequence is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not contain the given one.public StringAssert containsIgnoringCase(java.lang.String sequence)
String contains the given sequence, ignoring case considerations.sequence - the sequence to search for.this assertion object.java.lang.NullPointerException - if the given sequence is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not contain the given one.public StringAssert doesNotContain(java.lang.String sequence)
String does not contain the given sequence.sequence - the sequence to search for.this assertion object.java.lang.NullPointerException - if the given sequence is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String contains the given one.public StringAssert startsWith(java.lang.String prefix)
String starts with the given prefix.prefix - the given prefix.this assertion object.java.lang.NullPointerException - if the given prefix is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not start with the given prefix.public StringAssert endsWith(java.lang.String suffix)
String ends with the given suffix.suffix - the given suffix.this assertion object.java.lang.NullPointerException - if the given suffix is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not end with the given suffix.public StringAssert matches(java.lang.String regex)
String matches the given regular expression.regex - the regular expression to which the actual String is to be matched.this assertion object.java.lang.NullPointerException - if the given pattern is null.java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not match the given regular expression.public StringAssert doesNotMatch(java.lang.String regex)
String does not match the given regular expression.regex - the regular expression to which the actual String is to be matched.this assertion object.java.lang.NullPointerException - if the given pattern is null.java.util.regex.PatternSyntaxException - if the regular expression's syntax is invalid.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String matches the given regular expression.public StringAssert matches(java.util.regex.Pattern pattern)
String matches the given regular expression.pattern - the regular expression to which the actual String is to be matched.this assertion object.java.lang.NullPointerException - if the given pattern is null.java.lang.AssertionError - if the actual String is null.java.lang.AssertionError - if the actual String does not match the given regular expression.public StringAssert doesNotMatch(java.util.regex.Pattern pattern)
String does not match the given regular expression.pattern - the regular expression to which the actual String is to be matched.this assertion object.java.lang.NullPointerException - if the given pattern is null.java.lang.AssertionError - if the actual String does not match the given regular expression.public StringAssert usingElementComparator(java.util.Comparator<? super java.lang.String> customComparator)
equals 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);
usingElementComparator in interface EnumerableAssert<StringAssert,java.lang.String>customComparator - the comparator to use for incoming assertion checks.this assertion object.public StringAssert usingDefaultElementComparator()
This method should be used to disable a custom comparison strategy set by calling EnumerableAssert.usingElementComparator(Comparator).
usingDefaultElementComparator in interface EnumerableAssert<StringAssert,java.lang.String>this assertion object.public StringAssert usingComparator(java.util.Comparator<? super java.lang.String> customComparator)
AbstractAssertCustom 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);
usingComparator in interface Assert<StringAssert,java.lang.String>usingComparator in class AbstractAssert<StringAssert,java.lang.String>customComparator - the comparator to use for incoming assertion checks.this assertion object.public StringAssert usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator).
usingDefaultComparator in interface Assert<StringAssert,java.lang.String>usingDefaultComparator in class AbstractAssert<StringAssert,java.lang.String>this assertion object.Copyright © 2007–2018. All rights reserved.