JUNIT test for custom rest Endpoint using Mockito

cancel
Showing results for 
Search instead for 
Did you mean: 
Laxmi
Member II

JUNIT test for custom rest Endpoint using Mockito

I am following APS Junit  for testing aps custom logic.

I have JavaDelegate and  signal class.

I have custom endpoint which is calling third party api to fetch data, for that How Can I create UNIT Test case? without using Integration Testing and Using Mockito.

Any help would be appreciated.

 

Thanks&Regards,

Laxmi Mounika Boorela

1 Reply
abhinavmishra14
Advanced

Re: JUNIT test for custom rest Endpoint using Mockito

I would just mock a sample response into mockito unit test case. In mockito framework its all about mocking, so if a service is expecting some response from third party or from a web url, we just mock a sample response to valiate all positive/negative test scenarios. 

Example:

public void testBlah() throws Exception {
    	
		.......
		......
    	final String endPoint = "https://example.com/getJson/xyzabc123";
		when(blahService.getJson(endPoint))
				.thenReturn(new JSONObject(getMockedResourceAsString("/files/test-sample.json")));
    	.....
        .....		
}
~Abhinav
(ACSCE, AWS SAA, Azure Admin)