-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automagically add no-args constructor to synthetic beans.
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...t/java/io/quarkus/arc/test/unproxyable/SynthProxiableBeanWithoutNoArgConstructorTest.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,85 @@ | ||
package io.quarkus.arc.test.unproxyable; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Vetoed; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
import io.quarkus.arc.deployment.BeanRegistrarBuildItem; | ||
import io.quarkus.arc.processor.BeanRegistrar; | ||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.gizmo.MethodDescriptor; | ||
import io.quarkus.gizmo.ResultHandle; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class SynthProxiableBeanWithoutNoArgConstructorTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(SynthBean.class)) | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
|
||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
|
||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new BeanRegistrarBuildItem(new BeanRegistrar() { | ||
@Override | ||
public void register(RegistrationContext context) { | ||
context.configure(SynthBean.class) | ||
.scope(ApplicationScoped.class) | ||
.types(SynthBean.class) | ||
.unremovable() | ||
.creator(mc -> { | ||
ResultHandle ret = mc.newInstance( | ||
MethodDescriptor.ofConstructor(SynthBean.class, String.class), | ||
mc.load("foo")); | ||
mc.returnValue(ret); | ||
}) | ||
.done(); | ||
} | ||
})); | ||
} | ||
}).produces(BeanRegistrarBuildItem.class).build(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void testSyntheticBean() { | ||
InstanceHandle<SynthBean> instance = Arc.container().instance(SynthBean.class); | ||
assertTrue(instance.isAvailable()); | ||
assertEquals("foo", instance.get().getString()); | ||
} | ||
|
||
@Vetoed | ||
static class SynthBean { | ||
private String s; | ||
|
||
public SynthBean(String s) { | ||
this.s = s; | ||
} | ||
|
||
public String getString() { | ||
return s; | ||
} | ||
} | ||
} |
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