-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COLLECTIONS-770 When creating an iterator chain containing other iterator chains flatten the resulting internal object. #308
Open
stevebosman-oc
wants to merge
2
commits into
apache:master
Choose a base branch
from
stevebosman-oc:feature/COLLECTIONS-770
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -37,10 +37,14 @@ public class IteratorChainTest extends AbstractIteratorTest<String> { | |
protected String[] testArray = { | ||
"One", "Two", "Three", "Four", "Five", "Six" | ||
}; | ||
protected String[] testArray1234 = { | ||
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight" | ||
}; | ||
|
||
protected List<String> list1 = null; | ||
protected List<String> list2 = null; | ||
protected List<String> list3 = null; | ||
protected List<String> list4 = null; | ||
|
||
public IteratorChainTest() { | ||
super(IteratorChainTest.class.getSimpleName()); | ||
|
@@ -57,6 +61,9 @@ public void setUp() { | |
list3 = new ArrayList<>(); | ||
list3.add("Five"); | ||
list3.add("Six"); | ||
list4 = new ArrayList<>(); | ||
list4.add("Seven"); | ||
list4.add("Eight"); | ||
} | ||
|
||
@Override | ||
|
@@ -170,4 +177,60 @@ public void testEmptyChain() { | |
); | ||
} | ||
|
||
@Test | ||
public void testChainOfChains() { | ||
final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator()); | ||
final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator()); | ||
final Iterator<String> iteratorChainOfChains = new IteratorChain<>(iteratorChain1, iteratorChain2); | ||
|
||
for (final String testValue : testArray1234) { | ||
final Object iterValue = iteratorChainOfChains.next(); | ||
|
||
assertEquals( "Iteration value is correct", testValue, iterValue ); | ||
} | ||
|
||
assertFalse("Iterator should now be empty", iteratorChainOfChains.hasNext()); | ||
|
||
try { | ||
iteratorChainOfChains.next(); | ||
} catch (final Exception e) { | ||
assertEquals("NoSuchElementException must be thrown", e.getClass(), NoSuchElementException.class); | ||
} | ||
} | ||
|
||
@Test | ||
public void testChainOfUnmodifiableChains() { | ||
final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator()); | ||
final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1); | ||
final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator()); | ||
final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2); | ||
final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2); | ||
|
||
for (final String testValue : testArray1234) { | ||
final Object iterValue = iteratorChainOfChains.next(); | ||
|
||
assertEquals( "Iteration value is correct", testValue, iterValue ); | ||
} | ||
|
||
assertFalse("Iterator should now be empty", iteratorChainOfChains.hasNext()); | ||
|
||
try { | ||
iteratorChainOfChains.next(); | ||
} catch (final Exception e) { | ||
assertEquals("NoSuchElementException must be thrown", e.getClass(), NoSuchElementException.class); | ||
} | ||
Comment on lines
+217
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace this with |
||
|
||
} | ||
|
||
@Test | ||
public void testChainOfUnmodifiableChainsRetainsUnmodifiableBehaviourOfNestedIterator() { | ||
final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator()); | ||
final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1); | ||
final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator()); | ||
final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2); | ||
final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2); | ||
|
||
iteratorChainOfChains.next(); | ||
assertThrows(UnsupportedOperationException.class, iteratorChainOfChains::remove, | ||
"Calling remove must fail when nested iterator is unmodifiable"); } | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with
assertThrows()