### Question:
CacheEnforcementVisitor extends ResourceMutateVisitor { protected HttpRequest createNewHttpRequest(Gadget gadget, String uriStr) { HttpRequest request = new HttpRequest(Uri.parse(uriStr)); if (gadget != null) { GadgetSpec spec = gadget.getSpec(); if (spec != null) { request.setGadget(spec.getUrl()); } GadgetContext context = gadget.getContext(); if (context != null) { request.setContainer(context.getContainer()); } request.setParam(CACHE_ENFORCEMENT_FETCH_PARAM, "1"); } return request; } CacheEnforcementVisitor(ContentRewriterFeature.Config featureConfig,
                                 Executor executor,
                                 HttpCache cache,
                                 RequestPipeline requestPipeline,
                                 Tags... resourceTags); @Override VisitStatus visit(Gadget gadget, Node node); static final String CACHE_ENFORCEMENT_FETCH_PARAM; }### Answer:
@Test public void testCreateNewHttpRequest() throws Exception { Gadget gadget = createMock(Gadget.class); Uri uri = Uri.parse(GADGET); GadgetSpec gadgetSpec = createMock(GadgetSpec.class); expect(gadgetSpec.getUrl()).andReturn(uri); expect(gadget.getSpec()).andReturn(gadgetSpec); GadgetContext context = createMock(GadgetContext.class); expect(context.getContainer()).andReturn(CONTAINER); expect(gadget.getContext()).andReturn(context); replay(gadgetSpec); replay(context); replay(gadget); CacheEnforcementVisitor visitor = new CacheEnforcementVisitor( null, null, null, null, CacheEnforcementVisitor.Tags.ALL_RESOURCES); HttpRequest newRequest = visitor.createNewHttpRequest(gadget, IMG_URL); assertEquals(CONTAINER, newRequest.getContainer()); assertEquals("1", newRequest.getParam(CacheEnforcementVisitor.CACHE_ENFORCEMENT_FETCH_PARAM)); assertEquals(uri, newRequest.getGadget()); }