Class Object2DArrayAssert<ELEMENT>

    • Constructor Detail

      • Object2DArrayAssert

        public Object2DArrayAssert​(ELEMENT[][] actual)
    • Method Detail

      • isDeepEqualTo

        public Object2DArrayAssert<ELEMENT> isDeepEqualTo​(ELEMENT[][] expected)
        Verifies that the actual ELEMENT[][] 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 String[][] {{"1", "2"}, {"3", "4"}}).isDeepEqualTo(new String[][] {{"1", "2"}, {"3", "4"}});
        
         // assertions will fail
         assertThat(new String[][] {{"1", "2"}, {"3", "4"}}).isDeepEqualTo(new String[][] {{"1", "2"}, {"9", "0"}});
         assertThat(new String[][] {{"1", "2"}, {"3", "4"}}).isDeepEqualTo(new String[][] {{"1", "2", "3"}, {"4"}});
        Specified by:
        isDeepEqualTo in class Abstract2DArrayAssert<Object2DArrayAssert<ELEMENT>,​ELEMENT[][],​ELEMENT>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual value is not deeply equal to the given one.
      • isNullOrEmpty

        public void isNullOrEmpty()
        Verifies that the actual ELEMENT[][] 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
         String[][] array = null;
         assertThat(array).isNullOrEmpty();
         assertThat(new String[][] { }).isNullOrEmpty();
         assertThat(new String[][] { { } }).isNullOrEmpty();
         // this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
         assertThat(new String[][] { { }, { }, { } }).isNullOrEmpty();
        
         // assertion will fail
         assertThat(new String[][] { {'a'}, {'b'} }).isNullOrEmpty();
        Throws:
        AssertionError - if the actual ELEMENT[][] is not null or not empty.
      • isEmpty

        public void isEmpty()
        Verifies that the actual ELEMENT[][] 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 String[][] { {} }).isEmpty();
         // this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
         assertThat(new String[][] { { }, { }, { } }).isEmpty();
        
         // assertions will fail
         assertThat(new String[][] { {'a'}, {'b'} }).isEmpty();
         String[][] array = null;
         assertThat(array).isEmpty();
        Throws:
        AssertionError - if the actual ELEMENT[][] is not empty.
      • isNotEmpty

        public Object2DArrayAssert<ELEMENT> isNotEmpty()
        Verifies that the actual ELEMENT[][] is not empty, not empty means the array has at least one char element.

        Example:

         // assertion will pass
         assertThat(new String[][] { {'a'}, {'b'} }).isNotEmpty();
         assertThat(new String[][] { { }, {'b'} }).isNotEmpty();
        
         // assertions will fail
         assertThat(new String[][] { }).isNotEmpty();
         assertThat(new String[][] { { } }).isNotEmpty();
         // this is considered empty as there are no elements in the 2d array which is comprised of 3 empty rows.
         assertThat(new String[][] { { }, { }, { } }).isNotEmpty();
         String[][] array = null;
         assertThat(array).isNotEmpty();
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual ELEMENT[][] is empty or null.
      • hasDimensions

        public Object2DArrayAssert<ELEMENT> hasDimensions​(int expectedFirstDimension,
                                                          int expectedSecondDimension)
        Verifies that the actual ELEMENT[][] has the the given dimensions.

        Example:

         // assertion will pass
         assertThat(new String[][] { {"1", "2", "3"}, {"4", "5", "6"} }).hasDimensions(2, 3);
        
         // assertions will fail
         assertThat(new String[][] { }).hasDimensions(1, 1);
         assertThat(new String[][] { {"1", "2", "3"}, {"4", "5", "6"} }).hasDimensions(3, 2);
         assertThat(new String[][] { {"1", "2", "3"}, {"4", "5", "6", "7"} }).hasDimensions(2, 3); 
        Parameters:
        expectedFirstDimension - the expected number of values in first dimension of the actual ELEMENT[][].
        expectedSecondDimension - the expected number of values in second dimension of the actual ELEMENT[][].
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the number of values of the actual ELEMENT[][] is not equal to the given one.
      • hasSameDimensionsAs

        public Object2DArrayAssert<ELEMENT> hasSameDimensionsAs​(Object array)
        Verifies that the actual ELEMENT[][] has the same dimensions as the given array.

        Parameter is declared as Object to accept both Object and primitive arrays.

        Example:
         String[][] stringArray = {{"a", "b", "c""}, {"d", "e", "f""}};
         char[][] charArray = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
        
         // assertion will pass
         assertThat(stringArray).hasSameDimensionsAs(charArray);
        
         // assertions will fail
         assertThat(stringArray).hasSameDimensionsAs(new char[][] {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}});
         assertThat(stringArray).hasSameDimensionsAs(new char[][] {{'a', 'b'}, {'c', 'd', 'e'}});
         assertThat(stringArray).hasSameDimensionsAs(new char[][] {{'a', 'b', 'c'}, {'d', 'e'}});
        Parameters:
        array - the array to compare dimensions with actual ELEMENT[][].
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual ELEMENT[][] is null.
        AssertionError - if the array parameter is null or is not a true array.
        AssertionError - if actual ELEMENT[][] and given array don't have the same dimensions.
      • contains

        public Object2DArrayAssert<ELEMENT> contains​(ELEMENT[] value,
                                                     Index index)
        Verifies that the actual ELEMENT[][] contains the given ELEMENT[] at the given index.

        Example:

         // assertion will pass
         assertThat(new String[][] {{"a", "b"}, {"c", "d"}}).contains(new String[] {"a", "b"}, atIndex(0));
        
         // assertion will fail
         assertThat(new String[][] {{"a", "b"}, {"c", "d"}}).contains(new String[] {"a", "b"}, atIndex(1));
        Parameters:
        value - the value to look for.
        index - the index where the value should be stored in the actual ELEMENT[][].
        Returns:
        myself assertion object.
        Throws:
        AssertionError - if the actual ELEMENT[][] is null or empty.
        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 ELEMENT[][].
        AssertionError - if the actual ELEMENT[][] does not contain the given value at the given index.
      • doesNotContain

        public Object2DArrayAssert<ELEMENT> doesNotContain​(ELEMENT[] value,
                                                           Index index)
        Verifies that the actual ELEMENT[][] does not contain the given ELEMENT[] at the given index.

        Example:

         // assertion will pass
         assertThat(new String[][] {{"a", "b"}, {"c", "d"}}).doesNotContain(new String[] {"a", "b"}, atIndex(1));
        
         // assertion will fail
         assertThat(new String[][] {{"a", "b"}, {"c", "d"}}).doesNotContain(new String[] {"a", "b"}, atIndex(0));
        Parameters:
        value - the value to look for.
        index - the index where the value should be stored in the actual ELEMENT[][].
        Returns:
        myself assertion object.
        Throws:
        AssertionError - if the actual ELEMENT[][] is null.
        NullPointerException - if the given Index is null.
        AssertionError - if the actual ELEMENT[][] contains the given value at the given index.