-
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 #31085 from manovotn/eventRawTypeValidation
Arc - validate Event raw type injection points and throw DefinitionException when found
- Loading branch information
Showing
7 changed files
with
244 additions
and
0 deletions.
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
36 changes: 36 additions & 0 deletions
36
...rc/test/java/io/quarkus/arc/test/event/injection/invalid/ConstructorEventRawTypeTest.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,36 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ConstructorEventRawTypeTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
public static class InvalidBean { | ||
|
||
// raw event type | ||
public InvalidBean(Event event) { | ||
} | ||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...test/java/io/quarkus/arc/test/event/injection/invalid/DisposerMethodEventRawTypeTest.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,47 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.Disposes; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DisposerMethodEventRawTypeTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(DisposerMethodInjectionBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
public static class DisposerMethodInjectionBean { | ||
|
||
@Produces | ||
public Foo produceFoo() { | ||
return new Foo(); | ||
} | ||
|
||
// rawtype Event | ||
public void disposeFoo(@Disposes Foo foo, Event event) { | ||
} | ||
|
||
} | ||
|
||
static class Foo { | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../src/test/java/io/quarkus/arc/test/event/injection/invalid/EventRawTypeInjectionTest.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,38 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
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.Unremovable; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class EventRawTypeInjectionTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(WrongBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Singleton | ||
@Unremovable | ||
static class WrongBean { | ||
|
||
@Inject | ||
Event rawEvent; | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...src/test/java/io/quarkus/arc/test/event/injection/invalid/InitMethodEventRawTypeTest.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,38 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class InitMethodEventRawTypeTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
public static class InvalidBean { | ||
|
||
// raw event type | ||
@Inject | ||
public void initMethod(Event event) { | ||
} | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...src/test/java/io/quarkus/arc/test/event/injection/invalid/ObserverMethodEventRawType.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,37 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ObserverMethodEventRawType { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
public static class InvalidBean { | ||
|
||
// raw event type | ||
public void observe(@Observes String something, Event event) { | ||
} | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...test/java/io/quarkus/arc/test/event/injection/invalid/ProducerMethodEventRawTypeTest.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,41 @@ | ||
package io.quarkus.arc.test.event.injection.invalid; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ProducerMethodEventRawTypeTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(ProducerMethodInjectionBean.class).shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testExceptionIsThrown() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
public static class ProducerMethodInjectionBean { | ||
|
||
@Produces | ||
public Foo produceFoo(Event event) { // rawtype event injection point | ||
return new Foo(); | ||
} | ||
} | ||
|
||
static class Foo { | ||
|
||
} | ||
} |