0

我目前正在尝试使用 power mockito 测试打印到 servlet 输出流的内容,但我找不到任何方法。

这是我到目前为止所拥有的

Routing routingMock = PowerMockito.mock( Routing.class );
HttpServletRequest httpRequestMock = PowerMockito.mock( HttpServletRequest.class );        

HttpServletResponse httpServletResponseMock = PowerMockito.mock( HttpServletResponse.class );
PowerMockito.when( httpRequestMock.getPathInfo() ).thenReturn( "/Users" );         
ServletOutputStream outputStreamMock = PowerMockito.mock( ServletOutputStream.class );

PowerMockito.when( httpServletResponseMock.getOutputStream() ).thenReturn( outputStream );
routingMock.doGet( httpRequestMock, httpServletResponseMock );

谁能帮我弄清楚如何访问写入 outputStreamMock 的数据?

谢谢

4

1 回答 1

0

据我所知以及我对 power mockito 的经验。您必须自己在输出流中填写数据,然后返回。

就像在下面的语句中一样,对于输出流;填写数据,即将您需要的数据写入流,然后返回。

PowerMockito.when(httpServletResponseMock.getOutputStream()).thenReturn(outputStream);

于 2015-11-03T14:36:43.073 回答