org.fest.assertions
Class StringAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<S,A>
          extended by org.fest.assertions.GroupAssert<StringAssert,String>
              extended by org.fest.assertions.StringAssert

public class StringAssert
extends GroupAssert<StringAssert,String>

Assertions for Strings.

To create a new instance of this class invoke Assertions.assertThat(String).

Author:
Yvonne Wang, David DIDIER

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual, myself
 
Constructor Summary
protected StringAssert(String actual)
          Creates a new StringAssert.
 
Method Summary
protected  int actualGroupSize()
          Returns the number of elements in the actual String.
 StringAssert contains(String expected)
          Verifies that the actual String contains the given one.
 StringAssert containsIgnoringCase(String text)
          Verifies that the actual String contains the given text regardless of the case.
 StringAssert doesNotContain(String text)
          Verifies that the actual String does not contain the given text.
 StringAssert doesNotMatch(String regex)
          Verifies that the actual String does not match the given one.
 StringAssert endsWith(String expected)
          Verifies that the actual String ends with the given one.
 StringAssert excludes(String s)
          Verifies that the actual String does not contains the given one.
 StringAssert isEqualToIgnoringCase(String expected)
          Verifies that the actual String is equal to the given one ignoring case.
 StringAssert matches(String regex)
          Verifies that the actual String matches the given one.
 StringAssert startsWith(String expected)
          Verifies that the actual String starts with the given one.
 
Methods inherited from class org.fest.assertions.GroupAssert
hasSize, isEmpty, isNotEmpty, isNullOrEmpty
 
Methods inherited from class org.fest.assertions.GenericAssert
as, as, describedAs, describedAs, doesNotSatisfy, is, isEqualTo, isIn, isIn, isNot, isNotEqualTo, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs, overridingErrorMessage, satisfies
 
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringAssert

protected StringAssert(String actual)
Creates a new StringAssert.

Parameters:
actual - the target to verify.
Method Detail

isEqualToIgnoringCase

public StringAssert isEqualToIgnoringCase(String expected)
Verifies that the actual String is equal to the given one ignoring case.

Parameters:
expected - the given String to compare the actual String to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String is not equal to the given one ignoring case.

actualGroupSize

protected int actualGroupSize()
Returns the number of elements in the actual String.

Specified by:
actualGroupSize in class GroupAssert<StringAssert,String>
Returns:
the number of elements in the actual String.

contains

public StringAssert contains(String expected)
Verifies that the actual String contains the given one.

Parameters:
expected - the given String expected to be contained in the actual one.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String does not contain the given one.

endsWith

public StringAssert endsWith(String expected)
Verifies that the actual String ends with the given one.

Parameters:
expected - the given String expected to be at the end of the actual one.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String does not end with the given one.

startsWith

public StringAssert startsWith(String expected)
Verifies that the actual String starts with the given one.

Parameters:
expected - the given String expected to be at the beginning of the actual one.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String does not start with the given one.

excludes

public StringAssert excludes(String s)
Verifies that the actual String does not contains the given one.

Parameters:
s - the given String expected not to be contained in the actual one.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String does contain the given one.

matches

public StringAssert matches(String regex)
Verifies that the actual String matches 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 actual String is null.
AssertionError - if the actual String does not match the given regular expression.

doesNotMatch

public StringAssert doesNotMatch(String regex)
Verifies that the actual String does 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 actual String is null.
AssertionError - if the actual String matches the given regular expression.

containsIgnoringCase

public StringAssert containsIgnoringCase(String text)
Verifies that the actual String contains the given text regardless of the case.

Parameters:
text - the given text.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String does not contain the given text.
NullPointerException - if the given String is null.
Since:
1.3

doesNotContain

public StringAssert doesNotContain(String text)
Verifies that the actual String does not contain the given text.

Parameters:
text - the given text.
Returns:
this assertion object.
Throws:
AssertionError - if the actual String is null.
AssertionError - if the actual String contains the given text.
NullPointerException - if the given String is null.
Since:
1.3


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.