08-02-2023, 11:49 AM
I'm using Mockito's `@Mock` and `@InjectMocks` annotations to inject dependencies into private fields which are annotated with Spring's `@Autowired`:
@RunWith(MockitoJUnitRunner.class)
public class DemoTest {
@Mock
private SomeService service;
@InjectMocks
private Demo demo;
/* ... */
}
and
public class Demo {
@Autowired
private SomeService service;
/* ... */
}
Now I would like to also inject **real** objects into private `@Autowired` fields (without setters). Is this possible or is the mechanism limited to injecting Mocks only?
@RunWith(MockitoJUnitRunner.class)
public class DemoTest {
@Mock
private SomeService service;
@InjectMocks
private Demo demo;
/* ... */
}
and
public class Demo {
@Autowired
private SomeService service;
/* ... */
}
Now I would like to also inject **real** objects into private `@Autowired` fields (without setters). Is this possible or is the mechanism limited to injecting Mocks only?