AjaxServlet 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 pObjectID = 2; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getHeader(ClientToServerModel.UI_CONTEXT_ID.name())).thenReturn(String.valueOf(uiContextID)); Mockito.when(request.getHeader(ClientToServerModel.OBJECT_ID.name())).thenReturn(String.valueOf(pObjectID)); final Application application = new Application("0", null, null); final UIContext uiContext = Mockito.mock(UIContext.class); Mockito.when(uiContext.getID()).thenReturn(uiContextID); Mockito.when(uiContext.isAlive()).thenReturn(true); Mockito.when(uiContext.execute(ArgumentMatchers.any(Runnable.class))).thenCallRealMethod(); application.registerUIContext(uiContext); SessionManager.get().registerApplication(application); final PObject pObject = Mockito.mock(PObject.class); Mockito.when(uiContext.getObject(ArgumentMatchers.eq(pObjectID))).thenReturn(pObject); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); UIContext.setCurrent(uiContext); ajaxServlet.doGet(request, response); SessionManager.get().unregisterApplication(application); UIContext.setCurrent(null); }