@Test
public void hasNextCancels() {

    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    Flowable.fromIterable(new Iterable<Integer>() {
        @Override
        public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                int count;
                @Override
                public boolean hasNext() {
                    if (++count == 2) {
                        ts.cancel();
                    }
                    return true;
                }
                @Override
                public Integer next() {
                    return 1;
                }
                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    })
    .subscribe(ts);
    ts.assertValue(1)
    .assertNoErrors()
    .assertNotComplete();
}