dhamini-poornachandra / mockito

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

InjectionStrategys not working if non-default constructor doesn't match @Mock arguments #420

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
===== What steps will reproduce the problem?
1. Create a non-default constructor for a class (constructor must not fit the 
@Mock instances from 2.)
2. write a test using MockitoTestRunner with a few @Mock annotated members
3. org.mockito.internal.util.reflection.FieldInitializer:259 will only check if 
the constructor is parametrized, but not if it fits the provided @Mock arguments

===== What is the expected output? What do you see instead?
I'd expect that Mockito would move on to the next injection strategy, since the 
constructor does not fit the injection requirements.
Instead org.mockito.internal.util.reflection.FieldInitializer:242 will set 
"wasInitializedUsingConstructorArgs" to "true", causing injection to fail, 
because subsequent strategies won't be executed.

===== What version of the product are you using? On what operating system?
1.9.5

Original issue reported on code.google.com by reinhard...@gmail.com on 14 Feb 2013 at 5:47

GoogleCodeExporter commented 8 years ago
Hi

Sorry to reply this late. Well actually this is designed this way because, the 
type that needs injection is not a mock, and if the constructor is designed way 
it must be for a reason, so the injection strategy respect the design of this 
class.

Overriding this might prove more problematic than writing ourself the 
instantiation code.

So this enhancement won't happen in mockito. Though it might worth to mention 
it in the javadoc.

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 3:38

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 4:19