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: improve validation of interceptor method signatures
- Loading branch information
Showing
7 changed files
with
209 additions
and
40 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
6 changes: 6 additions & 0 deletions
6
...t-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorPlacement.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,6 @@ | ||
package io.quarkus.arc.processor; | ||
|
||
enum InterceptorPlacement { | ||
INTERCEPTOR_CLASS, | ||
TARGET_CLASS, | ||
} |
59 changes: 59 additions & 0 deletions
59
...c/test/java/io/quarkus/arc/test/interceptors/illegal/InterceptorWithoutParameterTest.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,59 @@ | ||
package io.quarkus.arc.test.interceptors.illegal; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.inject.spi.DefinitionException; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class InterceptorWithoutParameterTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(MyInterceptor.class, MyInterceptorBinding.class) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void trigger() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertInstanceOf(DefinitionException.class, error); | ||
assertTrue(error.getMessage().contains( | ||
"@AroundInvoke interceptor method declared in an interceptor class must have exactly one parameter")); | ||
assertTrue(error.getMessage().contains("intercept()")); | ||
assertTrue(error.getMessage().contains("InterceptorWithoutParameterTest$MyInterceptor")); | ||
} | ||
|
||
@Target({ TYPE, METHOD, FIELD, PARAMETER }) | ||
@Retention(RUNTIME) | ||
@InterceptorBinding | ||
@interface MyInterceptorBinding { | ||
} | ||
|
||
@MyInterceptorBinding | ||
@Interceptor | ||
@Priority(1) | ||
static class MyInterceptor { | ||
@AroundInvoke | ||
Object intercept() throws Exception { | ||
return null; | ||
} | ||
} | ||
} |
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