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.
Merge pull request quarkusio#38785 from Ladicek/arc-fix-void-method-i…
…nterception ArC: fix interception when some methods return void
- Loading branch information
Showing
3 changed files
with
174 additions
and
4 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
69 changes: 69 additions & 0 deletions
69
...jects/arc/tests/src/test/java/io/quarkus/arc/test/decorators/VoidMethodDecoratorTest.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,69 @@ | ||
package io.quarkus.arc.test.decorators; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class VoidMethodDecoratorTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Performer.class, MainPerformer.class, | ||
PerformerDecorator.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
MainPerformer performer = Arc.container().instance(MainPerformer.class).get(); | ||
|
||
assertFalse(MainPerformer.DONE.get()); | ||
assertFalse(PerformerDecorator.DONE.get()); | ||
|
||
performer.doSomething(); | ||
|
||
assertTrue(MainPerformer.DONE.get()); | ||
assertTrue(PerformerDecorator.DONE.get()); | ||
} | ||
|
||
interface Performer { | ||
void doSomething(); | ||
} | ||
|
||
@ApplicationScoped | ||
static class MainPerformer implements Performer { | ||
static final AtomicBoolean DONE = new AtomicBoolean(); | ||
|
||
@Override | ||
public void doSomething() { | ||
DONE.set(true); | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class PerformerDecorator implements Performer { | ||
static final AtomicBoolean DONE = new AtomicBoolean(); | ||
|
||
@Inject | ||
@Delegate | ||
Performer delegate; | ||
|
||
@Override | ||
public void doSomething() { | ||
DONE.set(true); | ||
delegate.doSomething(); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...ava/io/quarkus/arc/test/decorators/interceptor/VoidMethodInterceptorAndDecoratorTest.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,101 @@ | ||
package io.quarkus.arc.test.decorators.interceptor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.inject.Inject; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InterceptorBinding; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class VoidMethodInterceptorAndDecoratorTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Performer.class, MainPerformer.class, | ||
PerformerDecorator.class, MyInterceptorBinding.class, MyInterceptor.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
MainPerformer performer = Arc.container().instance(MainPerformer.class).get(); | ||
|
||
assertFalse(MainPerformer.DONE.get()); | ||
assertFalse(PerformerDecorator.DONE.get()); | ||
assertFalse(MyInterceptor.INTERCEPTED.get()); | ||
|
||
performer.doSomething(); | ||
|
||
assertTrue(MainPerformer.DONE.get()); | ||
assertTrue(PerformerDecorator.DONE.get()); | ||
assertTrue(MyInterceptor.INTERCEPTED.get()); | ||
} | ||
|
||
interface Performer { | ||
void doSomething(); | ||
} | ||
|
||
@ApplicationScoped | ||
@MyInterceptorBinding | ||
static class MainPerformer implements Performer { | ||
static final AtomicBoolean DONE = new AtomicBoolean(); | ||
|
||
@Override | ||
public void doSomething() { | ||
DONE.set(true); | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class PerformerDecorator implements Performer { | ||
static final AtomicBoolean DONE = new AtomicBoolean(); | ||
|
||
@Inject | ||
@Delegate | ||
Performer delegate; | ||
|
||
@Override | ||
public void doSomething() { | ||
DONE.set(true); | ||
delegate.doSomething(); | ||
} | ||
} | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface MyInterceptorBinding { | ||
} | ||
|
||
@MyInterceptorBinding | ||
@Priority(1) | ||
@Interceptor | ||
static class MyInterceptor { | ||
static final AtomicBoolean INTERCEPTED = new AtomicBoolean(); | ||
|
||
@AroundInvoke | ||
Object log(InvocationContext ctx) throws Exception { | ||
INTERCEPTED.set(true); | ||
return ctx.proceed(); | ||
} | ||
} | ||
} |