Browse Source

Use custom annotation for checking

This fixes problems with Object#finalize having Deprecated in some JDK
version and not in others.
master
Paweł Płazieński 2 months ago
parent
commit
4b926c0f02
3 changed files with 14 additions and 14 deletions
  1. +9
    -9
      src/test/java/org/perfectable/introspection/query/MethodQueryTest.java
  2. +2
    -2
      src/test/java/org/perfectable/introspection/query/Subject.java
  3. +3
    -3
      src/test/java/org/perfectable/introspection/query/SubjectReflection.java

+ 9
- 9
src/test/java/org/perfectable/introspection/query/MethodQueryTest.java View File

@@ -42,7 +42,7 @@ class MethodQueryTest {
SubjectReflection.WITH_RESULT_NO_ARGUMENT, SubjectReflection.WITH_RESULT_SINGLE_ARGUMENT,
SubjectReflection.WITH_RESULT_DOUBLE_ARGUMENT, SubjectReflection.WITH_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT,
SubjectReflection.ANNOTATED_WITH_DEPRECATED,
SubjectReflection.ANNOTATED_METHOD,
SubjectReflection.TO_STRING,
ObjectMethods.EQUALS, ObjectMethods.HASH_CODE,
ObjectMethods.GET_CLASS,
@@ -150,7 +150,7 @@ class MethodQueryTest {
.containsExactly(
SubjectReflection.WITH_RESULT_NO_ARGUMENT, SubjectReflection.WITH_RESULT_SINGLE_ARGUMENT,
SubjectReflection.WITH_RESULT_DOUBLE_ARGUMENT, SubjectReflection.WITH_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT, SubjectReflection.ANNOTATED_WITH_DEPRECATED,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT, SubjectReflection.ANNOTATED_METHOD,
SubjectReflection.TO_STRING,
ObjectMethods.CLONE, ObjectMethods.TO_STRING,
ObjectMethods.GET_CLASS)
@@ -167,7 +167,7 @@ class MethodQueryTest {
.containsExactly(
SubjectReflection.WITH_RESULT_NO_ARGUMENT, SubjectReflection.WITH_RESULT_SINGLE_ARGUMENT,
SubjectReflection.WITH_RESULT_DOUBLE_ARGUMENT, SubjectReflection.WITH_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT, SubjectReflection.ANNOTATED_WITH_DEPRECATED,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT, SubjectReflection.ANNOTATED_METHOD,
ObjectMethods.CLONE)
.doesNotContain(EXAMPLE_STRING, null, SubjectReflection.NO_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.STATIC_FIELD);
@@ -233,7 +233,7 @@ class MethodQueryTest {
SubjectReflection.WITH_RESULT_NO_ARGUMENT, SubjectReflection.WITH_RESULT_SINGLE_ARGUMENT,
SubjectReflection.WITH_RESULT_DOUBLE_ARGUMENT, SubjectReflection.WITH_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT,
SubjectReflection.ANNOTATED_WITH_DEPRECATED,
SubjectReflection.ANNOTATED_METHOD,
SubjectReflection.TO_STRING,
ObjectMethods.EQUALS, ObjectMethods.HASH_CODE,
ObjectMethods.GET_CLASS,
@@ -269,7 +269,7 @@ class MethodQueryTest {
SubjectReflection.WITH_RESULT_NO_ARGUMENT, SubjectReflection.WITH_RESULT_SINGLE_ARGUMENT,
SubjectReflection.WITH_RESULT_DOUBLE_ARGUMENT, SubjectReflection.WITH_RESULT_TRIPLE_ARGUMENT,
SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT,
SubjectReflection.ANNOTATED_WITH_DEPRECATED,
SubjectReflection.ANNOTATED_METHOD,
SubjectReflection.TO_STRING,
ObjectMethods.EQUALS, ObjectMethods.HASH_CODE,
ObjectMethods.GET_CLASS,
@@ -284,11 +284,11 @@ class MethodQueryTest {
@Test
void testAnnotatedWithClass() {
MethodQuery extracted =
MethodQuery.of(Subject.class).annotatedWith(Deprecated.class);
MethodQuery.of(Subject.class).annotatedWith(Subject.OtherAnnotation.class);

assertThat(extracted)
.filteredOn(JACOCO_EXCLUSION)
.containsExactly(SubjectReflection.ANNOTATED_WITH_DEPRECATED)
.containsExactly(SubjectReflection.ANNOTATED_METHOD)
.doesNotContain(EXAMPLE_STRING, null, SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT,
SubjectReflection.STATIC_FIELD);
}
@@ -296,11 +296,11 @@ class MethodQueryTest {
@Test
void testAnnotatedWith() {
MethodQuery extracted =
MethodQuery.of(Subject.class).annotatedWith(AnnotationFilter.single(Deprecated.class));
MethodQuery.of(Subject.class).annotatedWith(AnnotationFilter.single(Subject.OtherAnnotation.class));

assertThat(extracted)
.filteredOn(JACOCO_EXCLUSION)
.contains(SubjectReflection.ANNOTATED_WITH_DEPRECATED)
.contains(SubjectReflection.ANNOTATED_METHOD)
.doesNotContain(EXAMPLE_STRING, null, SubjectReflection.WITH_RESULT_VARARGS_ARGUMENT,
SubjectReflection.STATIC_FIELD);
}


+ 2
- 2
src/test/java/org/perfectable/introspection/query/Subject.java View File

@@ -133,8 +133,8 @@ public class Subject {
throw new AssertionError(MESSAGE_METHOD_CALLED);
}

@Deprecated
public Object annotatedWithDeprecated() {
@OtherAnnotation
public Object annotatedMethod() {
throw new AssertionError(MESSAGE_METHOD_CALLED);
}



+ 3
- 3
src/test/java/org/perfectable/introspection/query/SubjectReflection.java View File

@@ -70,8 +70,8 @@ public final class SubjectReflection {
getMethod(Subject.class, "methodPackage"); // SUPPRESS MultipleStringLiterals
public static final Method METHOD_PRIVATE =
getMethod(Subject.class, "methodPrivate"); // SUPPRESS MultipleStringLiterals
public static final Method ANNOTATED_WITH_DEPRECATED =
getMethod(Subject.class, "annotatedWithDeprecated");
public static final Method ANNOTATED_METHOD =
getMethod(Subject.class, "annotatedMethod");
public static final Method TO_STRING =
getMethod(Subject.class, "toString");

@@ -89,7 +89,7 @@ public final class SubjectReflection {
Subject.class.getDeclaredAnnotationsByType(Subject.Repetition.class);
@SuppressWarnings("assignment.type.incompatible")
static final Nullable INSTANCE_NULLABLE =
SubjectReflection.ANNOTATED_WITH_DEPRECATED.getAnnotation(Nullable.class);
SubjectReflection.ANNOTATED_METHOD.getAnnotation(Nullable.class);

private SubjectReflection() {
// utility class


Loading…
Cancel
Save