-
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.
Merge pull request #29775 from mkouba/check-normalscoped-synthetic-beans
Throw a CreationException if a normal scoped synthetic bean creates null
- Loading branch information
Showing
2 changed files
with
77 additions
and
1 deletion.
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
55 changes: 55 additions & 0 deletions
55
...a/io/quarkus/arc/test/buildextension/beans/NormalScopedSyntheticBeanProducedNullTest.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,55 @@ | ||
package io.quarkus.arc.test.buildextension.beans; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.CreationException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.BeanCreator; | ||
import io.quarkus.arc.processor.BeanRegistrar; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class NormalScopedSyntheticBeanProducedNullTest { | ||
|
||
public static volatile boolean beanDestroyerInvoked = false; | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanRegistrars(new TestRegistrar()).build(); | ||
|
||
@Test | ||
public void testCreationException() { | ||
CreationException e = assertThrows(CreationException.class, () -> { | ||
Arc.container().instance(CharSequence.class).get().length(); | ||
}); | ||
assertTrue(e.getMessage().contains("Null contextual instance was produced by a normal scoped synthetic bean"), | ||
e.getMessage()); | ||
} | ||
|
||
static class TestRegistrar implements BeanRegistrar { | ||
|
||
@Override | ||
public void register(RegistrationContext context) { | ||
context.configure(CharSequence.class).types(CharSequence.class).unremovable().scope(ApplicationScoped.class) | ||
.creator(CharSequenceCreator.class).done(); | ||
} | ||
|
||
} | ||
|
||
public static class CharSequenceCreator implements BeanCreator<CharSequence> { | ||
|
||
@Override | ||
public CharSequence create(CreationalContext<CharSequence> creationalContext, Map<String, Object> params) { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |