StreamServiceServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { process(req, resp); } catch (final IOException e) { log.error("Cannot stream request", e); } }    }
@Test public void testDoGet() throws ServletException, IOException { final int uiContextID = 1; final int streamRequestID = 2; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getParameter(ClientToServerModel.UI_CONTEXT_ID.toStringValue())).thenReturn(String.valueOf(uiContextID)); Mockito.when(request.getParameter(ClientToServerModel.STREAM_REQUEST_ID.toStringValue())) .thenReturn(String.valueOf(streamRequestID)); final Application application = new Application("0", null, null); final UIContext uiContext = Mockito.mock(UIContext.class); Mockito.when(uiContext.getID()).thenReturn(uiContextID); final StreamHandler streamListener = Mockito.mock(StreamHandler.class); Mockito.when(uiContext.removeStreamListener(streamRequestID)).thenReturn(streamListener); application.registerUIContext(uiContext); SessionManager.get().registerApplication(application); final PObject pObject = Mockito.mock(PObject.class); Mockito.when(uiContext.getObject(ArgumentMatchers.eq(streamRequestID))).thenReturn(pObject); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); streamServiceServlet.doGet(request, response); Mockito.verify(streamListener, Mockito.times(1)).onStream(request, response, uiContext); SessionManager.get().unregisterApplication(application); }