-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inherited test methods don't support their annotations (fixes #1032) #1033
base: main
Are you sure you want to change the base?
Inherited test methods don't support their annotations (fixes #1032) #1033
Conversation
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
public final class ReflectionUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add javadoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add tests
import java.util.stream.Stream; | ||
|
||
public final class ReflectionUtils { | ||
private ReflectionUtils() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add throw new IllegalStateException("Do not instance");
@@ -116,7 +117,7 @@ public static Set<Link> getLinks(final Collection<Annotation> annotations) { | |||
* @return discovered labels. | |||
*/ | |||
public static Set<Label> getLabels(final AnnotatedElement annotatedElement) { | |||
return getLabels(annotatedElement.getAnnotations()); | |||
return getLabels(getAllAnnotations(annotatedElement)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be added to getLinks method as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a bug:
public interface First {
default void a() {
}
}
public interface Second extends First {
default void b() {
}
}
then ReflectionUtils.getAllDeclaredMethods(Second.class)
will produce duplicate results:
public default void Second.b(),
public default void First.a(),
public default void First.a()
fixes #1032
Context
The
getTestMethod
method in theio.qameta.allure.junitplatform.AllureJunitPlatformUtils
class doesn't function as expected for tests that are inherited. This is because it usesaClass.getDeclaredMethods()
, which only operates on the current instance and does not include methods that are inherited. This can cause issues with annotations related to methods, such as descriptions and others.Revision 1
In this revision, I used the
aClass.getMethods()
that returns all public methods on a checking class.Revision 2
However, revision 1 covers one of the test cases when all test methods are public. It doesn't work when:
In short, I have to implement two methods placed into
ReflectionUtils
to recursively collect method and annotation information. These methods are designed as simplified logic oforg.springframework.data.util.ReflectionUtils
specifically for our needs.Checklist