Copilot commented on code in PR #1818:
URL: https://github.com/apache/commons-lang/pull/1818#discussion_r4272406021
##########
src/test/java/org/apache/commons/lang3/ClassUtilsTest.java:
##########
@@ -1633,4 +1633,24 @@ void testWrapperToPrimitiveNoWrapper() {
void testWrapperToPrimitiveNull() {
assertNull(ClassUtils.wrapperToPrimitive(null), "Wrong result for null
class");
}
+
+ @Test
+ void test_getShortClassName_Class_nestedInAnonymousOrLocalClass() {
+ // The declaring class chain of a member class nested in an anonymous
or local class cannot
+ // see past the anonymous/local enclosure, so the name-based form must
be used for the whole
+ // chain, matching getShortClassName(Class.getName()).
+ final Class<?> memberOfAnonymous = new Object() {
+ class Inner {
+ // empty
+ }
+ }.getClass().getDeclaredClasses()[0];
Review Comment:
`getDeclaredClasses()[0]` relies on an unspecified ordering of
`Class#getDeclaredClasses()`, which can make the test brittle across
JVMs/toolchains. Prefer selecting the nested class by name (e.g., filter for
simple name `Inner`) or asserting exactly one declared class before indexing,
so the test fails with a clear message if the assumption changes.
##########
src/test/java/org/apache/commons/lang3/ClassUtilsTest.java:
##########
@@ -1633,4 +1633,24 @@ void testWrapperToPrimitiveNoWrapper() {
void testWrapperToPrimitiveNull() {
assertNull(ClassUtils.wrapperToPrimitive(null), "Wrong result for null
class");
}
+
+ @Test
+ void test_getShortClassName_Class_nestedInAnonymousOrLocalClass() {
Review Comment:
The newly added test method name uses underscores, which is commonly
inconsistent with JUnit-style camelCase naming used in many parts of Commons
Lang tests. Consider renaming to match the predominant convention in this test
class (e.g., `testGetShortClassNameClassNestedInAnonymousOrLocalClass`) to keep
test discovery/readability consistent.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]