Junit Mockito test case for ResponseEntity<?> in spring integration framework

帅比萌擦擦* 提交于 2019-12-23 09:39:05

问题


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 ?


回答1:


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);


来源:https://stackoverflow.com/questions/39015830/junit-mockito-test-case-for-responseentity-in-spring-integration-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!