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 to inject manually configured Vertx instance in test methods if needed #55

Open
u6f6o opened this issue Feb 1, 2019 · 3 comments

Comments

@u6f6o
Copy link

u6f6o commented Feb 1, 2019

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:

  1. Add a new field with a supplier that returns a Vertx instance on invocation
private final Supplier<Vertx> vertxSupplier;
  1. Add a default constructor and a constructor with the supplier parameter
public VertxExtension() {
     this(Vertx::vertx);
}
public VertxExtension(Supplier<Vertx> vertxSupplier) {
     this.vertxSupplier = vertxSupplier;
}
  1. 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.

@jponge
Copy link
Member

jponge commented Feb 3, 2019

On paper this sounds interesting, feel-free to propose a pull-request so we can concretely review it 😉

@u6f6o
Copy link
Author

u6f6o commented Feb 4, 2019

👍 done: #56

@jponge jponge closed this as completed Feb 3, 2021
@slinkydeveloper
Copy link
Member

It seems like this issue is still not solved, and we have a duplicate: #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants