Reputation: 21
i have class which has doGet and doPost methods. In that methods am passibg string values and used httpclient.execute method to execute the get or post requests with headers and authentication info.
But i want to write junit for this class, when i try to mock using mocito, am getting only null response.
Please guide me how to add junit with httpclient.execute method.
Upvotes: 0
Views: 1350
Reputation: 509
In my unit test class I do somethig like this:
@Mock private HttpClient httpClient;
Then for example in @Before
method create mocks by:
MockitoAnnotations.initMocks(MyTestClass);
Then in a test method you define what execute()
method should return:
when(httpClient.execute(any())).thenReturn(JSON object);
You can also try to use PowerMockito. Or provide the code to better understand the question.
Upvotes: 1