Ver código fonte

修复PageListIterator的bug

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 2 anos atrás
pai
commit
a7fa558c12

+ 1 - 1
tools-common/src/main/java/com/qmth/boot/tools/iterator/PageListIterator.java

@@ -27,7 +27,7 @@ public abstract class PageListIterator<E> implements Iterator<E> {
         if (pageSize <= 0) {
         if (pageSize <= 0) {
             throw new IllegalArgumentException("Iterator pageSize should greater than 0");
             throw new IllegalArgumentException("Iterator pageSize should greater than 0");
         }
         }
-        this.pageNumber = 1;
+        this.pageNumber = 0;
         this.pageSize = pageSize;
         this.pageSize = pageSize;
         this.finish = false;
         this.finish = false;
         this.dataList = new LinkedList<>();
         this.dataList = new LinkedList<>();

+ 27 - 0
tools-common/src/test/java/com/qmth/boot/test/tools/iterator/PageListIteratorTest.java

@@ -0,0 +1,27 @@
+package com.qmth.boot.test.tools.iterator;
+
+import com.qmth.boot.tools.iterator.PageListIterator;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class PageListIteratorTest {
+
+    @Test
+    public void test() {
+        PageListIterator<Integer> iterator = new PageListIterator<Integer>(1) {
+
+            @Override
+            public Collection<Integer> getPageList(int pageNumber, int pageSize) {
+                return Collections.singletonList(pageNumber);
+            }
+        };
+        for (int i = 1; i <= 10; i++) {
+            Assert.assertTrue(iterator.hasNext());
+            Assert.assertEquals((int) iterator.next(), i);
+        }
+    }
+
+}