Can you spy on the Vert.x event bus in Quarkus tests?

Viewed 477

Does anyone know of a way to spy on the Vert.x event bus in Quarkus tests? Ideally I'd like to assert that during a method in the service layer we are sending an event to the correct address, but does anyone know if this is possible?

If I just try to use @InjectMock I get the following error

io.vertx.core.eventbus.impl.EventBusImpl@5769679b is not a normal scoped CDI bean, make sure the bean is a normal scope like @ApplicationScoped or @RequestScoped
2 Answers

I solved this Problem, by creating an ApplicationScoped Delegate around the EventBus. This Delegate can be mocked and inspected as a normal bean in Quarkus. All the Beans which were using the EventBus directly need to use the EventBusDelegate instead. In your test you can use the @InjectMock annotation to inject the EventBusDelegate mocked.

As suggested here https://github.com/quarkusio/quarkus/issues/8983

@InjectMock(convertScopes = true)

should solve your problem. If convertScopes is true, then Quarkus will change Singleton to ApplicationScoped to make the bean mockable.

NOTE: the documentation states that this is an advanced setting and should only be used if you don't rely on the differences between Singleton and ApplicationScoped beans

Related