forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC - resolve type variables for inherited observer methods
- resolves quarkusio#25364
- Loading branch information
Showing
2 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
...rkus/arc/test/observers/inheritance/typevariable/ObserverInheritanceTypeVariableTest.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,85 @@ | ||
package io.quarkus.arc.test.observers.inheritance.typevariable; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.event.Event; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
/** | ||
* https://github.com/quarkusio/quarkus/issues/25364 | ||
*/ | ||
public class ObserverInheritanceTypeVariableTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyEvent.class, MyAEvent.class, MyBEvent.class, MyAService.class, | ||
MyBService.class, EventSource.class); | ||
|
||
@Test | ||
public void testNotification() { | ||
Arc.container().instance(EventSource.class).get().sendA(); | ||
assertNotNull(MyAService.event); | ||
assertNull(MyBService.event); | ||
} | ||
|
||
static class MyEvent { | ||
} | ||
|
||
static class MyAEvent extends MyEvent { | ||
} | ||
|
||
static class MyBEvent extends MyEvent { | ||
} | ||
|
||
static abstract class AbstractService<E extends MyEvent> { | ||
|
||
void onEvent(@Observes E myEvent) { | ||
doSomething(myEvent); | ||
} | ||
|
||
abstract void doSomething(E myEvent); | ||
} | ||
|
||
@ApplicationScoped | ||
static class MyAService extends AbstractService<MyAEvent> { | ||
|
||
static volatile MyAEvent event; | ||
|
||
@Override | ||
protected void doSomething(MyAEvent myEvent) { | ||
MyAService.event = myEvent; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
static class MyBService extends AbstractService<MyBEvent> { | ||
|
||
static volatile MyBEvent event; | ||
|
||
@Override | ||
void doSomething(MyBEvent myEvent) { | ||
MyBService.event = myEvent; | ||
} | ||
} | ||
|
||
@Unremovable | ||
@Dependent | ||
static class EventSource { | ||
|
||
@Inject | ||
Event<MyEvent> event; | ||
|
||
void sendA() { | ||
event.fire(new MyAEvent()); | ||
} | ||
} | ||
|
||
} |