-
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.
ArC: fix decorators and interface default methods
- Loading branch information
Showing
3 changed files
with
68 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
59 changes: 59 additions & 0 deletions
59
...ts/arc/tests/src/test/java/io/quarkus/arc/test/decorators/DecoratorDefaultMethodTest.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.decorators; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.util.TypeLiteral; | ||
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 DecoratorDefaultMethodTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToLengthConverter.class, | ||
NoopConverterDecorator.class); | ||
|
||
@SuppressWarnings("serial") | ||
@Test | ||
public void testDecoration() { | ||
Converter<String> converter = Arc.container().instance(new TypeLiteral<Converter<String>>() { | ||
}).get(); | ||
assertEquals(5, converter.convert("Hola!")); | ||
} | ||
|
||
interface Converter<T> { | ||
default int convert(T value) { | ||
return Integer.MAX_VALUE; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToLengthConverter implements Converter<String> { | ||
@Override | ||
public int convert(String value) { | ||
return value.length(); | ||
} | ||
} | ||
|
||
@Priority(1) | ||
@Decorator | ||
static class NoopConverterDecorator implements Converter<String> { | ||
|
||
@Inject | ||
@Delegate | ||
Converter<String> delegate; | ||
|
||
@Override | ||
public int convert(String value) { | ||
return delegate.convert(value); | ||
} | ||
} | ||
|
||
} |