Hi, I am trying to use Junit and Mockit to test the code(①and②) under below ,
but it didn't work well. Do you know the right way to test the the method of ApiClient and FlowsApi using Junit and could you give some advices ,thank you !
②
■Appication code
FlowsApi apiInstance = new FlowsApi();
FlowAggregationQuery flowBody= new FlowAggregationQuery();
FlowAggregateQueryResponse result = apiInstance.postAnalyticsFlowsAggregatesQuery(flowBody);
■Junit test code
FlowsApi mock = Mockito.mock(FlowsApi.class);
Mockito.when(mock.postAnalyticsFlowsAggregatesQuery(Mockito.any(FlowAggregationQuery.class))).thenThrow(new IOException());
Thank you for you advice, but it seems I didn't explain my problem correctly.
What I want to do is to mock the under below class, then when I call one of the methods in my appication I can set the return value as I expect.
■ApiClient
ApiClient apiClient1 = PowerMockito.mock(ApiClient.class);
PowerMockito.whenNew(ApiClient.class).withAnyArguments().thenReturn(apiClient1);
PowerMockito.when(apiClient1.authorizeClientCredentials(Mockito.anyString(),Mockito.anyString())).thenThrow(new IOException());
→Using PowerMockito,when I call method, I can set the resonse value like above as I expect.
My new problem is when I use PowerMockito to mock classes ,
it works well with ApiClient class above,but when I use it to mock the class following, it doesn't work.
Do you know what I am doing wrong,thank you !
■ConversationsApi
ConversationsApi apiInstance = PowerMockito.mock(ConversationsApi.class); PowerMockito.whenNew(ConversationsApi.class).withNoArguments().thenReturn(apiInstance);
PowerMockito.when(apiInstance.postAnalyticsConversationsAggregatesQuery(conversationAggregationQuery)).thenThrow(new IOException());
→I expected error but my application finished nomally. So it seems,the mock dind't work.
I would suggest asking questions about how to use PowerMockito on their community forum if they have one, or a general purpose programming forum like stack overflow. Genesys does not provide support for 3rd party frameworks.