@Test
public void testNextWithEmpty() {

    Observable<String> obs = Observable.<String> empty().observeOn(Schedulers.newThread());
    Iterator<String> it = next(obs).iterator();
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("At the end of an iterator should throw a NoSuchElementException");
    } catch (NoSuchElementException e) {
    }
    // If the observable is completed, hasNext always returns false and next always throw a NoSuchElementException.
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("At the end of an iterator should throw a NoSuchElementException");
    } catch (NoSuchElementException e) {
    }
}