2016-08-18 27 views
1

我试图模拟外部调用。Junit Mockito ResponseEntity的测试用例<?>在弹簧集成框架

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

requestGateway是一个接口。

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

下面是我试图做的测试方法。

@Test 
public void test() 
{ 


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

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

编译错误是没有在上面时声明,称它是无效type.even thougg r是类型ResponseEntity的。

任何人都可以请帮我解决这个问题吗?

回答

4

可以代替使用类型不安全的方法

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

或在嘲讽

ResponseEntity r=new ResponseEntity(HttpStatus.ACCEPTED); 
when(requestGateway.pushNotification(any(XtifyRequest.class))).thenReturn(r); 
你可以删除类型信息