Browse Source

自定义分页偏移值测试用例.

聂秋秋 5 years ago
parent
commit
0f183e6259

+ 18 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/CacheTest.java

@@ -3,13 +3,11 @@ package com.baomidou.mybatisplus.test.h2.cache;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
-import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.test.h2.cache.mapper.CacheMapper;
 import com.baomidou.mybatisplus.test.h2.cache.model.CacheModel;
 import com.baomidou.mybatisplus.test.h2.cache.service.ICacheService;
 import org.apache.ibatis.cache.Cache;
-import org.apache.ibatis.cache.CacheKey;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.junit.jupiter.api.*;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -206,6 +204,24 @@ class CacheTest {
         Assertions.assertEquals(5, cache.getSize());
     }
     
+    @Test
+    void testCustomOffset(){
+        Cache cache = getCache();
+        cache.clear();
+        CustomPage<CacheModel> page1 = new CustomPage<>(2, 10, false);
+        Assertions.assertEquals(cache.getSize(), 0);
+        cacheService.page(page1);
+        Assertions.assertEquals(cache.getSize(), 1);
+        cacheService.page(page1);
+        Assertions.assertEquals(cache.getSize(), 1);
+        //页数其他条件不变,改变分页偏移量的骚操作.
+        page1.setOffset(12L);
+        cacheService.page(page1);
+        Assertions.assertEquals(cache.getSize(), 2);
+        cacheService.page(page1);
+        Assertions.assertEquals(cache.getSize(), 2);
+    }
+    
     private Cache getCache() {
         return sqlSessionFactory.getConfiguration().getCache(CacheMapper.class.getName());
     }

+ 40 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/CustomPage.java

@@ -0,0 +1,40 @@
+package com.baomidou.mybatisplus.test.h2.cache;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @author nieqiurong 2020/4/27.
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class CustomPage<T> extends Page<T> {
+    
+    private long offset;
+    
+    public CustomPage() {
+    }
+    
+    public CustomPage(long current, long size) {
+        super(current, size);
+    }
+    
+    public CustomPage(long current, long size, long total) {
+        super(current, size, total);
+    }
+    
+    public CustomPage(long current, long size, boolean isSearchCount) {
+        super(current, size, isSearchCount);
+    }
+    
+    public CustomPage(long current, long size, long total, boolean isSearchCount) {
+        super(current, size, total, isSearchCount);
+    }
+    
+    @Override
+    public long offset() {
+        return offset == 0 ? super.offset() : offset;
+    }
+    
+}