Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Feb 19, 2025

No description provided.

@quaff quaff marked this pull request as draft February 19, 2025 10:33
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 19, 2025
"Method '%s.properties()' should return String[]".formatted(this.annotationType.getName()));
}
catch (NoSuchMethodException ex) {
throw new RuntimeException(
Copy link
Contributor Author

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.

Copy link
Contributor

@nosan nosan Feb 19, 2025

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;
	}

}

Copy link
Contributor Author

@quaff quaff Feb 20, 2025

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

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants