package org.nibor.autolink;

import org.junit.Test;

import java.util.Iterator;
import java.util.NoSuchElementException;

import static org.junit.Assert.*;

public class LinkExtractorIterableTest {

    @Test
    public void iteratorIsNew() {
        Iterable<LinkSpan> iterable = getSingleElementIterable();
        assertEquals(LinkType.URL, iterable.iterator().next().getType());
        assertEquals(LinkType.URL, iterable.iterator().next().getType());
    }

    @Test
    public void hasNextOnlyAdvancesOnce() {
        Iterable<LinkSpan> iterable = getSingleElementIterable();
        Iterator<LinkSpan> iterator = iterable.iterator();
        assertTrue(iterator.hasNext());
        assertTrue(iterator.hasNext());
        assertNotNull(iterator.next());
        assertFalse(iterator.hasNext());
        assertFalse(iterator.hasNext());
    }

    @Test(expected = NoSuchElementException.class)
    public void nextThrowsNoSuchElementException() {
        Iterable<LinkSpan> iterable = getSingleElementIterable();
        Iterator<LinkSpan> iterator = iterable.iterator();
        assertNotNull(iterator.next());
        iterator.next();
    }

    private Iterable<LinkSpan> getSingleElementIterable() {
        String input = "foo http://example.com";
        return LinkExtractor.builder().build().extractLinks(input);
    }
}

@@ -1142,24 +1142,231 @@
 t();%0A    %7D%0A%0A
+    @Test(expected = UnsupportedOperationException.class)%0A    public void removeUnsupported() %7B%0A        Iterable%3CLinkSpan%3E iterable = getSingleElementIterable();%0A        iterable.iterator().remove();%0A    %7D%0A%0A
     private 

Add test for unsupported remove method