Skip to content

Commit d0c21e3

Browse files
WojciechZankowskiSekarMylsamy
authored andcommitted
Add hasNumberOfRows to two-dimensional array assertions (assertj#2461)
Co-authored-by: Sekar Mylsamy <SekarMylsamy@users.noreply.github.com>
1 parent f115e9d commit d0c21e3

File tree

39 files changed

+996
-2
lines changed

39 files changed

+996
-2
lines changed

src/main/java/org/assertj/core/api/Array2DAssert.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package org.assertj.core.api;
1414

1515
/**
16-
* Assertions applicable to two-dimensional arrays,
16+
* Assertions applicable to two-dimensional arrays.
1717
*
1818
* @param <SELF> the "self" type of this assertion class. Please read &quot;<a href="http://bit.ly/1IZIRcY"
1919
* target="_blank">Emulating
@@ -104,6 +104,25 @@ public interface Array2DAssert<SELF extends Array2DAssert<SELF, ELEMENT>, ELEMEN
104104
*/
105105
SELF hasDimensions(int expectedFirstDimension, int expectedSecondDimension);
106106

107+
/**
108+
* Verifies that the actual two-dimensional array has the given number of rows.
109+
* <p>
110+
* Example:
111+
* <pre><code class='java'> // assertion will pass
112+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(2);
113+
* assertThat(new int[][] {{1}, {1, 2}, {1, 2, 3}}).hasNumberOfRows(3);
114+
*
115+
* // assertions will fail
116+
* assertThat(new int[][] { }).hasNumberOfRows(1);
117+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(3);
118+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6, 7}}).hasNumberOfRows(1); </code></pre>
119+
*
120+
* @param expected the expected number of rows of the two-dimensional array.
121+
* @return {@code this} assertion object.
122+
* @throws AssertionError if the actual number of rows are not equal to the given one.
123+
*/
124+
SELF hasNumberOfRows(int expected);
125+
107126
/**
108127
* Verifies that the actual array has the same dimensions as the given array.
109128
* <p>

src/main/java/org/assertj/core/api/Boolean2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ public Boolean2DArrayAssert hasDimensions(int expectedFirstDimension, int expect
211211
return myself;
212212
}
213213

214+
/**
215+
* Verifies that the actual two-dimensional array has the given number of rows.
216+
* <p>
217+
* Example:
218+
* <pre><code class='java'> // assertion will pass
219+
* assertThat(new boolean[][] {{true, true, true}, {false, false, false}}).hasNumberOfRows(2);
220+
* assertThat(new boolean[][] {{true}, {true, false}, {true, false, false}}).hasNumberOfRows(3);
221+
*
222+
* // assertions will fail
223+
* assertThat(new boolean[][] { }).hasNumberOfRows(1);
224+
* assertThat(new boolean[][] {{true, true, true}, {false, false, false}}).hasNumberOfRows(3);
225+
* assertThat(new boolean[][] {{true, true, true}, {false, false, false, false}}).hasNumberOfRows(1); </code></pre>
226+
*
227+
* @param expected the expected number of rows of the two-dimensional array.
228+
* @return {@code this} assertion object.
229+
* @throws AssertionError if the actual number of rows are not equal to the given one.
230+
*/
231+
@Override
232+
public Boolean2DArrayAssert hasNumberOfRows(int expected) {
233+
boolean2dArrays.assertNumberOfRows(info, actual, expected);
234+
return myself;
235+
}
236+
214237
/**
215238
* Verifies that the actual {@code boolean[][]} has the same dimensions as the given array.
216239
* <p>

src/main/java/org/assertj/core/api/Byte2DArrayAssert.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,30 @@ public Byte2DArrayAssert hasDimensions(int expectedFirstDimension, int expectedS
212212
return myself;
213213
}
214214

215+
/**
216+
* Verifies that the actual two-dimensional array has the given number of rows.
217+
* <p>
218+
* Example:
219+
* <pre><code class='java'> // assertion will pass
220+
* assertThat(new byte[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(2);
221+
* assertThat(new byte[][] {{1}, {1, 2}, {1, 2, 3}}).hasNumberOfRows(3);
222+
*
223+
* // assertions will fail
224+
* assertThat(new byte[][] { }).hasNumberOfRows(1);
225+
* assertThat(new byte[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(3);
226+
* assertThat(new byte[][] {{1, 2, 3}, {4, 5, 6, 7}}).hasNumberOfRows(1); </code></pre>
227+
*
228+
* @param expected the expected number of rows of the two-dimensional array.
229+
* @return {@code this} assertion object.
230+
* @throws AssertionError if the actual number of rows are not equal to the given one.
231+
*/
232+
@Override
233+
public Byte2DArrayAssert hasNumberOfRows(int expected) {
234+
byte2dArrays.assertNumberOfRows(info, actual, expected);
235+
return myself;
236+
}
237+
238+
215239
/**
216240
* Verifies that the actual {@code byte[][]} has the same dimensions as the given array.
217241
* <p>

src/main/java/org/assertj/core/api/Char2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,29 @@ public Char2DArrayAssert hasDimensions(int expectedFirstDimension, int expectedS
212212
return myself;
213213
}
214214

215+
/**
216+
* Verifies that the actual two-dimensional array has the given number of rows.
217+
* <p>
218+
* Example:
219+
* <pre><code class='java'> // assertion will pass
220+
* assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6'}}).hasNumberOfRows(2);
221+
* assertThat(new char[][] {{'1'}, {'1', '2'}, {'1', '2', '3'}}).hasNumberOfRows(3);
222+
*
223+
* // assertions will fail
224+
* assertThat(new char[][] { }).hasNumberOfRows(1);
225+
* assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6'}}).hasNumberOfRows(3);
226+
* assertThat(new char[][] {{'1', '2', '3'}, {'4', '5', '6', '7'}}).hasNumberOfRows(1); </code></pre>
227+
*
228+
* @param expected the expected number of rows of the two-dimensional array.
229+
* @return {@code this} assertion object.
230+
* @throws AssertionError if the actual number of rows are not equal to the given one.
231+
*/
232+
@Override
233+
public Char2DArrayAssert hasNumberOfRows(int expected) {
234+
char2dArrays.assertNumberOfRows(info, actual, expected);
235+
return myself;
236+
}
237+
215238
/**
216239
* Verifies that the actual {@code char[][]} has the same dimensions as the given array.
217240
* <p>

src/main/java/org/assertj/core/api/Double2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,29 @@ public Double2DArrayAssert hasDimensions(int expectedFirstDimension, int expecte
212212
return myself;
213213
}
214214

215+
/**
216+
* Verifies that the actual two-dimensional array has the given number of rows.
217+
* <p>
218+
* Example:
219+
* <pre><code class='java'> // assertion will pass
220+
* assertThat(new double[][] {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}}).hasNumberOfRows(2);
221+
* assertThat(new double[][] {{1.0}, {1.0, 2.0}, {1.0, 2.0, 3.0}}).hasNumberOfRows(3);
222+
*
223+
* // assertions will fail
224+
* assertThat(new double[][] { }).hasNumberOfRows(1);
225+
* assertThat(new double[][] {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}}).hasNumberOfRows(3);
226+
* assertThat(new double[][] {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0, 7.0}}).hasNumberOfRows(1); </code></pre>
227+
*
228+
* @param expected the expected number of rows of the two-dimensional array.
229+
* @return {@code this} assertion object.
230+
* @throws AssertionError if the actual number of rows are not equal to the given one.
231+
*/
232+
@Override
233+
public Double2DArrayAssert hasNumberOfRows(int expected) {
234+
double2dArrays.assertNumberOfRows(info, actual, expected);
235+
return myself;
236+
}
237+
215238
/**
216239
* Verifies that the actual {@code double[][]} has the same dimensions as the given array.
217240
* <p>

src/main/java/org/assertj/core/api/Float2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ public Float2DArrayAssert hasDimensions(int expectedFirstDimension, int expected
207207
return myself;
208208
}
209209

210+
/**
211+
* Verifies that the actual two-dimensional array has the given number of rows.
212+
* <p>
213+
* Example:
214+
* <pre><code class='java'> // assertion will pass
215+
* assertThat(new float[][] {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}).hasNumberOfRows(2);
216+
* assertThat(new float[][] {{1.0f}, {1.0f, 2.0f}, {1.0f, 2.0f, 3.0f}}).hasNumberOfRows(3);
217+
*
218+
* // assertions will fail
219+
* assertThat(new float[][] { }).hasNumberOfRows(1);
220+
* assertThat(new float[][] {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}).hasNumberOfRows(3);
221+
* assertThat(new float[][] {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f, 7.0f}}).hasNumberOfRows(1); </code></pre>
222+
*
223+
* @param expected the expected number of rows of the two-dimensional array.
224+
* @return {@code this} assertion object.
225+
* @throws AssertionError if the actual number of rows are not equal to the given one.
226+
*/
227+
@Override
228+
public Float2DArrayAssert hasNumberOfRows(int expected) {
229+
float2dArrays.assertNumberOfRows(info, actual, expected);
230+
return myself;
231+
}
232+
210233
/**
211234
* Verifies that the actual {@code float[][]} has the same dimensions as the given array.
212235
* <p>

src/main/java/org/assertj/core/api/Int2DArrayAssert.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ public Int2DArrayAssert hasDimensions(int expectedFirstDimension, int expectedSe
125125
return myself;
126126
}
127127

128+
129+
/**
130+
* Verifies that the actual two-dimensional array has the given number of rows.
131+
* <p>
132+
* Example:
133+
* <pre><code class='java'> // assertion will pass
134+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(2);
135+
* assertThat(new int[][] {{1}, {1, 2}, {1, 2, 3}}).hasNumberOfRows(3);
136+
*
137+
* // assertions will fail
138+
* assertThat(new int[][] { }).hasNumberOfRows(1);
139+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(3);
140+
* assertThat(new int[][] {{1, 2, 3}, {4, 5, 6, 7}}).hasNumberOfRows(1); </code></pre>
141+
*
142+
* @param expected the expected number of rows of the two-dimensional array.
143+
* @return {@code this} assertion object.
144+
* @throws AssertionError if the actual number of rows are not equal to the given one.
145+
*/
146+
@Override
147+
public Int2DArrayAssert hasNumberOfRows(int expected) {
148+
int2dArrays.assertNumberOfRows(info, actual, expected);
149+
return myself;
150+
}
151+
128152
/**
129153
* Verifies that the actual {@code int[][]} has the same dimensions as the given array.
130154
* <p>

src/main/java/org/assertj/core/api/Long2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ public Long2DArrayAssert hasDimensions(int expectedFirstDimension, int expectedS
211211
return myself;
212212
}
213213

214+
/**
215+
* Verifies that the actual two-dimensional array has the given number of rows.
216+
* <p>
217+
* Example:
218+
* <pre><code class='java'> // assertion will pass
219+
* assertThat(new long[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(2);
220+
* assertThat(new long[][] {{1}, {1, 2}, {1, 2, 3}}).hasNumberOfRows(3);
221+
*
222+
* // assertions will fail
223+
* assertThat(new long[][] { }).hasNumberOfRows(1);
224+
* assertThat(new long[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(3);
225+
* assertThat(new long[][] {{1, 2, 3}, {4, 5, 6, 7}}).hasNumberOfRows(1); </code></pre>
226+
*
227+
* @param expected the expected number of rows of the two-dimensional array.
228+
* @return {@code this} assertion object.
229+
* @throws AssertionError if the actual number of rows are not equal to the given one.
230+
*/
231+
@Override
232+
public Long2DArrayAssert hasNumberOfRows(int expected) {
233+
long2dArrays.assertNumberOfRows(info, actual, expected);
234+
return myself;
235+
}
236+
214237
/**
215238
* Verifies that the actual {@code long[][]} has the same dimensions as the given array.
216239
* <p>

src/main/java/org/assertj/core/api/Object2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ public Object2DArrayAssert<ELEMENT> hasDimensions(int expectedFirstDimension, in
214214
return myself;
215215
}
216216

217+
/**
218+
* Verifies that the actual two-dimensional array has the given number of rows.
219+
* <p>
220+
* Example:
221+
* <pre><code class='java'> // assertion will pass
222+
* assertThat(new String[][] {{"1", "2", "3"}, {"4", "5", "6"}}).hasNumberOfRows(2);
223+
* assertThat(new String[][] {{"1"}, {"1", "2"}, {"1", "2", "3"}}).hasNumberOfRows(3);
224+
*
225+
* // assertions will fail
226+
* assertThat(new String[][] { }).hasNumberOfRows(1);
227+
* assertThat(new String[][] {{"1", "2", "3"}, {"4", "5", "6"}}).hasNumberOfRows(3);
228+
* assertThat(new String[][] {{"1", "2", "3"}, {"4", "5", "6", "7"}}).hasNumberOfRows(1); </code></pre>
229+
*
230+
* @param expected the expected number of rows of the two-dimensional array.
231+
* @return {@code this} assertion object.
232+
* @throws AssertionError if the actual number of rows are not equal to the given one.
233+
*/
234+
@Override
235+
public Object2DArrayAssert<ELEMENT> hasNumberOfRows(int expected) {
236+
object2dArrays.assertNumberOfRows(info, actual, expected);
237+
return myself;
238+
}
239+
217240
/**
218241
* Verifies that the actual {@code ELEMENT[][]} has the same dimensions as the given array.
219242
* <p>

src/main/java/org/assertj/core/api/Short2DArrayAssert.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,29 @@ public Short2DArrayAssert hasDimensions(int expectedFirstDimension, int expected
210210
return myself;
211211
}
212212

213+
/**
214+
* Verifies that the actual two-dimensional array has the given number of rows.
215+
* <p>
216+
* Example:
217+
* <pre><code class='java'> // assertion will pass
218+
* assertThat(new short[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(2);
219+
* assertThat(new short[][] {{1}, {1, 2}, {1, 2, 3}}).hasNumberOfRows(3);
220+
*
221+
* // assertions will fail
222+
* assertThat(new short[][] { }).hasNumberOfRows(1);
223+
* assertThat(new short[][] {{1, 2, 3}, {4, 5, 6}}).hasNumberOfRows(3);
224+
* assertThat(new short[][] {{1, 2, 3}, {4, 5, 6, 7}}).hasNumberOfRows(1); </code></pre>
225+
*
226+
* @param expected the expected number of rows of the two-dimensional array.
227+
* @return {@code this} assertion object.
228+
* @throws AssertionError if the actual number of rows are not equal to the given one.
229+
*/
230+
@Override
231+
public Short2DArrayAssert hasNumberOfRows(int expected) {
232+
short2dArrays.assertNumberOfRows(info, actual, expected);
233+
return myself;
234+
}
235+
213236
/**
214237
* Verifies that the actual {@code short[][]} has the same dimensions as the given array.
215238
* <p>

0 commit comments

Comments
 (0)