mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 06:08:00 +08:00
add test
This commit is contained in:
parent
858a90c8b7
commit
287800eeab
@ -1,13 +1,5 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.sql.Blob;
|
|
||||||
import java.sql.Clob;
|
|
||||||
import java.sql.RowId;
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
@ -16,6 +8,17 @@ import cn.hutool.core.util.ReflectUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.sql.SqlUtil;
|
import cn.hutool.db.sql.SqlUtil;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.RowId;
|
||||||
|
import java.sql.Time;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据实体对象<br>
|
* 数据实体对象<br>
|
||||||
* 数据实体类充当两个角色:<br>
|
* 数据实体类充当两个角色:<br>
|
||||||
@ -23,12 +26,12 @@ import cn.hutool.db.sql.SqlUtil;
|
|||||||
* 2. SQL条件,Entity中的每一个字段对应一个条件,字段值对应条件的值
|
* 2. SQL条件,Entity中的每一个字段对应一个条件,字段值对应条件的值
|
||||||
*
|
*
|
||||||
* @author loolly
|
* @author loolly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Entity extends Dict {
|
public class Entity extends Dict {
|
||||||
private static final long serialVersionUID = -1951012511464327448L;
|
private static final long serialVersionUID = -1951012511464327448L;
|
||||||
|
|
||||||
// --------------------------------------------------------------- Static method start
|
// --------------------------------------------------------------- Static method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Entity
|
* 创建Entity
|
||||||
*
|
*
|
||||||
@ -117,6 +120,7 @@ public class Entity extends Dict {
|
|||||||
// --------------------------------------------------------------- Constructor end
|
// --------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
// --------------------------------------------------------------- Getters and Setters start
|
// --------------------------------------------------------------- Getters and Setters start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 获得表名
|
* @return 获得表名
|
||||||
*/
|
*/
|
||||||
@ -136,7 +140,6 @@ public class Entity extends Dict {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return 字段集合
|
* @return 字段集合
|
||||||
*/
|
*/
|
||||||
public Set<String> getFieldNames() {
|
public Set<String> getFieldNames() {
|
||||||
@ -187,6 +190,7 @@ public class Entity extends Dict {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------- Getters and Setters end
|
// --------------------------------------------------------------- Getters and Setters end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将值对象转换为Entity<br>
|
* 将值对象转换为Entity<br>
|
||||||
* 类名会被当作表名,小写第一个字母
|
* 类名会被当作表名,小写第一个字母
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
|
import cn.hutool.db.pojo.User;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cn.hutool.db.pojo.User;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity测试
|
* Entity测试
|
||||||
*
|
*
|
||||||
@ -36,6 +35,18 @@ public class EntityTest {
|
|||||||
Assert.assertEquals("user", entity.getTableName());
|
Assert.assertEquals("user", entity.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseTest3() {
|
||||||
|
User user = new User();
|
||||||
|
user.setName("test");
|
||||||
|
|
||||||
|
Entity entity = Entity.create().parseBean(user, false, true);
|
||||||
|
|
||||||
|
Assert.assertFalse(entity.containsKey("id"));
|
||||||
|
Assert.assertEquals("test", entity.getStr("name"));
|
||||||
|
Assert.assertEquals("user", entity.getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityToBeanIgnoreCaseTest() {
|
public void entityToBeanIgnoreCaseTest() {
|
||||||
Entity entity = Entity.create().set("ID", 2).set("NAME", "testName");
|
Entity entity = Entity.create().set("ID", 2).set("NAME", "testName");
|
||||||
|
Loading…
Reference in New Issue
Block a user