-
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
415 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
66 changes: 66 additions & 0 deletions
66
...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,66 @@ | ||
package io.quarkus.arc.test.decorators; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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(); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...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,62 @@ | ||
package io.quarkus.arc.test.decorators; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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(); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../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,66 @@ | ||
package io.quarkus.arc.test.decorators; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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(); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...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,73 @@ | ||
package io.quarkus.arc.test.decorators.abstractimpl; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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(); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../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,69 @@ | ||
package io.quarkus.arc.test.decorators.abstractimpl; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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.