Top Description Methods
org.assertj.core.api

public Interface Array2DAssert<SELF extends Array2DAssert<SELF, ELEMENT>, ELEMENT>

Known Direct Implementers
org.assertj.core.api.Abstract2DArrayAssert
Type Parameters
<SELF>
the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
<ELEMENT>
the type of elements of the "actual" value.

Assertions applicable to two-dimensional arrays.
Author
Maciej Wajcht
Since
3.17.0

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

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

Verifies that the actual 2D array has the given dimensions.

public SELF

Returns:

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

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

public SELF

Returns:

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

Verifies that the actual array has the same dimensions as the given array.

public void
isEmpty()

Verifies that the actual array 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 SELF

Returns:

this assertion object.
isNotEmpty
()

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

public void
isNullOrEmpty()

Verifies that the actual array 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.

Method Detail

hasDimensionsback to summary
public SELF hasDimensions(int expectedFirstDimension, int expectedSecondDimension)

Verifies that the actual 2D array has the given dimensions.

Example:

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

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

the expected number of values in first dimension of the actual array.

expectedSecondDimension:int

the expected number of values in second dimension of the actual array.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual array's dimensions are not equal to the given ones.
hasNumberOfRowsback to summary
public SELF hasNumberOfRows(int expected)

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

Example:

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

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

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

Returns:SELF

this assertion object.

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

Verifies that the actual array has the same dimensions as the given array.

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

Example:
 String[][] stringArray = {{"a", "b", "c"}, {"d", "e", "f"}};
int[][] intArray = {{1, 2, 3}, {4, 5, 6}};

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

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

the array to compare dimensions with actual array.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual array is null.
  • if the array parameter is null or is not a true array.
  • if actual array and given array don't have the same dimensions.
isEmptyback to summary
public void isEmpty()

Verifies that the actual array 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 int[][] {{}}).isEmpty();
// this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
assertThat(new int[][] {{ }, { }, { }}).isEmpty();

// assertions will fail
assertThat(new int[][] {{ 1 }, { 2 }}).isEmpty();
int[][] array = null;
assertThat(array).isEmpty();
Exceptions
AssertionError:
if the actual array is not empty.
isNotEmptyback to summary
public SELF isNotEmpty()

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

Example:

 // assertions will pass
assertThat(new int[][] {{ 1 }, { 2 }}).isNotEmpty();
assertThat(new int[][] {{ }, { 2 }}).isNotEmpty();

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

this assertion object.

Exceptions
AssertionError:
if the actual array is empty or null.
isNullOrEmptyback to summary
public void isNullOrEmpty()

Verifies that the actual array 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
int[][] array = null;
assertThat(array).isNullOrEmpty();
assertThat(new int[][] { }).isNullOrEmpty();
assertThat(new int[][] {{ }}).isNullOrEmpty();
// this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
assertThat(new int[][] {{ }, { }, { }}).isNullOrEmpty();

// assertion will fail
assertThat(new int[][] {{ 1 }, { 2 }}).isNullOrEmpty();
Exceptions
AssertionError:
if the actual array is not null or not empty.