do you use openejb-mockito? there is a MockitoExtension which does that.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2016-03-14 15:56 GMT+01:00 Xavier Dury <[email protected]>:

> Hi Romain,
>
> I think that the @CdiExtensions is causing the problem: if I remove it,
> the test passes without the need of the @Produces annotation.
>
> Xavier
>
> ----------------------------------------
> > From: [email protected]
> > Date: Mon, 14 Mar 2016 15:35:41 +0100
> > Subject: Re: ApplicationComposer and Mockito
> > To: [email protected]
> >
> > Mockito is not wired for CDI OOTB since it is easy to control it: you
> would
> > need a @produces on the field.
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> | Blog
> > <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com>
> >
> > 2016-03-14 15:25 GMT+01:00 Xavier Dury <[email protected]>:
> >
> >> Hi,
> >>
> >> When using ApplicationComposer and mockito together in the following
> test
> >> example:
> >>
> >> package eg;
> >>
> >> import javax.inject.Inject;
> >>
> >> import org.apache.openejb.junit.ApplicationComposerRule;
> >> import org.apache.openejb.mockito.MockitoInjector;
> >> import org.apache.openejb.testing.CdiExtensions;
> >> import org.apache.openejb.testing.MockInjector;
> >> import org.apache.openejb.testing.Module;
> >> import org.junit.Rule;
> >> import org.junit.Test;
> >> import org.junit.rules.TestRule;
> >> import org.mockito.Mock;
> >> import org.mockito.Mockito;
> >>
> >> public @CdiExtensions class MyTest {
> >>
> >> public interface MyDependency {
> >>
> >> void call();
> >> }
> >>
> >> public static class MyBean {
> >>
> >> private @Inject MyDependency myDependency;
> >>
> >> public void doSomething() {
> >> myDependency.call();
> >> }
> >> }
> >>
> >> public final @Rule TestRule composer = new
> >> ApplicationComposerRule(this);
> >>
> >> public @Module Class<?> beanClass() {
> >> return MyBean.class;
> >> }
> >>
> >> public @MockInjector Class<?> mockInjector() {
> >> return MockitoInjector.class;
> >> }
> >>
> >> private @Mock MyDependency myDependency;
> >> private @Inject MyBean myBean;
> >>
> >> public @Test void test() {
> >> myBean.doSomething();
> >> Mockito.verify(myDependency).call();
> >> }
> >> }
> >>
> >> I get the following exception:
> >>
> >> SEVERE - CDI Beans module deployment failed
> >> org.apache.webbeans.exception.WebBeansDeploymentException:
> >> javax.enterprise.inject.UnsatisfiedResolutionException: Api type
> >> [eg.MyTest$MyDependency] is not found with the qualifiers
> >> Qualifiers: [@javax.enterprise.inject.Default()]
> >> for injection into Field Injection Point, field name : myDependency,
> Bean
> >> Owner : [MyBean, WebBeansType:MANAGED, Name:null, API
> >> Types:[eg.MyTest$MyBean,java.lang.Object],
> >>
> Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
> >> at
> >> org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:325)
> >> at
> >>
> org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:196)
> >> at
> >>
> org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:193)
> >> at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
> >> at
> >>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:895)
> >> at
> >>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:694)
> >> at
> >>
> org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:690)
> >> at
> >>
> org.apache.openejb.testing.ApplicationComposers.deployApp(ApplicationComposers.java:721)
> >> at
> >>
> org.apache.openejb.testing.ApplicationComposers.before(ApplicationComposers.java:383)
> >> at
> >>
> org.apache.openejb.testing.ApplicationComposers.evaluate(ApplicationComposers.java:1060)
> >> at
> >>
> org.apache.openejb.junit.DeployApplication.evaluate(DeployApplication.java:40)
> >> at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> >> Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api
> >> type [eg.MyTest$MyDependency] is not found with the qualifiers
> >> Qualifiers: [@javax.enterprise.inject.Default()]
> >> for injection into Field Injection Point, field name : myDependency,
> Bean
> >> Owner : [MyBean, WebBeansType:MANAGED, Name:null, API
> >> Types:[eg.MyTest$MyBean,java.lang.Object],
> >>
> Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]]
> >> at
> >>
> org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:65)
> >> at
> >>
> org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:234)
> >> at
> >>
> org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1199)
> >> at
> >> org.apache.webbeans.util.WebBeansUtil.validate(WebBeansUtil.java:1709)
> >> at
> >>
> org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:909)
> >> at
> >>
> org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:820)
> >> at
> >> org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:305)
> >> ... 26 more
> >>
> >> I swear I had this working before without problem. Am I missing
> something?
> >> I am using 7.0M3.
> >>
> >> Thanks,
> >>
> >> Xavier
>
>

Reply via email to