-
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 constructor injection for abstract decorators
- Loading branch information
Showing
7 changed files
with
427 additions
and
2 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
68 changes: 68 additions & 0 deletions
68
...s/src/test/java/io/quarkus/arc/test/decorators/DecoratorWithConstructorInjectionTest.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,68 @@ | ||
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.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 DecoratorWithConstructorInjectionTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToUpperCaseConverter.class, | ||
TrimConverterDecorator.class, Trimmer.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); | ||
assertEquals("HOLA!", converter.convert(" holA! ")); | ||
} | ||
|
||
interface Converter<T> { | ||
T convert(T value); | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToUpperCaseConverter implements Converter<String> { | ||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class TrimConverterDecorator implements Converter<String> { | ||
@Inject | ||
@Delegate | ||
Converter<String> delegate; | ||
|
||
private final Trimmer trimmer; | ||
|
||
@Inject | ||
TrimConverterDecorator(Trimmer trimmer) { | ||
this.trimmer = trimmer; | ||
} | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(trimmer.trim(value)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Trimmer { | ||
public String trim(String str) { | ||
return str.trim(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...c/tests/src/test/java/io/quarkus/arc/test/decorators/DecoratorWithFieldInjectionTest.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,64 @@ | ||
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.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 DecoratorWithFieldInjectionTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToUpperCaseConverter.class, | ||
TrimConverterDecorator.class, Trimmer.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); | ||
assertEquals("HOLA!", converter.convert(" holA! ")); | ||
} | ||
|
||
interface Converter<T> { | ||
T convert(T value); | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToUpperCaseConverter implements Converter<String> { | ||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class TrimConverterDecorator implements Converter<String> { | ||
@Inject | ||
@Delegate | ||
Converter<String> delegate; | ||
|
||
@Inject | ||
Trimmer trimmer; | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(trimmer.trim(value)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Trimmer { | ||
public String trim(String str) { | ||
return str.trim(); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../tests/src/test/java/io/quarkus/arc/test/decorators/DecoratorWithSetterInjectionTest.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,68 @@ | ||
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.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 DecoratorWithSetterInjectionTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToUpperCaseConverter.class, | ||
TrimConverterDecorator.class, Trimmer.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); | ||
assertEquals("HOLA!", converter.convert(" holA! ")); | ||
} | ||
|
||
interface Converter<T> { | ||
T convert(T value); | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToUpperCaseConverter implements Converter<String> { | ||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class TrimConverterDecorator implements Converter<String> { | ||
@Inject | ||
@Delegate | ||
Converter<String> delegate; | ||
|
||
private Trimmer trimmer; | ||
|
||
@Inject | ||
void init(Trimmer trimmer) { | ||
this.trimmer = trimmer; | ||
} | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(trimmer.trim(value)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Trimmer { | ||
public String trim(String str) { | ||
return str.trim(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...arkus/arc/test/decorators/abstractimpl/AbstractDecoratorWithConstructorInjectionTest.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.abstractimpl; | ||
|
||
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.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 AbstractDecoratorWithConstructorInjectionTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToUpperCaseConverter.class, | ||
TrimConverterDecorator.class, Trimmer.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); | ||
assertEquals("HELLO", converter.convert(" hello ")); | ||
assertEquals(ToUpperCaseConverter.class.getName(), converter.getId()); | ||
} | ||
|
||
interface Converter<T, U> { | ||
T convert(T value); | ||
|
||
U getId(); | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToUpperCaseConverter implements Converter<String, String> { | ||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return ToUpperCaseConverter.class.getName(); | ||
} | ||
} | ||
|
||
@Priority(1) | ||
@Decorator | ||
static abstract class TrimConverterDecorator implements Converter<String, String> { | ||
@Inject | ||
@Delegate | ||
Converter<String, String> delegate; | ||
|
||
private final Trimmer trimmer; | ||
|
||
@Inject | ||
TrimConverterDecorator(Trimmer trimmer) { | ||
this.trimmer = trimmer; | ||
} | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(trimmer.trim(value)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Trimmer { | ||
public String trim(String value) { | ||
return value.trim(); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
.../io/quarkus/arc/test/decorators/abstractimpl/AbstractDecoratorWithFieldInjectionTest.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,71 @@ | ||
package io.quarkus.arc.test.decorators.abstractimpl; | ||
|
||
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.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 AbstractDecoratorWithFieldInjectionTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Converter.class, ToUpperCaseConverter.class, | ||
TrimConverterDecorator.class, Trimmer.class); | ||
|
||
@Test | ||
public void testDecoration() { | ||
ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); | ||
assertEquals("HELLO", converter.convert(" hello ")); | ||
assertEquals(ToUpperCaseConverter.class.getName(), converter.getId()); | ||
} | ||
|
||
interface Converter<T, U> { | ||
T convert(T value); | ||
|
||
U getId(); | ||
} | ||
|
||
@ApplicationScoped | ||
static class ToUpperCaseConverter implements Converter<String, String> { | ||
@Override | ||
public String convert(String value) { | ||
return value.toUpperCase(); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return ToUpperCaseConverter.class.getName(); | ||
} | ||
} | ||
|
||
@Priority(1) | ||
@Decorator | ||
static abstract class TrimConverterDecorator implements Converter<String, String> { | ||
@Inject | ||
@Delegate | ||
Converter<String, String> delegate; | ||
|
||
@Inject | ||
Trimmer trimmer; | ||
|
||
@Override | ||
public String convert(String value) { | ||
return delegate.convert(trimmer.trim(value)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Trimmer { | ||
public String trim(String value) { | ||
return value.trim(); | ||
} | ||
} | ||
} |
Oops, something went wrong.