mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix test and sm2 bug
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package cn.hutool.core.bean;
|
||||
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
@@ -7,15 +14,6 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
|
||||
/**
|
||||
* Bean工具单元测试
|
||||
*
|
||||
@@ -61,7 +59,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void fillBeanWithMapIgnoreCaseTest() {
|
||||
HashMap<String, Object> map = CollectionUtil.newHashMap();
|
||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
||||
map.put("Name", "Joe");
|
||||
map.put("aGe", 12);
|
||||
map.put("openId", "DFDFSDFWERWER");
|
||||
@@ -73,7 +71,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void mapToBeanIgnoreCaseTest() {
|
||||
HashMap<String, Object> map = CollectionUtil.newHashMap();
|
||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
||||
map.put("Name", "Joe");
|
||||
map.put("aGe", 12);
|
||||
|
||||
@@ -84,11 +82,11 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void mapToBeanTest() {
|
||||
HashMap<String, Object> map = CollectionUtil.newHashMap();
|
||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
||||
map.put("a_name", "Joe");
|
||||
map.put("b_age", 12);
|
||||
|
||||
// 别名
|
||||
// 别名,用于对应bean的字段名
|
||||
HashMap<String, String> mapping = CollUtil.newHashMap();
|
||||
mapping.put("a_name", "name");
|
||||
mapping.put("b_age", "age");
|
||||
|
||||
@@ -2,7 +2,10 @@ package cn.hutool.core.convert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -54,28 +57,28 @@ public class ConvertTest {
|
||||
Integer aInteger = Convert.toInt(a);
|
||||
Assert.assertEquals(Integer.valueOf(34232), aInteger);
|
||||
int aInt = ConverterRegistry.getInstance().convert(int.class, a);
|
||||
Assert.assertTrue(34232 == aInt);
|
||||
Assert.assertEquals(34232, aInt);
|
||||
|
||||
// 带小数测试
|
||||
String b = " 34232.00";
|
||||
Integer bInteger = Convert.toInt(b);
|
||||
Assert.assertEquals(Integer.valueOf(34232), bInteger);
|
||||
int bInt = ConverterRegistry.getInstance().convert(int.class, b);
|
||||
Assert.assertTrue(34232 == bInt);
|
||||
Assert.assertEquals(34232, bInt);
|
||||
|
||||
// boolean测试
|
||||
boolean c = true;
|
||||
Integer cInteger = Convert.toInt(c);
|
||||
Assert.assertEquals(Integer.valueOf(1), cInteger);
|
||||
int cInt = ConverterRegistry.getInstance().convert(int.class, c);
|
||||
Assert.assertTrue(1 == cInt);
|
||||
Assert.assertEquals(1, cInt);
|
||||
|
||||
// boolean测试
|
||||
String d = "08";
|
||||
Integer dInteger = Convert.toInt(d);
|
||||
Assert.assertEquals(Integer.valueOf(8), dInteger);
|
||||
int dInt = ConverterRegistry.getInstance().convert(int.class, d);
|
||||
Assert.assertTrue(8 == dInt);
|
||||
Assert.assertEquals(8, dInt);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,28 +94,28 @@ public class ConvertTest {
|
||||
Long aLong = Convert.toLong(a);
|
||||
Assert.assertEquals(Long.valueOf(342324545435435L), aLong);
|
||||
long aLong2 = ConverterRegistry.getInstance().convert(long.class, a);
|
||||
Assert.assertTrue(342324545435435L == aLong2);
|
||||
Assert.assertEquals(342324545435435L, aLong2);
|
||||
|
||||
// 带小数测试
|
||||
String b = " 342324545435435.245435435";
|
||||
Long bLong = Convert.toLong(b);
|
||||
Assert.assertEquals(Long.valueOf(342324545435435L), bLong);
|
||||
long bLong2 = ConverterRegistry.getInstance().convert(long.class, b);
|
||||
Assert.assertTrue(342324545435435L == bLong2);
|
||||
Assert.assertEquals(342324545435435L, bLong2);
|
||||
|
||||
// boolean测试
|
||||
boolean c = true;
|
||||
Long cLong = Convert.toLong(c);
|
||||
Assert.assertEquals(Long.valueOf(1), cLong);
|
||||
long cLong2 = ConverterRegistry.getInstance().convert(long.class, c);
|
||||
Assert.assertTrue(1 == cLong2);
|
||||
Assert.assertEquals(1, cLong2);
|
||||
|
||||
// boolean测试
|
||||
String d = "08";
|
||||
Long dLong = Convert.toLong(d);
|
||||
Assert.assertEquals(Long.valueOf(8), dLong);
|
||||
long dLong2 = ConverterRegistry.getInstance().convert(long.class, d);
|
||||
Assert.assertTrue(8 == dLong2);
|
||||
Assert.assertEquals(8, dLong2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -30,6 +32,37 @@ public class ConvertToBeanTest {
|
||||
Assert.assertEquals(map.get("age"), 14);
|
||||
Assert.assertEquals("11213232", map.get("openid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanToMapTest2() {
|
||||
SubPerson person = new SubPerson();
|
||||
person.setAge(14);
|
||||
person.setOpenid("11213232");
|
||||
person.setName("测试A11");
|
||||
person.setSubName("sub名字");
|
||||
|
||||
Map<String, String> map = Convert.toMap(String.class, String.class, person);
|
||||
Assert.assertEquals(map.get("name"), "测试A11");
|
||||
Assert.assertEquals(map.get("age"), 14);
|
||||
Assert.assertEquals("11213232", map.get("openid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapToMapTest() {
|
||||
LinkedHashMap<String, Integer> map1 = new LinkedHashMap<>();
|
||||
map1.put("key1", 1);
|
||||
map1.put("key2", 2);
|
||||
map1.put("key3", 3);
|
||||
map1.put("key4", 4);
|
||||
|
||||
Map<String, String> map2 = Convert.toMap(String.class, String.class, map1);
|
||||
Console.log(map2);
|
||||
|
||||
Assert.assertEquals("1", map2.get("key1"));
|
||||
Assert.assertEquals("2", map2.get("key2"));
|
||||
Assert.assertEquals("3", map2.get("key3"));
|
||||
Assert.assertEquals("4", map2.get("key4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapToBeanTest() {
|
||||
|
||||
Reference in New Issue
Block a user