From fded130db2e786e0171311ddd645601eb0397683 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Thu, 17 Oct 2024 13:49:20 +0200 Subject: [PATCH] ArC: add test for observer of a primitive type --- .../event/primitive/PrimitiveEventTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/event/primitive/PrimitiveEventTest.java diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/event/primitive/PrimitiveEventTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/event/primitive/PrimitiveEventTest.java new file mode 100644 index 0000000000000..400b8439bcea1 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/event/primitive/PrimitiveEventTest.java @@ -0,0 +1,55 @@ +package io.quarkus.arc.test.event.primitive; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import jakarta.enterprise.event.Event; +import jakarta.enterprise.event.Observes; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.Arc; +import io.quarkus.arc.test.ArcTestContainer; + +public class PrimitiveEventTest { + @RegisterExtension + public ArcTestContainer container = new ArcTestContainer(Observer.class, Producer.class); + + @Test + public void test() { + assertFalse(Observer.primitiveNotified); + assertFalse(Observer.wrapperNotified); + + Arc.container().select(Producer.class).get().produce(); + + assertTrue(Observer.primitiveNotified); + assertTrue(Observer.wrapperNotified); + } + + @Singleton + static class Observer { + static boolean primitiveNotified = false; + static boolean wrapperNotified = false; + + void observePrimitive(@Observes int event) { + primitiveNotified = true; + } + + void observeWrapper(@Observes Integer event) { + wrapperNotified = true; + } + } + + @Singleton + static class Producer { + @Inject + Event event; + + void produce() { + event.fire(42); + } + } +}