14

I am trying to mock the external call.

 ResponseEntity<?> httpResponse = requestGateway.pushNotification(xtifyRequest);

requestGateway is an interface.

public interface RequestGateway
{
ResponseEntity<?> pushNotification(XtifyRequest xtifyRequest);
}

Below is the test method i am trying to do.

 @Test
public void test()
{


    ResponseEntity<?> r=new ResponseEntity<>(HttpStatus.ACCEPTED);

    when(requestGateway.pushNotification(any(XtifyRequest.class))).thenReturn(r);
}

A compilation error is there in the above when statement,saying it as an invalid type.even thougg r is of type ResponseEntity.

Can anyone please help me to solve this issue ?

Jill
  • 163
  • 1
  • 5
  • 20

1 Answers1

17

You can instead use the type-unsafe method

doReturn(r).when(requestGateway.pushNotification(any(XtifyRequest.class)));

Or you can remove the type info while mocking

ResponseEntity r=new ResponseEntity(HttpStatus.ACCEPTED);
when(requestGateway.pushNotification(any(XtifyRequest.class))).thenReturn(r);
Nithish Thomas
  • 1,515
  • 14
  • 20