mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-31 16:11:50 +08:00
fix bug and add test
This commit is contained in:
parent
514483010e
commit
c58418017e
@ -84,7 +84,7 @@ public class FilterIter<E> implements Iterator<E> {
|
||||
private boolean setNextObject() {
|
||||
while (iterator.hasNext()) {
|
||||
final E object = iterator.next();
|
||||
if (null != filter && filter.test(object)) {
|
||||
if (null == filter || filter.test(object)) {
|
||||
nextObject = object;
|
||||
nextObjectSet = true;
|
||||
return true;
|
||||
|
23
hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java
Executable file
23
hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java
Executable file
@ -0,0 +1,23 @@
|
||||
package cn.hutool.core.collection.iter;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class FilterIterTest {
|
||||
|
||||
@Test
|
||||
public void iterNullTest(){
|
||||
final Iterator<String> it = ListUtil.of("1", "2").iterator();
|
||||
final FilterIter<String> filterIter = new FilterIter<>(it, null);
|
||||
int count = 0;
|
||||
while (filterIter.hasNext()) {
|
||||
if(null != filterIter.next()){
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(2, count);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user