ModifierUtil明确注释,并增加hasAllModifiers方法

This commit is contained in:
Looly
2024-09-11 13:18:19 +08:00
parent ca30287f2a
commit 6ebca582f1
3 changed files with 118 additions and 19 deletions

View File

@@ -1,10 +1,12 @@
package cn.hutool.core.util;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ModifierUtilTest {
@Test
@@ -16,6 +18,36 @@ public class ModifierUtilTest {
ModifierUtil.ModifierType.STATIC)
);
}
@Test
public void hasModifierTest2() throws NoSuchMethodException {
Method method = ModifierUtilTest.class.getDeclaredMethod("ddd");
assertTrue(ModifierUtil.hasModifier(method, ModifierUtil.ModifierType.PRIVATE));
assertTrue(ModifierUtil.hasModifier(method,
ModifierUtil.ModifierType.PRIVATE,
ModifierUtil.ModifierType.ABSTRACT)
);
}
@Test
void issueIAQ2U0Test() throws NoSuchMethodException {
final Method method = ModifierUtilTest.class.getDeclaredMethod("ddd");
Assertions.assertTrue(ModifierUtil.hasModifier(method,
ModifierUtil.ModifierType.PRIVATE,
ModifierUtil.ModifierType.STATIC,
// 不存在
ModifierUtil.ModifierType.TRANSIENT
));
Assertions.assertFalse(ModifierUtil.hasAllModifiers(method,
ModifierUtil.ModifierType.PRIVATE,
ModifierUtil.ModifierType.STATIC,
// 不存在
ModifierUtil.ModifierType.TRANSIENT
));
}
private static void ddd() {
}
}