浏览代码

添加批量异常捕获测试

hubin 5 年之前
父节点
当前提交
4636b5dd8f
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserTest.java

+ 14 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2UserTest.java

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
 import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
 import net.sf.jsqlparser.parser.CCJSqlParserUtil;
 import net.sf.jsqlparser.statement.select.Select;
+import org.apache.ibatis.exceptions.PersistenceException;
 import org.junit.jupiter.api.*;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -342,6 +343,19 @@ class H2UserTest extends BaseTest {
     }
 
 
+    @Test
+    @Order(28)
+    void testSaveBatchException() {
+        try {
+            userService.saveBatch(Arrays.asList(
+                new H2User(1L, "tom"),
+                new H2User(1L, "andy")
+            ));
+        } catch (Exception e) {
+            Assertions.assertTrue(e instanceof PersistenceException);
+        }
+    }
+
     @Test
     public void myQueryWithGroupByOrderBy(){
         userService.mySelectMaps().forEach(System.out::println);