This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
The following commit(s) were added to refs/heads/master by this push:
new 1e8b3cbad Add FilterIteratorTest.testConstructorPredicateFilterInts()
1e8b3cbad is described below
commit 1e8b3cbadcd19acb0554f7aa7cb36197d51579ca
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Oct 29 07:58:29 2024 -0400
Add FilterIteratorTest.testConstructorPredicateFilterInts()
---
.../collections4/iterators/FilterIteratorTest.java | 25 ++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git
a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java
b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java
index 99e6dab4a..f8ef27c6f 100644
---
a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java
+++
b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java
@@ -45,10 +45,12 @@ import org.junit.jupiter.api.Test;
*/
public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
- private String[] array;
+ private static final List<Integer> collectionInts = Arrays.asList(1, 2, 3,
4, 5, 6);
+ private String[] array;
private List<E> list;
private FilterIterator<E> iterator;
+
/** Creates new TestFilterIterator */
public FilterIteratorTest() {
super(FilterIteratorTest.class.getSimpleName());
@@ -123,6 +125,22 @@ public class FilterIteratorTest<E> extends
AbstractIteratorTest<E> {
iterator = null;
}
+ /**
+ * Tests a predicate that accepts some but not all elements.
+ */
+ @Test
+ public void testConstructorPredicateFilterInts() {
+ final List<Integer> expected = Arrays.asList(2, 4, 6);
+ final Predicate<Integer> predicate = i -> i % 2 == 0;
+ final FilterIterator<Integer> filter = new
FilterIterator<>(collectionInts.iterator(), predicate);
+ final List<Integer> actual = new ArrayList<>();
+ filter.forEachRemaining(actual::add);
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * Tests a predicate that accepts everything.
+ */
@Test
public void testForEachRemainingAcceptAllCtor() {
final List<E> expected = IteratorUtils.toList(makeObject());
@@ -142,6 +160,9 @@ public class FilterIteratorTest<E> extends
AbstractIteratorTest<E> {
assertEquals(expected, actual);
}
+ /**
+ * Tests a predicate that rejects everything.
+ */
@Test
public void testForEachRemainingRejectAllCtor() {
final List<E> expected = IteratorUtils.toList(makeObject());
@@ -167,6 +188,7 @@ public class FilterIteratorTest<E> extends
AbstractIteratorTest<E> {
verifyNoMoreElements();
}
+
@Test
public void testReturnValues() {
verifyElementsInPredicate(ArrayUtils.EMPTY_STRING_ARRAY);
@@ -179,7 +201,6 @@ public class FilterIteratorTest<E> extends
AbstractIteratorTest<E> {
verifyElementsInPredicate(new String[] { "a", "b", "c" });
}
-
/**
* Test that when the iterator is changed, the hasNext method returns the
* correct response for the new iterator.