diff --git a/hutool-core/src/main/java/cn/hutool/core/comparator/CompareUtil.java b/hutool-core/src/main/java/cn/hutool/core/comparator/CompareUtil.java index 3795eec52..c592e7a30 100644 --- a/hutool-core/src/main/java/cn/hutool/core/comparator/CompareUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/comparator/CompareUtil.java @@ -2,6 +2,11 @@ package cn.hutool.core.comparator; import java.util.Comparator; +/** + * 比较工具类 + * + * @author looly + */ public class CompareUtil { /** @@ -22,7 +27,7 @@ public class CompareUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static int compare(T c1, T c2, Comparator comparator) { if (null == comparator) { - return compare((Comparable)c1, (Comparable)c2); + return compare((Comparable) c1, (Comparable) c2); } return comparator.compare(c1, c2); } diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java index 360051230..16112e51d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java @@ -156,6 +156,16 @@ public class BeanUtilTest { Assert.assertEquals("sub名字", map.get("aliasSubName")); } + @Test + public void mapToBeanWithAliasTest() { + Map map = MapUtil.newHashMap(); + map.put("aliasSubName", "sub名字"); + map.put("slow", true); + + final SubPersonWithAlias subPersonWithAlias = BeanUtil.mapToBean(map, SubPersonWithAlias.class, false); + Assert.assertEquals("sub名字", subPersonWithAlias.getSubName()); + } + @Test public void beanToMapWithLocalDateTimeTest() { final LocalDateTime now = LocalDateTime.now(); diff --git a/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java new file mode 100644 index 000000000..b1378be80 --- /dev/null +++ b/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java @@ -0,0 +1,16 @@ +package cn.hutool.core.comparator; + +import org.junit.Assert; +import org.junit.Test; + +public class CompareUtilTest { + + @Test + public void compareTest(){ + int compare = CompareUtil.compare(null, "a", true); + Assert.assertTrue(compare > 0); + + compare = CompareUtil.compare(null, "a", false); + Assert.assertTrue(compare < 0); + } +} diff --git a/hutool-http/src/main/java/cn/hutool/http/server/action/Action.java b/hutool-http/src/main/java/cn/hutool/http/server/action/Action.java index a905fd5df..73b69058e 100644 --- a/hutool-http/src/main/java/cn/hutool/http/server/action/Action.java +++ b/hutool-http/src/main/java/cn/hutool/http/server/action/Action.java @@ -12,6 +12,7 @@ import java.io.IOException; * @author Looly * @since 5.2.6 */ +@FunctionalInterface public interface Action { /** diff --git a/hutool-http/src/test/java/cn/hutool/http/server/BlankServerTest.java b/hutool-http/src/test/java/cn/hutool/http/server/BlankServerTest.java new file mode 100644 index 000000000..b5819778e --- /dev/null +++ b/hutool-http/src/test/java/cn/hutool/http/server/BlankServerTest.java @@ -0,0 +1,13 @@ +package cn.hutool.http.server; + +import cn.hutool.http.HttpUtil; + +public class BlankServerTest { + public static void main(String[] args) { + HttpUtil.createServer(8888) + .addAction("/", (req, res)->{ + res.write("Hello Hutool Server"); + }) + .start(); + } +} diff --git a/hutool-http/src/test/java/cn/hutool/http/server/DocServerTest.java b/hutool-http/src/test/java/cn/hutool/http/server/DocServerTest.java index 198af98c6..e5685e2bc 100644 --- a/hutool-http/src/test/java/cn/hutool/http/server/DocServerTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/server/DocServerTest.java @@ -9,7 +9,6 @@ public class DocServerTest { HttpUtil.createServer(80) // 设置默认根目录, .setRoot("D:\\workspace\\site\\hutool-site") - // 返回JSON数据测试 .start(); DesktopUtil.browse("http://localhost/"); diff --git a/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java b/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java index ddf9082ab..2c325eec1 100644 --- a/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/server/SimpleServerTest.java @@ -23,11 +23,11 @@ public class SimpleServerTest { // 文件上传测试 // http://localhost:8888/formTest?a=1&a=2&b=3 .addAction("/file", (request, response) -> { - final UploadFile file = request.getMultipart().getFile("file"); - // 传入目录,默认读取HTTP头中的文件名然后创建文件 - file.write("d:/test/"); - Console.log("Write file to: d:/test/"); - response.write(request.getParams().toString(), ContentType.TEXT_PLAIN.toString()); + final UploadFile file = request.getMultipart().getFile("file"); + // 传入目录,默认读取HTTP头中的文件名然后创建文件 + file.write("d:/test/"); + Console.log("Write file to: d:/test/"); + response.write(request.getParams().toString(), ContentType.TEXT_PLAIN.toString()); } ) .start();