You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By accident a tests delares a field of an interface type instead of the implementing class.
@InjectMocks
public InterfaceType unitUnderTest;
Injection is not possible on interfaces or enums. The error message should make this clear, the currenta message that doesn't help much:
org.mockito.exceptions.base.MockitoException:
Cannot instantiate @InjectMocks field named 'configurationManager'.
You haven't provided the instance at field declaration so I tried to construct the instance.
However, I failed because: the type 'ConfigurationManager' is an interface.
Examples of correct usage of @InjectMocks:
@InjectMocks Service service = new Service();
@InjectMocks Service service;
//also, don't forget about MockitoAnnotations.initMocks();
//and... don't forget about some @Mocks for injection :)
The error message should be someting like: The field 'unitUnderTest' can not be annotated with @InjectMocks cause the type 'InterfaceType ' not a class!
The text was updated successfully, but these errors were encountered:
By accident a tests delares a field of an interface type instead of the implementing class.
Injection is not possible on interfaces or enums. The error message should make this clear, the currenta message that doesn't help much:
The error message should be someting like:
The field 'unitUnderTest' can not be annotated with @InjectMocks cause the type 'InterfaceType ' not a class!
The text was updated successfully, but these errors were encountered: