### Question:
ProxyServlet extends InjectedServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { if (request.getHeader("If-Modified-Since") != null) { servletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } Uri reqUri = new UriBuilder(request).toUri(); HttpResponse response = null; try { ProxyUriManager.ProxyUri proxyUri = proxyUriManager.process(reqUri); String host = request.getHeader("Host"); if (!lockedDomainService.isSafeForOpenProxy(host)) { Uri resourceUri = proxyUri.getResource(); String msg = "Embed request for url " + (resourceUri != null ? resourceUri.toString() : "n/a") + " made to wrong domain " + host; LOG.info(msg); throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, msg, HttpResponse.SC_BAD_REQUEST); } response = proxyHandler.fetch(proxyUri); } catch (GadgetException e) { response = ServletUtil.errorResponse(new GadgetException(e.getCode(), e.getMessage(), HttpServletResponse.SC_BAD_REQUEST)); } ServletUtil.copyResponseToServlet(response, servletResponse); }  @Inject void setProxyHandler(ProxyHandler proxyHandler); @Inject void setProxyUriManager(ProxyUriManager proxyUriManager); @Inject void setLockedDomainService(LockedDomainService lockedDomainService);  }### Answer:
@Test public void testIfModifiedSinceAlwaysReturnsEarly() throws Exception { expect(request.getHeader("If-Modified-Since")).andReturn("Yes, this is an invalid header"); replay(); servlet.doGet(request, recorder); verify(); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, recorder.getHttpStatusCode()); assertFalse(rewriter.responseWasRewritten()); }
@Test public void testDoGetNormal() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andReturn(new HttpResponse(RESPONSE_BODY)); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY); }
@Test public void testDoGetHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetException() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doGet(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test public void testDoGetNormalWithLockedDomainUnsafe() throws Exception { setupRequest(BASIC_SYNTAX_URL, false); replay(); servlet.doGet(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains("wrong domain", recorder.getResponseAsString()); }