-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I'd like to propose to adapt the VertxExtension
in order to allow a manual configuration of the Vertx
instance before injecting it in the test/setup/teardown methods.
Junit5 offers a @RegisterExtension
annotation that allows to configure extension objects. More information can be found here.
Thus, the current mechanics, to simply inject a Vertx
instance would still work, while users who'd like to adapt the settings of the Vertx
instance for a given test case could still benefit from the VertxExtension
.
In order to verify my proposal, I created a copy of the existing VertxExtension
and added/adapted following code:
- Add a new field with a supplier that returns a
Vertx
instance on invocation
private final Supplier<Vertx> vertxSupplier;
- Add a default constructor and a constructor with the supplier parameter
public VertxExtension() {
this(Vertx::vertx);
}
public VertxExtension(Supplier<Vertx> vertxSupplier) {
this.vertxSupplier = vertxSupplier;
}
- Adapt the resolveParameter method to invoke the
vertxSupplier
return getOrCreateScopedObject(
parameterContext,
extensionContext,
VERTX_INSTANCE_KEY,
VERTX_INSTANCE_CREATOR_KEY,
key -> new ConfigurableVertxExtension.ScopedObject<>(vertxSupplier.get(), closeRegularVertx()));
In the test class itself, we could provide a configured vertx instance instead of sticking with the default (kotlin code):
companion object {
@JvmField
@RegisterExtension
val ext = VertxExtension { manuallyConfiguredVertx() }
}
Hope you consider this proposal.