garydgregory commented on a change in pull request #446: LANG-1480 getAbbreviatedName refactored to create appropriate length … URL: https://github.com/apache/commons-lang/pull/446#discussion_r327638147
########## File path: src/test/java/org/apache/commons/lang3/ClassUtilsTest.java ########## @@ -160,26 +162,59 @@ public void test_getAbbreviatedName_Class() { assertEquals("", ClassUtils.getAbbreviatedName((Class<?>) null, 1)); assertEquals("j.l.String", ClassUtils.getAbbreviatedName(String.class, 1)); assertEquals("j.l.String", ClassUtils.getAbbreviatedName(String.class, 5)); + assertEquals("o.a.c.l.ClassUtils", ClassUtils.getAbbreviatedName(ClassUtils.class, 18)); assertEquals("j.lang.String", ClassUtils.getAbbreviatedName(String.class, 13)); assertEquals("j.lang.String", ClassUtils.getAbbreviatedName(String.class, 15)); assertEquals("java.lang.String", ClassUtils.getAbbreviatedName(String.class, 20)); } + /** + * Test that in case the required length is larger than the name and thus there is no need for any shortening + * then the returned string object is the same as the one passed as argument. Note, however, that this is + * tested as an internal implementation detail, but it is not a guaranteed feature of the implementation. + */ @Test - public void test_getAbbreviatedName_Class_NegativeLen() { + @DisplayName("When the length hint is longer than the actual length then the same String object is returned") + void test_getAbbreviatedName_TooLongHint(){ + final String className = "java.lang.String"; + Assertions.assertSame(className, ClassUtils.getAbbreviatedName(className, className.length()+1)); + Assertions.assertSame(className, ClassUtils.getAbbreviatedName(className, className.length())); + } + + @Test + @DisplayName("When the desired length is negative then exception is thrown") + void test_getAbbreviatedName_Class_NegativeLen() { assertThrows(IllegalArgumentException.class, () -> ClassUtils.getAbbreviatedName(String.class, -10)); } @Test - public void test_getAbbreviatedName_Class_ZeroLen() { + @DisplayName("When the desired length is zero then exception is thrown") + void test_getAbbreviatedName_Class_ZeroLen() { assertThrows(IllegalArgumentException.class, () -> ClassUtils.getAbbreviatedName(String.class, 0)); } @Test - public void test_getAbbreviatedName_String() { Review comment: Let's not change the visibility of test classes and methods please. ---------------------------------------------------------------- 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 With regards, Apache Git Services