I have something like this
@Component
public class TestController {
@Autowired
private TestService testService;
public String getSomething(String parameter1) {
return testService.fetchSomething(parameter1);
}
}
And I am covering it with tests and have the following problem:
@RunWith(MockitoJUnitRunner.class)
public class TestControllerTest {
private static TestService testService = mock(TestService.class);
@InjectMocks
private static TestController testController = new TestController();
....
}
These fields are static because I need them for @ClassRule.
The problem is that in this case injection doesn't work, and testService is null in testController.
Is it possible to provide injection into static object (without constructor creation in Controller)? Or maybe there is another workaround for this?
The question is not about mocking static methods, but injecting mocks into static objects Will appreciate any advice, thanks.