mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add test
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.hutool.db.meta;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.ds.DSFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -20,25 +21,34 @@ public class MetaUtilTest {
|
||||
|
||||
@Test
|
||||
public void getTablesTest() {
|
||||
List<String> tables = MetaUtil.getTables(ds);
|
||||
final List<String> tables = MetaUtil.getTables(ds);
|
||||
Assert.assertEquals("user", tables.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableMetaTest() {
|
||||
Table table = MetaUtil.getTableMeta(ds, "user");
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user");
|
||||
Assert.assertEquals(CollectionUtil.newHashSet("id"), table.getPkNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnNamesTest() {
|
||||
String[] names = MetaUtil.getColumnNames(ds, "user");
|
||||
final String[] names = MetaUtil.getColumnNames(ds, "user");
|
||||
Assert.assertArrayEquals(StrUtil.splitToArray("id,name,age,birthday,gender", ','), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableIndexInfoTest() {
|
||||
Table table = MetaUtil.getTableMeta(ds, "user_1");
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user_1");
|
||||
Assert.assertEquals(table.getIndexInfoList().size(), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表不存在抛出异常。
|
||||
*/
|
||||
@Test(expected = DbRuntimeException.class)
|
||||
public void getTableNotExistTest() {
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user_not_exist");
|
||||
Assert.assertEquals(table.getIndexInfoList().size(), 2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user