-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathLinkIterableTest.java
More file actions
48 lines (39 loc) · 1.52 KB
/
LinkIterableTest.java
File metadata and controls
48 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.nibor.autolink;
import org.junit.jupiter.api.Test;
import java.util.Iterator;
import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
public class LinkIterableTest {
@Test
public void iteratorIsNew() {
Iterable<LinkSpan> iterable = getSingleLinkIterable();
assertEquals(LinkType.URL, iterable.iterator().next().getType());
assertEquals(LinkType.URL, iterable.iterator().next().getType());
}
@Test
public void hasNextOnlyAdvancesOnce() {
Iterable<LinkSpan> iterable = getSingleLinkIterable();
Iterator<LinkSpan> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
assertTrue(iterator.hasNext());
assertNotNull(iterator.next());
assertFalse(iterator.hasNext());
assertFalse(iterator.hasNext());
}
@Test
public void nextThrowsNoSuchElementException() {
Iterable<LinkSpan> iterable = getSingleLinkIterable();
Iterator<LinkSpan> iterator = iterable.iterator();
assertNotNull(iterator.next());
assertThrows(NoSuchElementException.class, iterator::next);
}
@Test
public void removeUnsupported() {
Iterable<LinkSpan> iterable = getSingleLinkIterable();
assertThrows(UnsupportedOperationException.class, () -> iterable.iterator().remove());
}
private Iterable<LinkSpan> getSingleLinkIterable() {
String input = "foo http://example.com";
return LinkExtractor.builder().build().extractLinks(input);
}
}