-
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 #31012 from mkouba/arc-detect-unsupported-inject
ArC: detect unsupported Inject annotations
- Loading branch information
Showing
4 changed files
with
89 additions
and
19 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
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
21 changes: 21 additions & 0 deletions
21
...eployment/src/test/java/io/quarkus/arc/test/wrongannotations/BeanWithIncorrectInject.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,21 @@ | ||
package io.quarkus.arc.test.wrongannotations; | ||
|
||
import jakarta.enterprise.inject.spi.BeanManager; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class BeanWithIncorrectInject { | ||
|
||
@Inject | ||
BeanManager bm1; | ||
|
||
@javax.inject.Inject | ||
BeanManager bm2; | ||
|
||
@com.oracle.svm.core.annotate.Inject | ||
BeanManager bm3; | ||
|
||
@org.gradle.internal.impldep.javax.inject.Inject | ||
BeanManager bm4; | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ns/arc/deployment/src/test/java/io/quarkus/arc/test/wrongannotations/WrongInjectTest.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,50 @@ | ||
package io.quarkus.arc.test.wrongannotations; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import javax.inject.Inject; | ||
|
||
import jakarta.enterprise.inject.spi.BeanManager; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class WrongInjectTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(BeanWithIncorrectInject.class)) | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
assertTrue(rootCause.getMessage().contains( | ||
"@com.google.inject.Inject declared on io.quarkus.arc.test.wrongannotations.BeanWithIncorrectInject.bm1, use @jakarta.inject.Inject instead"), | ||
t.toString()); | ||
assertTrue(rootCause.getMessage().contains( | ||
"@javax.inject.Inject declared on io.quarkus.arc.test.wrongannotations.BeanWithIncorrectInject.bm2, use @jakarta.inject.Inject instead"), | ||
t.toString()); | ||
assertTrue(rootCause.getMessage().contains( | ||
"@com.oracle.svm.core.annotate.Inject declared on io.quarkus.arc.test.wrongannotations.BeanWithIncorrectInject.bm3, use @jakarta.inject.Inject instead"), | ||
t.toString()); | ||
assertTrue(rootCause.getMessage().contains( | ||
"@org.gradle.internal.impldep.javax.inject.Inject declared on io.quarkus.arc.test.wrongannotations.BeanWithIncorrectInject.bm4, use @jakarta.inject.Inject instead"), | ||
t.toString()); | ||
assertTrue(rootCause.getMessage().contains( | ||
"@javax.inject.Inject declared on io.quarkus.arc.test.wrongannotations.WrongInjectTest.beanManager, use @jakarta.inject.Inject instead"), | ||
t.toString()); | ||
}); | ||
|
||
@Inject | ||
BeanManager beanManager; | ||
|
||
@Test | ||
public void testValidationFailed() { | ||
// This method should not be invoked | ||
fail(); | ||
} | ||
|
||
} |