final HttpClient httpClient;
final HttpUtils httpUtils;
@Autowired
public SampleConstructor(HttpUtils httpUtils) {
this.httpClient = ApacheHttpSingleton.getHttpClient();
this.httpUtils = httpUtils;
}
So I have this class having two objects which I am initializing using the autowired constructor. While writing the JUnit tests for this class, I have to mock the two objects. The HttpUtils object is straightforward. However, it's the HttpClient object I am having trouble mocking.
@Mock
HttpUtils mockHttpUtils;
@Mock
HttpClient mockHttpClient;
@InjectMocks
SampleConstructor mockService;
The above approach works for HttpUtils but not for HttpClient. Can someone please help me with how I can inject the mocked object for HttpClient?