Gualtiero Testa (17) [Avatar] Offline

in the chapter 3 listings, mocks are injected manually. For example in the listing 3.10:

// test method level
final Games games = new Games();
games.em = entityManager;

Why Mockito @InjectMocks has not been used?

I usually do the following:
// class level
@InjectMocks private Games games;

// test method level
// just use games

Which is less code in the test methods and it works with both field and setter injection.
Andy Gumbrecht (9) [Avatar] Offline
Hi Gualtiero,

I just think that some of the code was written quite a while back and we missed a few 'catch up' points in the review process.

I'd probably do the same these days, but nearly always still use mocks as deep down as possible - I only mock what I 'must', rather than for convenience.

Thanks to the feedback,