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

Allow anonymous test extension subclasses to share the test state of their parents #45818

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected QuarkusTestExtensionState getState(ExtensionContext context) {
QuarkusTestExtensionState state = store.get(QuarkusTestExtensionState.class.getName(), QuarkusTestExtensionState.class);
if (state != null) {
Class<?> testingTypeOfState = store.get(IO_QUARKUS_TESTING_TYPE, Class.class);
if (!this.getClass().equals(testingTypeOfState)) {
if (!this.getTestingType().equals(testingTypeOfState)) {
// The current state was created by a different testing type, so we need to renew it, so the new state is
// compatible with the current testing type.
try {
Expand All @@ -78,7 +78,7 @@ protected QuarkusTestExtensionState getState(ExtensionContext context) {
protected void setState(ExtensionContext context, QuarkusTestExtensionState state) {
ExtensionContext.Store store = getStoreFromContext(context);
store.put(QuarkusTestExtensionState.class.getName(), state);
store.put(IO_QUARKUS_TESTING_TYPE, this.getClass());
store.put(IO_QUARKUS_TESTING_TYPE, this.getTestingType());
}

protected ExtensionContext.Store getStoreFromContext(ExtensionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,24 @@ private void invokeCallbacks(List<Object> callbacks, String methodName, Class<?>
throw e;
}
}

protected Class getTestingType() {

// In general, the testing type should be the test extension class, but ...
Class type = this.getClass();

// We don't want to pick up the class of anonymous classes, since they're clearly supposed to 'be' the superclass.
// We want something like
// @RegisterExtension
// static QuarkusTestExtension TEST = new QuarkusTestExtension() {
// @Override
// // Whatever
// };
// to count as a QuarkusTestExtension class
if (type.isAnonymousClass()) {
return type.getSuperclass();
} else {
return type;
}
}
}
Loading