-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43931 from Ladicek/arc-test-primitive-observer
ArC: add test for observer of a primitive type
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...jects/arc/tests/src/test/java/io/quarkus/arc/test/event/primitive/PrimitiveEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> event; | ||
|
||
void produce() { | ||
event.fire(42); | ||
} | ||
} | ||
} |