### Question:
GeomajasController extends RemoteServiceServlet implements GeomajasService, ServletConfigAware { public ServletContext getServletContext() { if (null == servletContext) { throw new IllegalStateException("getServletContext() cannot be used outside web context"); } return servletContext; }  @RequestMapping("/geomajasService") ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response); @Api SerializationPolicyLocator getSerializationPolicyLocator(); @Api void setSerializationPolicyLocator(SerializationPolicyLocator serializationPolicyLocator); CommandResponse execute(GwtCommand request); ServletContext getServletContext(); void setServletConfig(ServletConfig servletConfig);  }### Answer:
@Test public void testNonWebContext() throws ServletException, IOException { MockServletConfig config = new MockServletConfig(); MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext()); MockHttpServletResponse response = new MockHttpServletResponse(); GeomajasController c = new GeomajasController(); c.init(config); try { c.doPost(request, response); Assert.fail("Should fail outside web context"); } catch (RuntimeException e) { } }