Skip to content

Commit

Permalink
Allow anonymous classes to share the test state of their parents
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Jan 22, 2025
1 parent 55cd78c commit 934120f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected QuarkusTestExtensionState getState(ExtensionContext context) {
}

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 Down Expand Up @@ -98,7 +98,7 @@ protected void setState(ExtensionContext context, QuarkusTestExtensionState stat
System.out.println("HOLLY setting state " + state.getClass() + " cl:" + state.getClass().getClassLoader());
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;
}
}
}

0 comments on commit 934120f

Please sign in to comment.