CDI Event Arrival Integration Test with Quarkus

To test the arrival of a CDI Event sent from a managed bean:

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;

public class MessageSender {

    Event<String> messageEvent;

    public void send(){"duke rocks!");
} can inject the managed bean into an integration test with ordered methods as "Class under Test":

import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import io.quarkus.test.junit.QuarkusTest;

public class MessageSenderIT {
    MessageSender cut;
    String expected;

    //...the first test sends the event:
    void send() {

    //on "ordinary" CDI listener receives the message
    public void receive(@Observes String message){
        this.expected = message;

    //the last test method verifies the arrival of the event
    void verifyArrival() {
        assertEquals("duke rocks!",this.expected);


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments