Reputation: 1282
I want to mock response with payload as a simple string. Below code is in my test :
Response response = mock(Response.class, RETURNS_DEEP_STUBS);
when(mockRestClient.get("someMockUrl")).thenReturn(response);
when(response.readEntity(String.class)).thenReturn("XXXYYYZZZ");
Also tried with:
Response response = Response.status(Status.OK).entity("XXXYYYZZZ").build();
MyCode looks something like this :
Response response = restClient.get(tokenUrl); // I was mocking this and getting mock response
String requestToken = response.readEntity(String.class); //failing at this line
None of the above is working. Help is Appreciated!
Upvotes: 0
Views: 1395
Reputation: 1282
I see the issue was with using the deep stubs. It was not necessary in my case.
Response mockResponse = mock(Response.class);
when(mockResponse.readEntity(String.class)).thenReturn("XXXYYYZZZ");
Upvotes: 2