@Override
    public T next() {
        if (this.next != null || hasNext()) {
            final T out = this.next;
            this.next = null;
            return out;
        } else {
            throw new NoSuchElementException();
        }
    }
@Test
    void testNext() {
        try {
            // create the resettable Iterator
            SpillingResettableIterator<IntValue> iterator =
                    new SpillingResettableIterator<IntValue>(
                            this.reader,
                            this.serializer,
                            this.memman,
                            this.ioman,
                            2,
                            this.memOwner);
            // open the iterator
            iterator.open();

            IntValue record;
            int cnt = 0;
            while (cnt < NUM_TESTRECORDS) {
                record = iterator.next();
                assertThat(record).withFailMessage("Record was not read from iterator").isNotNull();
                cnt++;
            }

            assertThatThrownBy(iterator::next)
                    .withFailMessage("Too many records were read from iterator.")
                    .isInstanceOf(NoSuchElementException.class);

            iterator.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Test encountered an exception.");
        }
    }