Top Description Fields Constructors Methods
org.assertj.core.api

public Class Char2DArrayAssert

extends Abstract2DArrayAssert<Char2DArrayAssert, char[][], Character>
Class Inheritance
Static Imports
org.assertj.core.error.ShouldHaveSameSizeAs.shouldHaveSameSizeAs, .ShouldNotBeNull.shouldNotBeNull, .SubarraysShouldHaveSameSize.subarraysShouldHaveSameSize, org.assertj.core.error.array2d.Array2dElementShouldBeDeepEqual.elementShouldBeEqual

Assertion methods for two-dimensional arrays of chars.

To create an instance of this class, invoke Assertions#assertThat(char[][]).

Author
Maciej Wajcht
Since
3.17.0

Field Summary

Modifier and TypeField and Description
protected Char2DArrays
private final Failures

Constructor Summary

AccessConstructor and Description
public
Char2DArrayAssert(char[][] actual)

Method Summary

Modifier and TypeMethod and Description
public Char2DArrayAssert

Returns:

myself assertion object.
contains
(char[]
the value to look for.
value
,
Index
the index where the value should be stored in the actual char[][].
index
)

Verifies that the actual char[][] contains the given char[] at the given index.

public Char2DArrayAssert

Returns:

myself assertion object.
doesNotContain
(char[]
the value to look for.
value
,
Index
the index where the value should be stored in the actual char[][].
index
)

Verifies that the actual char[][] does not contain the given char[] at the given index.

public Char2DArrayAssert

Returns:

this assertion object.
hasDimensions
(int
the expected number of values in first dimension of the actual char[][].
expectedFirstDimension
,
int
the expected number of values in second dimension of the actual char[][].
expectedSecondDimension
)

Implements org.assertj.core.api.Array2DAssert.hasDimensions.

Verifies that the actual char[][] has the given dimensions.
public Char2DArrayAssert

Returns:

this assertion object.
hasNumberOfRows
(int
the expected number of rows of the two-dimensional array.
expected
)

Implements org.assertj.core.api.Array2DAssert.hasNumberOfRows.

Verifies that the actual two-dimensional array has the given number of rows.
public Char2DArrayAssert

Returns:

this assertion object.
hasSameDimensionsAs
(Object
the array to compare dimensions with actual char[][].
array
)

Implements org.assertj.core.api.Array2DAssert.hasSameDimensionsAs.

Verifies that the actual char[][] has the same dimensions as the given array.
public Char2DArrayAssert

Returns:

this assertion object.
inUnicode
()

Use unicode character representation instead of standard representation in error messages.

public Char2DArrayAssert

Returns:

this assertion object.
isDeepEqualTo
(char[][]
the given value to compare the actual value to.
expected
)

Implements abstract org.assertj.core.api.Abstract2DArrayAssert.isDeepEqualTo.

Verifies that the actual char[][] is deeply equal to the given one.
public void
isEmpty()

Implements org.assertj.core.api.Array2DAssert.isEmpty.

Verifies that the actual char[][] is empty, empty means the array has no elements, said otherwise it can have any number of rows but all rows must be empty.
public Char2DArrayAssert

Returns:

this assertion object.
isEqualTo
(Object
the given value to compare the actual char[][] to.
expected
)

Overrides org.assertj.core.api.AbstractAssert.isEqualTo.

Implements org.assertj.core.api.Assert.isEqualTo.

Verifies that the actual char[][] is equal to the given one.
public Char2DArrayAssert

Returns:

this assertion object.
isNotEmpty
()

Implements org.assertj.core.api.Array2DAssert.isNotEmpty.

Verifies that the actual char[][] is not empty, not empty means the array has at least one char element.
public void
isNullOrEmpty()

Implements org.assertj.core.api.Array2DAssert.isNullOrEmpty.

Verifies that the actual char[][] is null or empty, empty means the array has no elements, said otherwise it can have any number of rows but all rows must be empty.

Field Detail

char2dArraysback to summary
protected Char2DArrays char2dArrays
Annotations
@VisibleForTesting
failuresback to summary
private final Failures failures

Constructor Detail

Char2DArrayAssertback to summary
public Char2DArrayAssert(char[][] actual)

Method Detail

containsback to summary
public Char2DArrayAssert contains(char[] value, Index index)

Verifies that the actual char[][] contains the given char[] at the given index.

Example:

 // assertion will pass
assertThat(new char[][] {{'a', 'b'}, {'c', 'd'} }).contains(new char[] {'a', 'b'}, atIndex(0));

// assertion will fail
assertThat(new char[][] {{'a', 'b'}, {'c', 'd'} }).contains(new char[] {'a', 'b'}, atIndex(1));
Parameters
value:char[]

