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

VertxExtension throwing when test method accepts io.vertx.rxjava.core.Vertx argument #41

Closed
matthewadams opened this issue May 26, 2018 · 1 comment

Comments

@matthewadams
Copy link

matthewadams commented May 26, 2018

As a follow up to #40, I made the suggested fix:

import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import io.vertx.rxjava.core.Vertx;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import rx.Single;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(VertxExtension.class)
public class AuthenticatorTest {
  public static class AuthenticatorStub {
    public AuthenticatorStub(Vertx vertx) {}
    public Single<Token> getToken() {
      return Single.just(new Token().setValue("bogus").setExpiry(Instant.now().plusSeconds(60 * 5)));
    }
  }

  @Test
  public void testGetNewToken(Vertx vertx, VertxTestContext context) throws InterruptedException {
    AuthenticatorStub auth = new AuthenticatorStub(vertx);
    auth.getToken().subscribe(token -> {
      try {
        fail("bogus");
        context.completeNow();
      } catch (Throwable t) {
        context.failNow(t);
      }
    }, context::failNow);
    assertTrue(context.awaitCompletion(60, TimeUnit.SECONDS));
  }
}

This time, however, I get a ParameterResolutionException, because I'm accepting a io.vertx.rxjava.core.Vertx, not an io.vertx.core.Vertx:

org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [io.vertx.rxjava.core.Vertx arg0] in executable [public void com.nml.ips.bnymellon.rest.AuthenticatorTest.testGetNewToken(io.vertx.rxjava.core.Vertx,io.vertx.junit5.VertxTestContext) throws java.lang.InterruptedException].

...

While I was able to workaround the issue with the code below, I feel like this module should optionally depend on io.vertx:vertx-rx-java (ie, use maven's scope provided or similar) and, if a test signature accepts an io.vertx.rxjava.core.Vertx, the extension should supply a new io.vertx.rxjava.core.Vertx(vertx), where vertx is the io.vertx.core.Vertx that the extension would normally supply.

Here's my workaround:

import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import io.vertx.rxjava.core.Vertx;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import rx.Single;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(VertxExtension.class)
public class AuthenticatorTest2 {
  public static class AuthenticatorStub {
    public AuthenticatorStub(Vertx vertx) {}
    public Single<Token> getToken() {
      return Single.just(new Token().setValue("bogus").setExpiry(Instant.now().plusSeconds(60 * 5)));
    }
  }

  public Vertx rxvertx;

  @BeforeEach
  public void setup(io.vertx.core.Vertx vertx) {
    rxvertx = new Vertx(vertx);
  }

  @Test
  public void testGetNewToken(VertxTestContext context) throws InterruptedException {
    AuthenticatorStub auth = new AuthenticatorStub(rxvertx);
    auth.getToken().subscribe(token -> {
      try {
        fail("bogus");
        context.completeNow();
      } catch (Throwable t) {
        context.failNow(t);
      }
    }, context::failNow);
    assertTrue(context.awaitCompletion(60, TimeUnit.SECONDS));
  }
}
@jponge
Copy link
Member

jponge commented May 28, 2018

This has already been implemented in the master branch and will be part of 3.6.0, see #33 and #34

@jponge jponge closed this as completed May 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants