0

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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Bala
  • 1,193
  • 2
  • 12
  • 34

2 Answers2

3

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 ;)

manne
  • 194
  • 2
  • 5
0

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.

bric3
  • 40,072
  • 9
  • 91
  • 111
  • thanks for your reply. That is a nice piece of information, but, @ InjectMock works only when we have a setter or constructor based injection in the CUT... but, in my case, I am using EJB3.x which does not need these. So, it may be an additional overhead in my case, to write a setter method in the CUT for mock injection. – Bala Nov 19 '11 at 14:35
  • Actually, Mockito 1.8.5 does field injection. Version 1.9 adds it all with setter injection then field injection if setter injection is not possible. – bric3 Nov 19 '11 at 18:30