fix brief bug

This commit is contained in:
Looly
2020-06-23 18:02:38 +08:00
parent e0e07c726f
commit 8bb47018e6
3 changed files with 12 additions and 4 deletions

View File

@@ -3312,11 +3312,11 @@ public class StrUtil {
if (null == str) {
return null;
}
if ((str.length() + 3) <= maxLength) {
if (str.length() <= maxLength) {
return str.toString();
}
int w = maxLength / 2;
int l = str.length();
int l = str.length() + 3;
final String str2 = str.toString();
return format("{}...{}", str2.substring(0, maxLength - w), str2.substring(l - w));

View File

@@ -448,5 +448,12 @@ public class StrUtilTest {
String[] results2 = StrUtil.subBetweenAll(src2,"/*","*/");
Assert.assertEquals(0, results2.length);
}
@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);
}
}