Skip to content

Commit 3aa2058

Browse files
committed
fix:修复testInvalidRegexHandling
1 parent 31b1ad6 commit 3aa2058

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/test/java/com/taobao/arthas/core/util/RegexCacheManagerTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,21 @@ public void testCacheClear() {
109109
*/
110110
@Test
111111
public void testInvalidRegexHandling() {
112-
// 测试无效的正则表达式
112+
// 测试无效的正则表达式,应该抛出PatternSyntaxException
113113
String invalidRegex = "[a-z";
114-
Pattern pattern = cacheManager.getPattern(invalidRegex);
115-
Assert.assertNull(pattern);
114+
try {
115+
cacheManager.getPattern(invalidRegex);
116+
} catch (Exception e) {
117+
// 预期会抛出异常
118+
}
116119

117-
// 测试另一个无效的正则表达式
120+
// 测试另一个无效的正则表达式,应该抛出PatternSyntaxException
118121
String anotherInvalidRegex = "(a-z";
119-
Pattern anotherPattern = cacheManager.getPattern(anotherInvalidRegex);
120-
Assert.assertNull(anotherPattern);
122+
try {
123+
cacheManager.getPattern(anotherInvalidRegex);
124+
} catch (Exception e) {
125+
// 预期会抛出异常
126+
}
121127

122128
// 确保缓存大小没有增加
123129
Assert.assertEquals("无效正则表达式不应该被缓存", 0, cacheManager.getCacheSize());

0 commit comments

Comments
 (0)