### Question:
Matrix { public abstract MatrixNonZeroElementRowIterator getNonZeroElementRowIterator(final int row); protected  Matrix(final int numRows, final int numCols); final int getElementCount(); final int getRowCount(); final int getColumnCount(); final double getAt(final int row, final int col); final void setAt(final int row, final int col, final double val); final void incrementAt(final int row, final int col, final double val); final ColumnVector getRowSumVector(); final ColumnVector getColumnSumVector(); Collection<Integer> normalizeColumns(); void removeNegatives(); void removeLessThan(final double minValue); final void scale(final double scale); Matrix multiplyElementWise(final Matrix matrix); Matrix addElementWise(final Matrix matrix); final double absSum(); final double sum(); ColumnVector multiply(final ColumnVector vector); final Matrix transpose(); Matrix roundTo(final int numPlaces); Matrix multiply(final double scalar); Matrix add(final double scalar); Matrix abs(); Matrix sqrt(); final boolean isSameSize(final Matrix matrix); final boolean isZeroMatrix(); @Override int hashCode(); @Override boolean equals(final Object obj); void forEach(final ReadOnlyElementVisitorFunction func); abstract MatrixNonZeroElementRowIterator getNonZeroElementRowIterator(final int row);  }### Answer:
@Test public void hasNextReturnsTrueIfMoreColumnsAreAvailable() { final TMatrix matrix = this.createMatrixForIteratorTests(); final MatrixNonZeroElementRowIterator iterator = matrix.getNonZeroElementRowIterator(0); for (int i = 0; i < 3; i++) { MatcherAssert.assertThat(iterator.hasNext(), IsEqual.equalTo(true)); iterator.next(); } }
@Test public void hasNextReturnsFalseImmediatelyForZeroRow() { final TMatrix matrix = this.createMatrixForIteratorTests(); final MatrixNonZeroElementRowIterator iterator = matrix.getNonZeroElementRowIterator(1); MatcherAssert.assertThat(iterator.hasNext(), IsEqual.equalTo(false)); ExceptionAssert.assertThrows(v -> iterator.next(), IndexOutOfBoundsException.class); }
@Test public void hasNextReturnsFalseAfterAllElementsHaveBeenIteratedForNonZeroRow() { final TMatrix matrix = this.createMatrixForIteratorTests(); final MatrixNonZeroElementRowIterator iterator = matrix.getNonZeroElementRowIterator(0); for (int i = 0; i < 3; i++) { iterator.next(); } MatcherAssert.assertThat(iterator.hasNext(), IsEqual.equalTo(false)); ExceptionAssert.assertThrows(v -> iterator.next(), IndexOutOfBoundsException.class); }
@Test public void nextReturnsCorrectMatrixElementsInOrder() { final TMatrix matrix = this.createMatrixForIteratorTests(); final MatrixNonZeroElementRowIterator iterator = matrix.getNonZeroElementRowIterator(0); MatcherAssert.assertThat(iterator.next(), IsEqual.equalTo(new MatrixElement(0, 0, 1.1))); MatcherAssert.assertThat(iterator.next(), IsEqual.equalTo(new MatrixElement(0, 1, 2.2))); MatcherAssert.assertThat(iterator.next(), IsEqual.equalTo(new MatrixElement(0, 3, 4.4))); }