yskumar007 / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Make injection dependency resolver configurable #291

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Provide a way to change the dependency resolving mechanism. Note however that 
the injection engine is already configurable.

Original issue reported on code.google.com by brice.du...@gmail.com on 8 Nov 2011 at 2:28

GoogleCodeExporter commented 9 years ago
Actually instead of that, we could just pass use injection strategy, this a bit 
like higher level. Because we don't want Mockito to be a DI framework. Passing 
a strategy does seem to be more relevant.

We could write something like :

@InjectMocks(applying = ConstructorInjection.class)

@InjectMocks(applying = YourCustomInjectionStrategy.class)

Original comment by brice.du...@gmail.com on 17 Feb 2012 at 10:14

GoogleCodeExporter commented 9 years ago
The only issue with this way of configuring the strategy in the annotation is 
the custom strategy itself cannot have configurable state as the annotation 
members are required to be constants by language design.

Original comment by brice.du...@gmail.com on 17 Feb 2012 at 10:18

GoogleCodeExporter commented 9 years ago
I wonder what's the use case. Do you have a need for separate injection 
strategies in different tests?

Original comment by szcze...@gmail.com on 18 Feb 2012 at 10:00

GoogleCodeExporter commented 9 years ago
We discussed it a bit in this thread on the mailing list : 
http://groups.google.com/group/mockito/browse_thread/thread/bdec413595d4a57b/37a
379ea7f0b9105

Marek and his mockaroo project might be interested by this feature for example.

However we could avoid this annotation injection and use the ServiceLoader 
alike stuff ?

Original comment by brice.du...@gmail.com on 19 Feb 2012 at 1:58

GoogleCodeExporter commented 9 years ago
I'm not opposing the feature - just thinking on what would be best for the 
user. The necessity to decide on the kind of injection per test feels a bit 
awkward. It feels that making the injection smarter or make it easily 
configurable per project is the way to go. Just loud thinking :)

Original comment by szcze...@gmail.com on 20 Feb 2012 at 1:56

GoogleCodeExporter commented 9 years ago
Mmmh I think it should be configurable per test. If someone want to ensure 
constructor injection on specific objects, it seems like the right thing to do.

Plus it allows to use a custom strategy, for things like '@Collaborator2'.

About project wise configuration : using MockitoConfiguration or a 
ServiceLoader could be the way to go.

Original comment by brice.du...@gmail.com on 20 Feb 2012 at 2:20

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 3 Sep 2012 at 10:00