Fix WireMock server field injection for native tests
@@ -116,8 +116,9 @@ public abstract class WireMockTestResourceLifecycleManager implements QuarkusTes
@Override
public void inject(Object testInstance) {
if (isMockingEnabled() || isRecordingEnabled()) {
- Class<?> c = testInstance.getClass();
- for (Field field : c.getDeclaredFields()) {
+ Class<?> testClass = testInstance.getClass();
+ while (testClass != Object.class) {
+ for (Field field : testClass.getDeclaredFields()) {
if (field.getAnnotation(MockServer.class) != null) {
if (!WireMockServer.class.isAssignableFrom(field.getType())) {
throw new RuntimeException("@MockServer can only be used on fields of type WireMockServer");
@@ -126,6 +127,7 @@ public abstract class WireMockTestResourceLifecycleManager implements QuarkusTes
field.setAccessible(true);
try {
if (server == null) {
+ LOG.info("Starting WireMockServer");
server = createServer();
server.start();
}
@@ -137,6 +139,8 @@ public abstract class WireMockTestResourceLifecycleManager implements QuarkusTes
}
}
}
+ testClass = testClass.getSuperclass();
+ }
}
}
