1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.dromara.streamquery.stream.core.collection.Lists; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.stream.Stream;
class PageUtilTest {
@Test void batchPagingTest() { Page<Object> page = PageUtil.batchFlow(new Page<>(1, 10), (current, size) -> { return new ArrayList<>(); }, list -> i -> false, 100); Assertions.assertTrue(page.getRecords().isEmpty());
Page<Long> page1 = PageUtil.batchFlow(new Page<>(1, 10), (current, size) -> { return Stream.iterate((current - 1) * size + 1, i -> i <= current * size, i -> ++i).toList(); }, list -> i -> i % 2 == 0, -1); Assertions.assertEquals(Lists.of(2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L), page1.getRecords());
Page<Long> page2 = PageUtil.batchFlow(new Page<>(2, 10), (current, size) -> { return Stream.iterate(1L, i -> ++i).limit(9).toList(); }, list -> i -> true, -1); Assertions.assertEquals(19, page2.getTotal()); Assertions.assertEquals(Lists.of(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), page2.getRecords());
}
}
|