@InjectMocks @ Collaboration capability
Could you please help me some code:
@ContextConfiguration(locations = { "/applicationContext.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class TestUnit2 {
@Mock
private MongoOperations mongoTemplate;
@InjectMocks
@Autowired
private WorkcircleRepositoryMongoImpl workCircleRepository;
@Autowired
private WorkcircleServiceImpl workCircleServiceImpl;
@Before
public void setUp() {
....
when(mongoTemplate.findOne(new Query(), Person.class)).thenReturn(expectedPerson);
MockitoAnnotations.initMocks(this);
}
@Test
public void test() {
... workCircleServiceImpl.find()...
}
But the test failed:
NP at the line "... workCircleServiceImpl.find () ...",
separately @InjectMocks and @Autowired work, but don't work together.
+3
source to share