修复 CharSequenceUtil.brief 方法字符串越界,以及maxLength部分值时,结果与预期不符的BUG修复

This commit is contained in:
王良
2022-01-05 15:11:09 +08:00
parent cdf105589d
commit 2449716921
2 changed files with 38 additions and 21 deletions

View File

@@ -529,10 +529,18 @@ public class StrUtilTest {
@Test
public void briefTest() {
String str = RandomUtil.randomString(1000);
int maxLength = RandomUtil.randomInt(1000);
String brief = StrUtil.brief(str, maxLength);
Assert.assertEquals(brief.length(), maxLength);
// case: 1 至 str.length - 1
String str = RandomUtil.randomString(RandomUtil.randomInt(1, 100));
for (int maxLength = 1; maxLength < str.length(); maxLength++) {
String brief = StrUtil.brief(str, maxLength);
Assert.assertEquals(brief.length(), maxLength);
}
// case: 不会格式化的值
Assert.assertEquals(str, StrUtil.brief(str, 0));
Assert.assertEquals(str, StrUtil.brief(str, -1));
Assert.assertEquals(str, StrUtil.brief(str, str.length()));
Assert.assertEquals(str, StrUtil.brief(str, str.length() + 1));
}
@Test