mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug and add test
This commit is contained in:
@@ -84,7 +84,7 @@ public class FilterIter<E> implements Iterator<E> {
|
|||||||
private boolean setNextObject() {
|
private boolean setNextObject() {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E object = iterator.next();
|
final E object = iterator.next();
|
||||||
if (null != filter && filter.test(object)) {
|
if (null == filter || filter.test(object)) {
|
||||||
nextObject = object;
|
nextObject = object;
|
||||||
nextObjectSet = true;
|
nextObjectSet = true;
|
||||||
return 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user