Copilot commented on code in PR #1810:
URL: https://github.com/apache/commons-lang/pull/1810#discussion_r4230388843
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -470,6 +526,24 @@ void testHashCode() {
});
}
+ @Test
+ void testHashCodeWithFunction() {
+ final FunctionAnnotation annotation =
AnnotatedClass.class.getAnnotation(FunctionAnnotation.class);
+ assertEquals(annotation.hashCode(),
AnnotationUtils.hashCode(annotation));
+ }
+
+ @Test
+ void testHashCodeWithRunnable() {
+ final RunnableAnnotation annotation =
AnnotatedClass.class.getAnnotation(RunnableAnnotation.class);
+ assertEquals(annotation.hashCode(),
AnnotationUtils.hashCode(annotation));
+ }
+
+ @Test
+ void testHashCodeWithSupplier() {
+ final SupplierAnnotation annotation =
AnnotatedClass.class.getAnnotation(SupplierAnnotation.class);
+ assertEquals(annotation.hashCode(),
AnnotationUtils.hashCode(annotation));
+ }
Review Comment:
The regression tests for `hashCode()` don’t currently prove that synthetic
lambda-body methods are *not* invoked, because the lambdas used here are
non-throwing. To make this a true regression guard for LANG-1835, add a
`hashCode` test using `ThrowingSupplierAnnotation` (or a throwing `Runnable`)
and assert `AnnotationUtils.hashCode(annotation)` completes without triggering
the `AssertionError`.
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -519,4 +593,16 @@ void testToString() {
});
}
+ @Test
+ void testToStringWithRunnable() {
+ final RunnableAnnotation annotation =
AnnotatedClass.class.getAnnotation(RunnableAnnotation.class);
+ assertEquals("@" + RunnableAnnotation.class.getName() +
"(value=member)", AnnotationUtils.toString(annotation));
+ }
+
+ @Test
+ void testToStringWithSupplier() {
+ final SupplierAnnotation annotation =
AnnotatedClass.class.getAnnotation(SupplierAnnotation.class);
+ assertEquals("@" + SupplierAnnotation.class.getName() +
"(value=member)", AnnotationUtils.toString(annotation));
+ }
+
Review Comment:
Similar to `hashCode`, the `toString()` regressions here don’t validate the
“don’t execute lambda bodies” requirement since the lambdas are harmless.
Consider adding a `toString` test using `ThrowingSupplierAnnotation` and assert
`AnnotationUtils.toString(annotation)` returns the expected value string
without throwing, which would directly catch a regression where synthetic
methods are invoked.
--
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]