mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
|
||||
/**
|
||||
* 验证器单元测试
|
||||
*
|
||||
@@ -108,13 +106,13 @@ public class ValidatorTest {
|
||||
@Test
|
||||
public void isMatchTest() {
|
||||
String url = "http://aaa-bbb.somthing.com/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url));
|
||||
|
||||
url = "https://aaa-bbb.somthing.com/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url));
|
||||
|
||||
url = "https://aaa-bbb.somthing.com:8080/a.php?a=b&c=2";
|
||||
Assert.assertTrue(Validator.isMactchRegex(PatternPool.URL_HTTP, url));
|
||||
Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -24,8 +24,17 @@ public class IdcardUtilTest {
|
||||
boolean valid15 = IdcardUtil.isValidCard(ID_15);
|
||||
Assert.assertTrue(valid15);
|
||||
|
||||
// 无效
|
||||
String idCard = "360198910283844";
|
||||
Assert.assertFalse(IdcardUtil.isValidCard(idCard));
|
||||
|
||||
// 生日无效
|
||||
idCard = "201511221897205960";
|
||||
Assert.assertFalse(IdcardUtil.isValidCard(idCard));
|
||||
|
||||
// 生日无效
|
||||
idCard = "815727834224151";
|
||||
Assert.assertFalse(IdcardUtil.isValidCard(idCard));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -10,9 +10,8 @@ import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 反射工具类单元测试
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ReflectUtilTest {
|
||||
|
||||
@@ -20,17 +19,17 @@ public class ReflectUtilTest {
|
||||
public void getMethodsTest() {
|
||||
Method[] methods = ReflectUtil.getMethods(ExamInfoDict.class);
|
||||
Assert.assertEquals(22, methods.length);
|
||||
|
||||
|
||||
//过滤器测试
|
||||
methods = ReflectUtil.getMethods(ExamInfoDict.class, t -> Integer.class.equals(t.getReturnType()));
|
||||
|
||||
|
||||
Assert.assertEquals(4, methods.length);
|
||||
final Method method = methods[0];
|
||||
Assert.assertNotNull(method);
|
||||
|
||||
|
||||
//null过滤器测试
|
||||
methods = ReflectUtil.getMethods(ExamInfoDict.class, null);
|
||||
|
||||
|
||||
Assert.assertEquals(22, methods.length);
|
||||
final Method method2 = methods[0];
|
||||
Assert.assertNotNull(method2);
|
||||
@@ -41,22 +40,22 @@ public class ReflectUtilTest {
|
||||
Method method = ReflectUtil.getMethod(ExamInfoDict.class, "getId");
|
||||
Assert.assertEquals("getId", method.getName());
|
||||
Assert.assertEquals(0, method.getParameterTypes().length);
|
||||
|
||||
|
||||
method = ReflectUtil.getMethod(ExamInfoDict.class, "getId", Integer.class);
|
||||
Assert.assertEquals("getId", method.getName());
|
||||
Assert.assertEquals(1, method.getParameterTypes().length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getMethodIgnoreCaseTest() {
|
||||
Method method = ReflectUtil.getMethodIgnoreCase(ExamInfoDict.class, "getId");
|
||||
Assert.assertEquals("getId", method.getName());
|
||||
Assert.assertEquals(0, method.getParameterTypes().length);
|
||||
|
||||
|
||||
method = ReflectUtil.getMethodIgnoreCase(ExamInfoDict.class, "GetId");
|
||||
Assert.assertEquals("getId", method.getName());
|
||||
Assert.assertEquals(0, method.getParameterTypes().length);
|
||||
|
||||
|
||||
method = ReflectUtil.getMethodIgnoreCase(ExamInfoDict.class, "setanswerIs", Integer.class);
|
||||
Assert.assertEquals("setAnswerIs", method.getName());
|
||||
Assert.assertEquals(1, method.getParameterTypes().length);
|
||||
@@ -75,7 +74,7 @@ public class ReflectUtilTest {
|
||||
final Field[] fields = ReflectUtil.getFields(TestSubClass.class);
|
||||
Assert.assertEquals(4, fields.length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setFieldTest() {
|
||||
TestClass testClass = new TestClass();
|
||||
@@ -90,6 +89,13 @@ public class ReflectUtilTest {
|
||||
Assert.assertEquals(10, testClass.getA());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noneStaticInnerClassTest() {
|
||||
final TestAClass testAClass = ReflectUtil.newInstanceIfPossible(TestAClass.class);
|
||||
Assert.assertNotNull(testAClass);
|
||||
Assert.assertEquals(2, testAClass.getA());
|
||||
}
|
||||
|
||||
static class TestClass {
|
||||
private int a;
|
||||
|
||||
@@ -101,4 +107,17 @@ public class ReflectUtilTest {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("InnerClassMayBeStatic")
|
||||
class TestAClass {
|
||||
private int a = 2;
|
||||
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user