|
3 | 3 | import io.swagger.v3.core.converter.AnnotatedType; |
4 | 4 | import org.testng.annotations.Test; |
5 | 5 |
|
6 | | -import java.lang.annotation.Annotation; |
7 | | -import java.lang.annotation.ElementType; |
8 | | -import java.lang.annotation.Retention; |
9 | | -import java.lang.annotation.RetentionPolicy; |
10 | | -import java.lang.annotation.Target; |
| 6 | +import java.lang.annotation.*; |
11 | 7 | import java.lang.reflect.Type; |
12 | 8 | import java.util.HashSet; |
13 | 9 | import java.util.Set; |
@@ -49,20 +45,22 @@ public void testEqualsAndHashCode_shouldBeOrderInsensitiveForAnnotations() { |
49 | 45 | } |
50 | 46 |
|
51 | 47 | /** |
52 | | - * Tests that JDK/internal annotations are filtered out for equals() and hashCode() comparison. |
| 48 | + * Tests that the JDK Deprecated annotation is considered for equals() and hashCode() comparison. |
53 | 49 | */ |
54 | 50 | @Test |
55 | | - public void testEqualsAndHashCode_shouldIgnoreJdkInternalAnnotations() { |
| 51 | + public void testEqualsAndHashCode_shouldIncludeJdkDeprecatedAnnotations() { |
56 | 52 | Annotation annA = getAnnotationInstance(TestAnnA.class); |
57 | 53 | Annotation deprecated = getAnnotationInstance(Deprecated.class); |
58 | 54 | AnnotatedType typeWithUserAnn = new AnnotatedType(String.class).ctxAnnotations(new Annotation[]{annA}); |
59 | | - AnnotatedType typeWithJdkAnn = new AnnotatedType(String.class).ctxAnnotations(new Annotation[]{annA, deprecated}); |
| 55 | + AnnotatedType typeWithJdkAnnAndUserAnn = new AnnotatedType(String.class).ctxAnnotations(new Annotation[]{deprecated, annA}); |
| 56 | + AnnotatedType typeWithUserAnnAndJdkAnn = new AnnotatedType(String.class).ctxAnnotations(new Annotation[]{annA, deprecated}); |
60 | 57 | AnnotatedType typeWithOnlyJdkAnn = new AnnotatedType(String.class).ctxAnnotations(new Annotation[]{deprecated}); |
61 | 58 | AnnotatedType typeWithNoAnn = new AnnotatedType(String.class); |
62 | | - assertEquals(typeWithUserAnn, typeWithJdkAnn, "JDK annotations should be ignored in equality comparison."); |
63 | | - assertEquals(typeWithUserAnn.hashCode(), typeWithJdkAnn.hashCode(), "JDK annotations should be ignored in hashCode calculation."); |
64 | | - assertEquals(typeWithOnlyJdkAnn, typeWithNoAnn, "An object with only JDK annotations should be equal to one with no annotations."); |
65 | | - assertEquals(typeWithOnlyJdkAnn.hashCode(), typeWithNoAnn.hashCode(), "The hash code of an object with only JDK annotations should be the same as one with no annotations."); |
| 59 | + assertNotEquals(typeWithUserAnn, typeWithJdkAnnAndUserAnn, "JDK Deprecated annotation should be included in equality comparison."); |
| 60 | + assertNotEquals(typeWithUserAnn.hashCode(), typeWithJdkAnnAndUserAnn.hashCode(), "JDK Deprecated annotation should be included in hashCode calculation."); |
| 61 | + assertNotEquals(typeWithOnlyJdkAnn, typeWithNoAnn, "An object with only JDK Deprecated annotation should not be equal to one with no annotations."); |
| 62 | + assertNotEquals(typeWithOnlyJdkAnn.hashCode(), typeWithNoAnn.hashCode(), "The hash code of an object with only a JDK Deprecated annotation should not be the same as one with no annotations."); |
| 63 | + assertEquals(typeWithJdkAnnAndUserAnn, typeWithUserAnnAndJdkAnn, "Hash codes should be equal even if annotation order is different."); |
66 | 64 | } |
67 | 65 |
|
68 | 66 | /** |
|
0 commit comments