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

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.
All Known Implementing Classes:
Abstract2DArrayAssert, Boolean2DArrayAssert, Byte2DArrayAssert, Char2DArrayAssert, Double2DArrayAssert, Float2DArrayAssert, Int2DArrayAssert, Long2DArrayAssert, Object2DArrayAssert, Short2DArrayAssert

public interface Array2DAssert<SELF extends Array2DAssert<SELF,ELEMENT>,ELEMENT>
Assertions applicable to two-dimensional arrays.
Since:
3.17.0
Author:
Maciej Wajcht
  • Method Summary

    Modifier and Type
    Method
    Description
    hasDimensions(int expectedFirstDimension, int expectedSecondDimension)
    Verifies that the actual 2D array has the given dimensions.
    hasNumberOfRows(int expected)
    Verifies that the actual two-dimensional array has the given number of rows.
    Verifies that the actual array has the same dimensions as the given array.
    void
    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.
    Verifies that the actual array is not empty, not empty means the array has at least one element.
    void
    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 Details

    • isNullOrEmpty

      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();
      Throws:
      AssertionError - if the actual array is not null or not empty.
    • isEmpty

      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();
      Throws:
      AssertionError - if the actual array is not empty.
    • isNotEmpty

      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:
      this assertion object.
      Throws:
      AssertionError - if the actual array is empty or null.
    • hasDimensions

      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 - the expected number of values in first dimension of the actual array.
      expectedSecondDimension - the expected number of values in second dimension of the actual array.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual array's dimensions are not equal to the given ones.
    • hasNumberOfRows

      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 - the expected number of rows of the two-dimensional array.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual number of rows are not equal to the given one.
    • hasSameDimensionsAs

      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 - the array to compare dimensions with actual array.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual array is null.
      AssertionError - if the array parameter is null or is not a true array.
      AssertionError - if actual array and given array don't have the same dimensions.