I have a Spring boot project which has a suite of unit tests which use mockito's @InjectMocks to both instantiate the class being tested and inject any mocks which may be present into it.
In other words if I have this
@InjectMocks MyClass myClass;
Then I do not need
MyClass myClass = New MyClass();
or @Autowired MyClass myClass;
Until now this setup worked fine.
However more recently it has become necessary to have access to the projects spring boot properties when running tests. This means it has been necessary to use the SpringBoot task runner inside tests so that any instances of @Autowire (including those which instantiate the Environment class) work.
I discovered that if @InjectMocks is used to instantiate a class then any instances of @Autowired inside the class do not work (the object they should create is null). This means no Environment class and no access to Spring properties.
Instead i have to add @Autowired to the @InjectMocks annotation
so this
@InjectMocks MyClass myClass;
becomes this
@Autowired
@InjectMocks MyClass myClass;
My question is simple. Is there anything wrong with doing this? Does it double instantiate myClass or do anything that may causes glitches