the value to look for.

index:Index

the index where the value should be stored in the actual char[][].

Returns:Char2DArrayAssert

myself assertion object.

Exceptions
AssertionError:
  • if the actual char[][] is null or empty.
  • if the actual char[][] does not contain the given value at the given index.
NullPointerException:
if the given Index is null.
IndexOutOfBoundsException:
if the value of the given Index is equal to or greater than the size of the actual char[][].
doesNotContainback to summary
public Char2DArrayAssert doesNotContain(char[] value, Index index)

Verifies that the actual char[][] does not contain the given char[] at the given index.

Example:

 // assertion will pass
assertThat(new char[][] {{'a', 'b'}, {'c', 'd'} }).doesNotContain(new char[] {'a', 'b'}, atIndex(1));

// assertion will fail
assertThat(new char[][] {{'a', 'b'}, {'c', 'd'} }).doesNotContain(new char[] {'a', 'b'}, atIndex(0));
Parameters
value:char[]

the value to look for.

index:Index

the index where the value should be stored in the actual char[][].

Returns:Char2DArrayAssert

myself assertion object.

Exceptions
AssertionError:
  • if the actual char[][] is null.
  • if the actual char[][] contains the given value at the given index.
NullPointerException:
if the given Index is null.
hasDimensionsback to summary
public Char2DArrayAssert hasDimensions(int expectedFirstDimension, int expectedSecondDimension)

Implements org.assertj.core.api.Array2DAssert.hasDimensions.

Verifies that the actual char[][] has the given dimensions.

Example:

 // assertion will pass
assertThat(new char[][] { {'1', '2', '3'}, {'4', '5', '6'} }).hasDimensions(2, 3);

// assertions will fail
assertThat(new char[][] { }).hasDimensions(1, 1);
assertThat(new char[][] { {'1', '2', '3'}, {'4', '5', '6'} }).hasDimensions(3, 2);
assertThat(new char[][] { {'1', '2', '3'}, {'4', '5', '6', '7'} }).hasDimensions(2, 3); 
Parameters
expectedFirstDimension:int

the expected number of values in first dimension of the actual char[][].

expectedSecondDimension:int

the expected number of values in second dimension of the actual char[][].

Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
if the number of values of the actual char[][] is not equal to the given one.
hasNumberOfRowsback to summary
public Char2DArrayAssert hasNumberOfRows(int expected)

Implements org.assertj.core.api.Array2DAssert.hasNumberOfRows.

Verifies that the actual two-dimensional array has the given number of rows.

Example:

 // assertion will pass
assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6'}}).hasNumberOfRows(2);
assertThat(new char[][] {{'1'}, {'1', '2'}, {'1', '2', '3'}}).hasNumberOfRows(3);

// assertions will fail
assertThat(new char[][] { }).hasNumberOfRows(1);
assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6'}}).hasNumberOfRows(3);
assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6', '7'}}).hasNumberOfRows(1); 
Parameters
expected:int

the expected number of rows of the two-dimensional array.

Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
if the actual number of rows are not equal to the given one.
hasSameDimensionsAsback to summary
public Char2DArrayAssert hasSameDimensionsAs(Object array)

Implements org.assertj.core.api.Array2DAssert.hasSameDimensionsAs.

Verifies that the actual char[][] has the same dimensions as the given array.

Parameter is declared as Object to accept both Object[] and primitive arrays (e.g. int[]).

Example:
 char[][] charArray = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
int[][] intArray = {{1, 2, 3}, {4, 5, 6}};

// assertion will pass
assertThat(charArray).hasSameDimensionsAs(intArray);

// assertions will fail
assertThat(charArray).hasSameDimensionsAs(new int[][] {{1, 2}, {3, 4}, {5, 6}});
assertThat(charArray).hasSameDimensionsAs(new int[][] {{1, 2}, {3, 4, 5}});
assertThat(charArray).hasSameDimensionsAs(new int[][] {{1, 2, 3}, {4, 5}});
Parameters
array:Object

the array to compare dimensions with actual char[][].

Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
  • if the actual char[][] is null.
  • if the array parameter is null or is not a true array.
  • if actual char[][] and given array don't have the same dimensions.
inUnicodeback to summary
public Char2DArrayAssert inUnicode()

Use unicode character representation instead of standard representation in error messages.

With standard error message:

 assertThat(new char[][] {{'a', 'b'}, {'ć', 'd'}}).isDeepEqualTo(new char[][] {{'a', 'b'}, {'c', 'd'}});

org.opentest4j.AssertionFailedError:
Expecting "actual[1][0]" value to be equal to:
 <'c'>
but was
 <'ć'>
