-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and avoid bugs around empty and singleton iterators.
- Loading branch information
1 parent
e137af4
commit 6ba911d
Showing
2 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/io/github/jervenbolleman/handlegraph4j/iterators/AutoClosedIteratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.github.jervenbolleman.handlegraph4j.iterators; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class AutoClosedIteratorTest { | ||
|
||
@Test | ||
public void empty() { | ||
try (AutoClosedIterator<Object> empty = AutoClosedIterator.empty()) { | ||
assertFalse(empty.hasNext()); | ||
assertThrows(NoSuchElementException.class, () -> empty.next()); | ||
} | ||
} | ||
|
||
@Test | ||
public void concatTwoEmptyIterators() { | ||
try (AutoClosedIterator<Object> empty1 = AutoClosedIterator.empty(); | ||
AutoClosedIterator<Object> empty2 = AutoClosedIterator.empty(); | ||
AutoClosedIterator<Object> both = AutoClosedIterator.concat(empty1, empty2)) { | ||
assertFalse(both.hasNext()); | ||
assertThrows(NoSuchElementException.class, () -> both.next()); | ||
} | ||
} | ||
|
||
@Test | ||
public void concatEmptyThenFullIterators() { | ||
try (AutoClosedIterator<Object> empty1 = AutoClosedIterator.empty(); | ||
AutoClosedIterator<Object> notEmpty= AutoClosedIterator.of("String"); | ||
AutoClosedIterator<Object> both = AutoClosedIterator.concat(empty1, notEmpty)) { | ||
assertTrue(both.hasNext()); | ||
assertNotNull(both.next()); | ||
assertFalse(both.hasNext()); | ||
assertThrows(NoSuchElementException.class, () -> both.next()); | ||
} | ||
} | ||
} | ||
|