|
|
@@ -2,6 +2,7 @@ package cn.hutool.core.collection;
|
|
|
|
|
|
import cn.hutool.core.date.StopWatch;
|
|
|
import cn.hutool.core.lang.Console;
|
|
|
+import cn.hutool.core.util.PageUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Ignore;
|
|
|
@@ -53,4 +54,53 @@ public class ListUtilTest {
|
|
|
final int[] indexArray2 = ListUtil.indexOfAll(a, "1"::equals);
|
|
|
Assert.assertArrayEquals(new int[]{0,6}, indexArray2);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void pageTest(){
|
|
|
+
|
|
|
+
|
|
|
+ List<Integer> a = ListUtil.toLinkedList(1, 2, 3,4,5);
|
|
|
+
|
|
|
+ PageUtil.setFirstPageNo(1);
|
|
|
+ int[] a_1 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] a1 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] a2 = ListUtil.page(2,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] a3 = ListUtil.page(3,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] a4 = ListUtil.page(4,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},a_1);
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},a1);
|
|
|
+ Assert.assertArrayEquals(new int[]{3,4},a2);
|
|
|
+ Assert.assertArrayEquals(new int[]{5},a3);
|
|
|
+ Assert.assertArrayEquals(new int[]{},a4);
|
|
|
+
|
|
|
+
|
|
|
+ PageUtil.setFirstPageNo(2);
|
|
|
+ int[] b_1 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] b1 = ListUtil.page(2,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] b2 = ListUtil.page(3,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] b3 = ListUtil.page(4,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] b4 = ListUtil.page(5,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},b_1);
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},b1);
|
|
|
+ Assert.assertArrayEquals(new int[]{3,4},b2);
|
|
|
+ Assert.assertArrayEquals(new int[]{5},b3);
|
|
|
+ Assert.assertArrayEquals(new int[]{},b4);
|
|
|
+
|
|
|
+ PageUtil.setFirstPageNo(0);
|
|
|
+ int[] c_1 = ListUtil.page(-1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] c1 = ListUtil.page(0,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] c2 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] c3 = ListUtil.page(2,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ int[] c4 = ListUtil.page(3,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},c_1);
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2},c1);
|
|
|
+ Assert.assertArrayEquals(new int[]{3,4},c2);
|
|
|
+ Assert.assertArrayEquals(new int[]{5},c3);
|
|
|
+ Assert.assertArrayEquals(new int[]{},c4);
|
|
|
+
|
|
|
+
|
|
|
+ PageUtil.setFirstPageNo(1);
|
|
|
+ int[] d1 = ListUtil.page(0,8,a).stream().mapToInt(Integer::valueOf).toArray();
|
|
|
+ Assert.assertArrayEquals(new int[]{1,2,3,4,5},d1);
|
|
|
+ }
|
|
|
}
|