With unicode based error message:
 assertThat(new char[][] {{'a', 'b'}, {'ć', 'd'}}).inUnicode().isDeepEqualTo(new char[][] {{'a', 'b'}, {'c', 'd'}});

org.opentest4j.AssertionFailedError:
Expecting actual[1][0] value to be equal to:
 <c>
but was
 <ć>
Returns:Char2DArrayAssert

this assertion object.

Annotations
@CheckReturnValue
isDeepEqualToback to summary
public Char2DArrayAssert isDeepEqualTo(char[][] expected)

Implements abstract org.assertj.core.api.Abstract2DArrayAssert.isDeepEqualTo.

Verifies that the actual char[][] is deeply equal to the given one.

Two array references are considered deeply equal if both are null or if they refer to arrays that contain the same number of elements and all corresponding pairs of elements in the two arrays are deeply equal.

Example:

 // assertion will pass
assertThat(new char[][] {{'1', '2'}, {'3', '4'}}).isDeepEqualTo(new char[][] {{'1', '2'}, {'3', '4'}});

// assertions will fail
assertThat(new char[][] {{'1', '2'}, {'3', '4'}}).isDeepEqualTo(new char[][] {{'1', '2'}, {'9', '0'}});
assertThat(new char[][] {{'1', '2'}, {'3', '4'}}).isDeepEqualTo(new char[][] {{'1', '2', '3'}, {'4'}});
Parameters
expected:char[][]

the given value to compare the actual value to.

Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
if the actual value is not deeply equal to the given one.
isEmptyback to summary
public void isEmpty()

Implements org.assertj.core.api.Array2DAssert.isEmpty.

Verifies that the actual char[][] is empty, empty means the array has no elements, said otherwise it can have any number of rows but all rows must be empty.

Example:

 // assertions will pass
assertThat(new char[][] { {} }).isEmpty();
// this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
assertThat(new char[][] { { }, { }, { } }).isEmpty();

// assertions will fail
assertThat(new char[][] { {'a'}, {'b'} }).isEmpty();
char[][] array = null;
assertThat(array).isEmpty();
Annotations
@Override
Exceptions
AssertionError:
if the actual char[][] is not empty.
isEqualToback to summary
public Char2DArrayAssert isEqualTo(Object expected)

Overrides org.assertj.core.api.AbstractAssert.isEqualTo.

Implements org.assertj.core.api.Assert.isEqualTo.

Verifies that the actual char[][] is equal to the given one.

Warning

This method will use equals to compare (it will compare arrays references only).
Unless you specify a comparator with usingComparator(Comparator), it is advised to use isDeepEqualTo(char[][]) instead.

Example:

 char[][] array = {{'1', '2'}, {'3', '4'}}

// assertion will pass
assertThat(array).isEqualTo(array);

// assertion will fail as isEqualTo calls equals which compares arrays references only.
assertThat(array).isEqualTo(new char[][] {{'1', '2'}, {'3', '4'}});
Parameters
expected:Object

the given value to compare the actual char[][] to.

Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
if the actual char[][] is not equal to the given one.
isNotEmptyback to summary
public Char2DArrayAssert isNotEmpty()

Implements org.assertj.core.api.Array2DAssert.isNotEmpty.

Verifies that the actual char[][] is not empty, not empty means the array has at least one char element.

Example:

 // assertion will pass
assertThat(new char[][] { {'a'}, {'b'} }).isNotEmpty();
assertThat(new char[][] { { }, {'b'} }).isNotEmpty();

// assertions will fail
assertThat(new char[][] { }).isNotEmpty();
assertThat(new char[][] { { } }).isNotEmpty();
// this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
assertThat(new char[][] { { }, { }, { } }).isNotEmpty();
char[][] array = null;
assertThat(array).isNotEmpty();
Returns:Char2DArrayAssert

this assertion object.

Annotations
@Override
Exceptions
AssertionError:
if the actual char[][] is empty or null.
isNullOrEmptyback to summary
public void isNullOrEmpty()

Implements org.assertj.core.api.Array2DAssert.isNullOrEmpty.

Verifies that the actual char[][] is null or empty, empty means the array has no elements, said otherwise it can have any number of rows but all rows must be empty.

Example:

 // assertions will pass
char[][] array = null;
assertThat(array).isNullOrEmpty();
assertThat(new char[][] { }).isNullOrEmpty();
assertThat(new char[][] { { } }).isNullOrEmpty();
// this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
assertThat(new char[][] { { }, { }, { } }).isNullOrEmpty();

// assertion will fail
assertThat(new char[][] { {'a'}, {'b'} }).isNullOrEmpty();
Annotations
@Override
Exceptions
AssertionError:
if the actual char[][] is not null or not empty.