tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: ApplicationComposer and qualified mocks
Date Wed, 05 Apr 2017 10:28:31 GMT
Hi Xavier,


2017-04-05 12:22 GMT+02:00 Xavier Dury <kalgon@hotmail.com>:

> Hi,
>
>
> When using ApplicationComposer, I can declare mocks in my test classes
> like that:
>
>
> @Mock
>
> MyDependency myDependency;
>
>
> @MockInjector
> public Class<?> mockInjector() { return MockitoInjector.class; }
>
> But that does not seem to work with (un@Named) qualified mocks:
>
>
Hmm, MockitoInjector has no link with CDI, it is for EJB injections (which
are not using CDI/@Inject)


>
> @Mock
>
> @MyQualifier
>
> MyDependency myDependency;
>

This looks like a cdi injection but @Inject is missing


>
> Of course, I can still make a producer for the qualified mock like this:
>
> @Produces
> @MyQualifier
> MyDependency myDependency() { return Mockito.mock(MyDependency.class); }
>
> But I wanted to know if that was the only way to do it because, now, I
> have to programmatically create the mock instead of declaring it with @Mock.
>
>
The openejb-mockito extension only supports @Default and @Any qualifiers (
https://github.com/apache/tomee/blob/master/utils/openejb-mockito/src/main/java/org/apache/openejb/mockito/MockitoExtension.java)
but no real blocker to support another one. The only issue is to define how
to select an instance based on a qualifier then.

Note: @Named is not a "real" qualifier so you actually used @Default I think



> Thanks,
>
> Xavier
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message