Could anyone please share with me how Unitils @InjectInto or @InjectIntoByType annotations are being processed?
I have checked UnitilsJUnit4.class, which is required for processing this annotation. That in turn needs UnitilsJUnit4TestClassRunner.class which extends JUnit4ClassRunner. AFAIK, UnitilsJUnit4TestClassRunner does not have any implementation on how Unitils processes the annotation @InjectInto.
The basic idea behind this question - This annotation does not support injection of Mockito mocks. I just want to check if it is possible to to add some implementation that can do this. If there is any other direct solution that integrates Mockito with Unitils, even that is welcome.
Yeah Unitils doesn't support Mockito. However Mockito comes with handy mock injection utility annotations.
You could write in your JUnit test something like that :
@RunWith(MockitoJUnitRunner.class)
class MessageEchoerTest {
@Mock Message message;
@InjectMocks MessageEchoer messageEchoer;
}
Note that it only works with mockito mocks or spies.