mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 14:18:05 +08:00
add test
This commit is contained in:
parent
22187269da
commit
a300a8926e
@ -2,6 +2,11 @@ package cn.hutool.core.comparator;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较工具类
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
*/
|
||||||
public class CompareUtil {
|
public class CompareUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +27,7 @@ public class CompareUtil {
|
|||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public static <T> int compare(T c1, T c2, Comparator<T> comparator) {
|
public static <T> int compare(T c1, T c2, Comparator<T> comparator) {
|
||||||
if (null == comparator) {
|
if (null == comparator) {
|
||||||
return compare((Comparable)c1, (Comparable)c2);
|
return compare((Comparable) c1, (Comparable) c2);
|
||||||
}
|
}
|
||||||
return comparator.compare(c1, c2);
|
return comparator.compare(c1, c2);
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,16 @@ public class BeanUtilTest {
|
|||||||
Assert.assertEquals("sub名字", map.get("aliasSubName"));
|
Assert.assertEquals("sub名字", map.get("aliasSubName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mapToBeanWithAliasTest() {
|
||||||
|
Map<String, Object> 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
|
@Test
|
||||||
public void beanToMapWithLocalDateTimeTest() {
|
public void beanToMapWithLocalDateTimeTest() {
|
||||||
final LocalDateTime now = LocalDateTime.now();
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import java.io.IOException;
|
|||||||
* @author Looly
|
* @author Looly
|
||||||
* @since 5.2.6
|
* @since 5.2.6
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface Action {
|
public interface Action {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,6 @@ public class DocServerTest {
|
|||||||
HttpUtil.createServer(80)
|
HttpUtil.createServer(80)
|
||||||
// 设置默认根目录,
|
// 设置默认根目录,
|
||||||
.setRoot("D:\\workspace\\site\\hutool-site")
|
.setRoot("D:\\workspace\\site\\hutool-site")
|
||||||
// 返回JSON数据测试
|
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
DesktopUtil.browse("http://localhost/");
|
DesktopUtil.browse("http://localhost/");
|
||||||
|
Loading…
Reference in New Issue
Block a user