Skip to content

Commit 7375df4

Browse files
committed
More tests for SwingStreamUtils.asIterable(TreeModel)
1 parent 989ebb7 commit 7375df4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/java/io/github/parubok/stream/SwingStreamUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ public static Iterable<KTreePath> asIterable(TreeModel treeModel, TreeTraversalT
275275
return asIterable(treeModel, traversalType, true);
276276
}
277277

278+
/**
279+
* @return Iterator which does not check for the tree model modifications during the iteration.
280+
*/
278281
public static Iterable<KTreePath> asIterable(TreeModel treeModel, TreeTraversalType traversalType,
279282
boolean failOnModification) {
280283
requireNonNull(treeModel);

src/test/java/io/github/parubok/stream/SwingStreamUtilsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,15 @@ public void removeTreeModelListener(TreeModelListener l) {
12641264
};
12651265
Assertions.assertEquals(0, listeners.size());
12661266
Iterator<KTreePath> iterator = SwingStreamUtils.asIterable(model).iterator();
1267-
Assertions.assertEquals(1, listeners.size());
1267+
Assertions.assertEquals(1, listeners.size()); // must be removed after iteration
12681268
while (iterator.hasNext()) {
12691269
iterator.next();
12701270
}
12711271
Assertions.assertEquals(0, listeners.size());
1272+
1273+
// without modification check - no listener is added
1274+
iterator = SwingStreamUtils.asIterable(model, SwingStreamUtils.DEFAULT_TREE_TRAVERSAL_TYPE, false).iterator();
1275+
Assertions.assertEquals(0, listeners.size());
12721276
});
12731277
}
12741278
}

0 commit comments

Comments
 (0)