Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

It is processed in the Injection module (see org.unitils.inject.InjectModule and the classes inside org.unitils.inject.util package). Unfortunately i cannot give you the specific answer. For further information you have to debug or wait for additional answers ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top