Class CharArrayAssert


public class CharArrayAssert extends ArrayAssert<char[]>
Understands assertion methods for char arrays. To create a new instance of this class use the method Assertions.assertThat(char[]).
  • Constructor Details

    • CharArrayAssert

      protected CharArrayAssert(char... actual)
      Creates a new CharArrayAssert.
      Parameters:
      actual - the target to verify.
  • Method Details

    • as

      public CharArrayAssert as(String description)
      Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

      For example:

       assertThat(values).as("Some values").isNotEmpty();
       

      Specified by:
      as in class GroupAssert<char[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • describedAs

      public CharArrayAssert describedAs(String description)
      Alias for as(String), 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.

      For example:

       assertThat(values).describedAs("Some values").isNotEmpty();
       

      Specified by:
      describedAs in class GroupAssert<char[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • as

      public CharArrayAssert as(Description description)
      Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

      For example:

       assertThat(values).as(new BasicDescription("Some values")).isNotEmpty();
       

      Specified by:
      as in class GroupAssert<char[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • describedAs

      public CharArrayAssert describedAs(Description description)
      Alias for as(Description), 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.

      For example:

       assertThat(values).describedAs(new BasicDescription("Some values")).isNotEmpty();
       

      Specified by:
      describedAs in class GroupAssert<char[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • contains

      public CharArrayAssert contains(char... values)
      Verifies that the actual char array contains the given values.
      Parameters:
      values - the values to look for.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
      NullPointerException - if the given char array is null.
      AssertionError - if the actual char array does not contain the given values.
    • containsOnly

      public CharArrayAssert containsOnly(char... values)
      Verifies that the actual char array contains the given values only.
      Parameters:
      values - the values to look for.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
      NullPointerException - if the given char array is null.
      AssertionError - if the actual char array does not contain the given objects, or if the actual char array contains elements other than the ones specified.
    • excludes

      public CharArrayAssert excludes(char... values)
      Verifies that the actual char array does not contain the given values.
      Parameters:
      values - the values the array should exclude.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
      NullPointerException - if the given char array is null.
      AssertionError - if the actual char array contains any of the given values.
    • satisfies

      public CharArrayAssert satisfies(Condition<char[]> condition)
      Verifies that the actual char array satisfies the given condition.
      Specified by:
      satisfies in class GenericAssert<char[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual char array does not satisfy the given condition.
      See Also:
    • doesNotSatisfy

      public CharArrayAssert doesNotSatisfy(Condition<char[]> condition)
      Verifies that the actual char array does not satisfy the given condition.
      Specified by:
      doesNotSatisfy in class GenericAssert<char[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual char array satisfies the given condition.
      See Also:
    • is

      public CharArrayAssert is(Condition<char[]> condition)
      Specified by:
      is in class GenericAssert<char[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual char array does not satisfy the given condition.
      Since:
      1.2
    • isNot

      public CharArrayAssert isNot(Condition<char[]> condition)
      Specified by:
      isNot in class GenericAssert<char[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual char array satisfies the given condition.
      Since:
      1.2
    • isNotNull

      public CharArrayAssert isNotNull()
      Verifies that the actual char array is not null.
      Specified by:
      isNotNull in class GenericAssert<char[]>
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
    • isNotEmpty

      public CharArrayAssert isNotEmpty()
      Verifies that the actual char array contains at least on element.
      Specified by:
      isNotEmpty in class GroupAssert<char[]>
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
      AssertionError - if the actual char array is empty.
    • isEqualTo

      public CharArrayAssert isEqualTo(char[] expected)
      Verifies that the actual char array is equal to the given array. Array equality is checked by Arrays.equals(char[], char[]).
      Specified by:
      isEqualTo in class GenericAssert<char[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is not equal to the given one.
    • isNotEqualTo

      public CharArrayAssert isNotEqualTo(char[] array)
      Verifies that the actual char array is not equal to the given array. Array equality is checked by Arrays.equals(char[], char[]).
      Specified by:
      isNotEqualTo in class GenericAssert<char[]>
      Parameters:
      array - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is equal to the given one.
    • hasSize

      public CharArrayAssert hasSize(int expected)
      Verifies that the number of elements in the actual char array is equal to the given one.
      Specified by:
      hasSize in class GroupAssert<char[]>
      Parameters:
      expected - the expected number of elements in the actual char array.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is null.
      AssertionError - if the number of elements in the actual char array is not equal to the given one.
    • isSameAs

      public CharArrayAssert isSameAs(char[] expected)
      Verifies that the actual char array is the same as the given array.
      Specified by:
      isSameAs in class GenericAssert<char[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is not the same as the given one.
    • isNotSameAs

      public CharArrayAssert isNotSameAs(char[] expected)
      Verifies that the actual char array is not the same as the given array.
      Specified by:
      isNotSameAs in class GenericAssert<char[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual char array is the same as the given one.
    • overridingErrorMessage

      public CharArrayAssert overridingErrorMessage(String message)
      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:
      overridingErrorMessage in class GroupAssert<char[]>
      Parameters:
      message - the given error message, which will replace the default one.
      Returns:
      this assertion.