ModeShape/modeshape — pull request #1022 by rhauch (2014-01-02 18:22:32+00:00)
Title: MODE-2126 Corrected NodeIterator.hasNext() to never advance

Turns out that, in some cases, calling `iterator.hasNext()` multiple times before calling `iterator.next()` incorrectly advanced the iterator when it should not have. Most cases were fine, but it was a problem when the following two conditions were met:

1. new children were added to the parent node and these were not yet saved; and
2. the iterator was obtained to find nodes with names that matched a specific
pattern (e.g., `node.getNodes(namePattern)`)

This commit adds several test cases (one of which replicated the problem, while all the others tests show the problem is limited to the above conditions) and that fixes the problem.