Sfoglia il codice sorgente

fix(mybatis-plus-generator.main): 提交选择器测试

825944942@qq.com 5 anni fa
parent
commit
0dd84154cd

+ 8 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/select/Branch.java

@@ -8,10 +8,18 @@ import java.util.function.Predicate;
  *
  * @author hanchunlin
  * Created at 2020/6/11 17:19
+ * @see BranchBuilder
  */
 public interface Branch<P, T> {
+
+    /**
+     * @return 分支进入条件
+     */
     Predicate<P> tester();
 
+    /**
+     * @return 值工厂
+     */
     Function<P, T> factory();
 
     static <P, T> Branch<P, T> of(Predicate<P> tester, Function<P, T> factory) {

+ 5 - 0
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/select/Selector.java

@@ -55,4 +55,9 @@ public class Selector<P, T> {
         return or(() -> t);
     }
 
+    @Override
+    public String toString() {
+        return String.format("Selector{success=%s}", success);
+    }
+
 }

+ 33 - 0
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/config/converts/select/SelectorTest.java

@@ -0,0 +1,33 @@
+package com.baomidou.mybatisplus.generator.config.converts.select;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * @author hanchunlin
+ * Created at 2020/6/11 19:43
+ */
+class SelectorTest {
+
+    @Test
+    void test() {
+        assertEquals("1", asString(1));
+        assertEquals("123", asString(4));
+    }
+
+    /**
+     * 将数字转换为字符串
+     *
+     * @param i 数字
+     * @return 返回对应的字符串
+     */
+    private String asString(int i) {
+        Selector<Integer, String> selector = Selector.param(i);
+        return selector.test(BranchBuilder.<Integer, String>of(ii -> ii == 1).then(p -> "1"))
+            .test(BranchBuilder.<Integer, String>of(ii -> ii == 2).then(p -> "2"))
+            .test(BranchBuilder.<Integer, String>of(ii -> ii == 3).then(p -> "3"))
+            .or("123");
+    }
+
+}