@Test public void getContextPath() throws Exception { GetPropertiesServlet servlet = new GetPropertiesServlet(); servlet.setJettyMode( true ); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); when( mockHttpServletRequest.getContextPath() ).thenReturn( GetPropertiesServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( "xml" ) ).thenReturn( "Y" ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockHttpServletResponse.getOutputStream() ).thenReturn( new ServletOutputStream() { private ByteArrayOutputStream baos = new ByteArrayOutputStream(); @Override public void write( int b ) throws IOException { baos.write( b ); } public String toString() { return baos.toString(); } } ); servlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); Assert.assertFalse( mockHttpServletResponse.getOutputStream().toString() .startsWith( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ) ); }
@Override public String getContextPath() { return CONTEXT_PATH; }
GetPropertiesServlet extends BodyHttpServlet { @Override public String getContextPath() { return CONTEXT_PATH; } }
GetPropertiesServlet extends BodyHttpServlet { @Override public String getContextPath() { return CONTEXT_PATH; }  }
GetPropertiesServlet extends BodyHttpServlet { @Override public String getContextPath() { return CONTEXT_PATH; }  @Override String getContextPath(); }
GetPropertiesServlet extends BodyHttpServlet { @Override public String getContextPath() { return CONTEXT_PATH; }  @Override String getContextPath(); static final String CONTEXT_PATH; }