Jelajahi Sumber

增加测试

zhou-hao 6 tahun lalu
induk
melakukan
f641c7f20c

+ 5 - 0
hsweb-commons/hsweb-commons-utils/pom.xml

@@ -85,5 +85,10 @@
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
         </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

+ 22 - 2
hsweb-commons/hsweb-commons-utils/src/test/java/org/hswebframework/web/ExpressionUtilsTests.java

@@ -1,9 +1,11 @@
 package org.hswebframework.web;
 
+import lombok.SneakyThrows;
 import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Collections;
+import java.util.Map;
 
 import static org.junit.Assert.*;
 
@@ -11,11 +13,29 @@ public class ExpressionUtilsTests {
 
     @Test
     public void testAnalytical() throws Exception {
-        String result = ExpressionUtils.analytical("test${1+2}", "spel");
+        String result = ExpressionUtils.analytical("test${1+2} ${''} ${1+4+5}", "spel");
 
-        Assert.assertEquals(result, "test3");
+        Assert.assertEquals(result, "test3  10");
 
         result = ExpressionUtils.analytical("test${#param}", Collections.singletonMap("param", "3"), "spel");
         Assert.assertEquals(result, "test3");
     }
+
+    @Test
+    @SneakyThrows
+    public void benchmark() {
+
+        String expression = "test${1+2}  ${1+4+5}";
+
+        ExpressionUtils.analytical(expression, Collections.emptyMap(), "spel");
+
+        long time = System.currentTimeMillis();
+        for (int i = 0; i < 100000; i++) {
+            ExpressionUtils.analytical(expression, Collections.emptyMap(), "spel");
+        }
+
+        System.out.println(System.currentTimeMillis() - time);
+    }
+
+
 }

+ 8 - 0
hsweb-commons/hsweb-commons-utils/src/test/resources/logback.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd"
+               debug="false" scan="true" scanPeriod="30 second">
+    <root level="warn">
+
+    </root>
+</configuration>