[ https://issues.apache.org/jira/browse/LANG-1480?focusedWorklogId=300781&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-300781 ]
ASF GitHub Bot logged work on LANG-1480: ---------------------------------------- Author: ASF GitHub Bot Created on: 24/Aug/19 23:48 Start Date: 24/Aug/19 23:48 Worklog Time Spent: 10m Work Description: kinow commented on pull request #446: LANG-1480 getAbbreviatedName refactored to create appropriate length … URL: https://github.com/apache/commons-lang/pull/446#discussion_r317377567 ########## File path: src/test/java/org/apache/commons/lang3/ClassUtilsTest.java ########## @@ -178,8 +179,22 @@ public void test_getAbbreviatedName_Class_ZeroLen() { @Test public void test_getAbbreviatedName_String() { assertEquals("", ClassUtils.getAbbreviatedName((String) null, 1)); + assertEquals("", ClassUtils.getAbbreviatedName("", 1)); assertEquals("WithoutPackage", ClassUtils.getAbbreviatedName("WithoutPackage", 1)); assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", 1)); + assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("org.apache.commons.lang3.ClassUtils", 18)); + assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName("o.a.c.l.ClassUtils", 18)); + assertEquals("o..c.l.ClassUtils", ClassUtils.getAbbreviatedName("o..c.l.ClassUtils", 18)); + assertEquals(".", ClassUtils.getAbbreviatedName(".", 18)); + assertEquals(".", ClassUtils.getAbbreviatedName(".", 1)); + assertEquals("..", ClassUtils.getAbbreviatedName("..", 1)); + assertEquals("...", ClassUtils.getAbbreviatedName("...", 2)); + assertEquals("...", ClassUtils.getAbbreviatedName("...", 3)); + assertEquals("java.lang.String", ClassUtils.getAbbreviatedName("java.lang.String", Integer.MAX_VALUE)); + assertEquals("j.lang.String", ClassUtils.getAbbreviatedName("java.lang.String", "j.lang.String".length())); + assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", "j.lang.String".length() - 1)); + assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", "j.l.String".length())); + assertEquals("j.l.String", ClassUtils.getAbbreviatedName("java.lang.String", "j.l.String".length() - 1)); Review comment: I think you are not testing the bug you found? There is no test for a call to `getAbbreviatedName` with class name as a `String`, and length as the exact length of that `String`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 300781) Remaining Estimate: 23.5h (was: 23h 40m) Time Spent: 0.5h (was: 20m) > ClassUtils. getAbbreviatedName(String ,int) returns too long result > ------------------------------------------------------------------- > > Key: LANG-1480 > URL: https://issues.apache.org/jira/browse/LANG-1480 > Project: Commons Lang > Issue Type: Bug > Components: lang.* > Affects Versions: 3.9 > Environment: Environment independent. > Reporter: Peter Verhas > Priority: Major > Original Estimate: 24h > Time Spent: 0.5h > Remaining Estimate: 23.5h > > In some cases, the algorithm decides incorrectly when to which package names > to abbreviate. For example, abbreviating > {{org.apache.commons.lang3.ClassUtils}} to the length 18 will result > {{o.a.c.lang3.ClassUtils}} (22 characters) instead of {{o.a.c.l.ClassUtils}} > (18 characters as requested). The reason for this is that the algorithm > starts from the right and goes to the left abbreviating the packages and > starts to abbreviate the packages when it runs out of the available space. > Instead, the algorithm should start from the left and abbreviate all packages > that would result in a too-long string without abbreviating the package name. -- This message was sent by Atlassian Jira (v8.3.2#803003)