title: how to mock a servletContext instead of Servlet or HttpServletRequest?
body: <p>I have an independent project for writing test cases; the problem is I can't mock <code>HttpServletRequest</code>, simply because in my servlet there are calls like <code>getServletContext()</code> as test cases are running from the outside servlet container. It will always return an error saying "no context found". This is just one dependency with the servlet container; there can be hundreds. For example, <code>initialContext.lookup()</code> also depends on a container. </p>
  
  <p>How can I use Mockito to write a test case in this scenario? Please don't ask for an error message; it's more of a logical problem than technical. </p>
  
  <p>Looking on the internet for tutorials makes me wonder if I am doing something seriously wrong. No one seems to have encountered this problem before... How can you mock <code>HttpServletRequest</code> without ever having <code>getServletContext()</code> called in the servlet? I mean seriously, how rare can it be?</p>