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.
CDI decorators - fix processing of decorated methods
- resolves quarkusio#29230
- Loading branch information
Showing
5 changed files
with
110 additions
and
20 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
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
75 changes: 75 additions & 0 deletions
75
...rc/tests/src/test/java/io/quarkus/arc/test/decorators/SimpleDecoratorOverloadingTest.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,75 @@ | ||
package io.quarkus.arc.test.decorators; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import javax.annotation.Priority; | ||
import javax.decorator.Decorator; | ||
import javax.decorator.Delegate; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.Dependent; | ||
import javax.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 SimpleDecoratorOverloadingTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, SimpleConverter.class, | ||
ConverterDecorator.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
SimpleConverter converter = Arc.container().instance(SimpleConverter.class).get(); | ||
assertEquals("HOLA!", converter.convert(" holA!")); | ||
assertEquals(42, converter.convert(42)); | ||
} | ||
|
||
interface Converter { | ||
|
||
int convert(int value); | ||
|
||
String convert(String value); | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
static class SimpleConverter implements Converter { | ||
|
||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
|
||
@Override | ||
public int convert(int value) { | ||
return -1 * value; | ||
} | ||
|
||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class ConverterDecorator implements Converter { | ||
|
||
@Inject | ||
@Delegate | ||
Converter delegate; | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(value.trim()); | ||
} | ||
|
||
@Override | ||
public int convert(int value) { | ||
return -1 * delegate.convert(value); | ||
} | ||
|
||
} | ||
|
||
} |