-
Notifications
You must be signed in to change notification settings - Fork 41k
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
Introduce TestSliceTestContextBootstrapper for test slices #44354
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Yanming Zhou <[email protected]>
"Method '%s.properties()' should return String[]".formatted(this.annotationType.getName())); | ||
} | ||
catch (NoSuchMethodException ex) { | ||
throw new RuntimeException( |
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.
I need advice for exception type and message.
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.
You can simplify things a little bit
public abstract class TestSliceTestContextBootstrapper<A extends Annotation> extends SpringBootTestContextBootstrapper {
private final Class<A> annotationType;
@SuppressWarnings("unchecked")
protected TestSliceTestContextBootstrapper() {
this.annotationType = (Class<A>) ResolvableType.forClass(TestSliceTestContextBootstrapper.class, getClass())
.resolveGeneric();
}
@Override
protected String[] getProperties(Class<?> testClass) {
MergedAnnotation<A> annotation = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY)
.withEnclosingClasses(TestContextAnnotationUtils::searchEnclosingClass)
.from(testClass)
.get(this.annotationType);
return annotation.isPresent() ? annotation.getStringArray("properties") : null;
}
}
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.
Yes, I have considered this way, but I think it's better to keep the logic in TestContextAnnotationUtils
, WDYT?
I created spring-projects/spring-framework#34456
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.
but I think it's better to keep the logic in TestContextAnnotationUtils, WDYT?
Honestly, I don't see any issues with using MergedAnnotations.search(...)
instead of
TestContextAnnotationUtils
. On one hand, it would be nice if the Spring Framework
could provide this functionality, but it does not make the situation significantly better.
Considering that it is used only once in a single place, IMO, it is too much to ask to add it to the Spring Framework.
Also, this PR is still in a draft state, and there is no feedback from the Spring Boot team regarding
this enhancement, so maybe it makes sense to wait for feedback first and then ask the Spring Framework team to
add something.
No description provided.