@Test(timeout = 100, expected = InappropriateMatrixDimensionException.class) public void invalidDataMatrixSubtraction() throws Exception { int[][] matrix1 = { {0, 0, -1}, {-5, 3, 1, 4} }; int[][] matrix2 = { {-2, -1, 1, 7}, {-9, 9, -1, 3} }; int[][] expectedResultMatrix = new int[matrix1.length][matrix1[0].length]; for (int i = 0; i < expectedResultMatrix.length; i++) { for (int j = 0; j < expectedResultMatrix[i].length; j++) { expectedResultMatrix[i][j] = matrix1[i][j] - matrix2[i][j]; } } Assert.assertArrayEquals( expectedResultMatrix, MatrixOperationsUtil.matrixSubtraction(matrix1, matrix2)); }