-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto Generate Event Publishers (#554)
* Auto Generate Event Publishers * Update BeanReader.java * allow generated extends type in autoprovides * Update TypeExtendsReader.java * fix imported type gen * fix restricted packages * blackbox test * Delete module-info.java * doc * static write * fix register param name * Revert the change to name qualifier * Rename Event.defaultQualifier -> qualifier * format javadoc only * Rename field back to defaultQualifier --------- Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
- Loading branch information
Showing
21 changed files
with
300 additions
and
59 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
blackbox-other/src/main/java/org/other/one/events/SomeOptionalDep$Publisher.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,19 @@ | ||
package org.other.one.events; | ||
|
||
import io.avaje.inject.Component; | ||
import io.avaje.inject.event.Event; | ||
import io.avaje.inject.event.ObserverManager; | ||
import io.avaje.inject.spi.Generated; | ||
import java.lang.reflect.Type; | ||
import org.other.one.SomeOptionalDep; | ||
|
||
@Component | ||
@Generated("avaje-inject-generator") | ||
public class SomeOptionalDep$Publisher extends Event<SomeOptionalDep> { | ||
|
||
private static final Type TYPE = SomeOptionalDep.class; | ||
|
||
public SomeOptionalDep$Publisher(ObserverManager manager) { | ||
super(manager, TYPE, ""); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
blackbox-test-inject/src/main/java/org/example/myapp/events/ExternalEventPublisher.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,22 @@ | ||
package org.example.myapp.events; | ||
|
||
import org.example.external.aspect.MyExternalAspect; | ||
import org.other.one.SomeOptionalDep; | ||
|
||
import io.avaje.inject.Component; | ||
import io.avaje.inject.event.Event; | ||
|
||
@Component | ||
public class ExternalEventPublisher { | ||
Event<SomeOptionalDep> event; | ||
|
||
public ExternalEventPublisher(Event<SomeOptionalDep> event) { | ||
|
||
this.event = event; | ||
} | ||
|
||
@MyExternalAspect | ||
public void fire(SomeOptionalDep dep) { | ||
event.fire(dep); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
blackbox-test-inject/src/main/java/org/example/myapp/events/ExternalObserver.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,19 @@ | ||
package org.example.myapp.events; | ||
|
||
import org.other.one.SomeOptionalDep; | ||
|
||
import io.avaje.inject.event.Observes; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class ExternalObserver { | ||
|
||
boolean invoked; | ||
SomeOptionalDep recievedEvent; | ||
|
||
public void observe(@Observes SomeOptionalDep event) { | ||
invoked = true; | ||
|
||
this.recievedEvent = event; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
blackbox-test-inject/src/test/java/org/example/myapp/events/TestEventMessaging.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,33 @@ | ||
package org.example.myapp.events; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.other.one.SomeOptionalDep; | ||
|
||
import io.avaje.inject.test.InjectTest; | ||
import jakarta.inject.Inject; | ||
|
||
@InjectTest | ||
class TestEventMessaging { | ||
|
||
@Inject ExternalObserver observer; | ||
@Inject ExternalEventPublisher event; | ||
|
||
@BeforeEach | ||
void before() { | ||
observer.invoked = false; | ||
observer.recievedEvent = null; | ||
} | ||
|
||
@Test | ||
void test() { | ||
var message = new SomeOptionalDep() {}; | ||
|
||
event.fire(message); | ||
|
||
assertThat(observer.invoked).isTrue(); | ||
assertThat(observer.recievedEvent).isSameAs(message); | ||
} | ||
} |
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
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
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
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
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
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
1 change: 0 additions & 1 deletion
1
inject-generator/src/main/java/io/avaje/inject/generator/package-info.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
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
Oops, something went wrong.