### Question:
GadgetsHandlerService { @VisibleForTesting GadgetsHandlerApi.CajaResponse createCajaResponse(Uri uri, String html, String js, List<GadgetsHandlerApi.Message> messages, Set<String> fields, Long expireMs) { ImmutableList.Builder<GadgetsHandlerApi.Message> msgBuilder = ImmutableList.builder(); for (final GadgetsHandlerApi.Message m : messages) { msgBuilder.add( beanDelegator.createDelegator(null, GadgetsHandlerApi.Message.class, ImmutableMap.<String, Object>of("name", m.getName(), "level", m.getLevel(), "message", m.getMessage()))); } return (GadgetsHandlerApi.CajaResponse) beanFilter.createFilteredBean( beanDelegator.createDelegator(null, GadgetsHandlerApi.CajaResponse.class, ImmutableMap.<String, Object>builder() .put("url", uri) .put("html", BeanDelegator.nullable(html)) .put("js", BeanDelegator.nullable(js)) .put("messages", msgBuilder.build()) .put("error", BeanDelegator.NULL) .put("responsetimems", timeSource.currentTimeMillis()) .put("expiretimems", BeanDelegator.nullable(expireMs)) .build()), fields); } @Inject  GadgetsHandlerService(TimeSource timeSource, Processor processor,
      IframeUriManager iframeUriManager, SecurityTokenCodec securityTokenCodec,
      ProxyUriManager proxyUriManager, JsUriManager jsUriManager, ProxyHandler proxyHandler,
      JsServingPipeline jsPipeline, JsRequestBuilder jsRequestBuilder,
      @Named("shindig.cache.xml.refreshInterval") long specRefreshInterval,
      BeanFilter beanFilter, CajaContentRewriter cajaContentRewriter,
      GadgetAdminStore gadgetAdminStore,
      FeatureRegistryProvider featureRegistryProvider,
      ModuleIdManager moduleIdManager,
      ContainerConfig config); GadgetsHandlerApi.MetadataResponse getMetadata(GadgetsHandlerApi.MetadataRequest request); GadgetsHandlerApi.TokenResponse getToken(GadgetsHandlerApi.TokenRequest request); GadgetsHandlerApi.JsResponse getJs(GadgetsHandlerApi.JsRequest request); GadgetsHandlerApi.ProxyResponse getProxy(GadgetsHandlerApi.ProxyRequest request); static GadgetsHandlerApi.MessageLevel convertMessageLevel(String name); GadgetsHandlerApi.CajaResponse getCaja(GadgetsHandlerApi.CajaRequest request); GadgetsHandlerApi.BaseResponse createErrorResponse(Uri uri, Exception e,
      String defaultMsg); GadgetsHandlerApi.BaseResponse createErrorResponse(Uri url, int code, String error);  }### Answer:
@Test public void testCreateCajaResponse() throws Exception { String goldenEntries[][] = { { "name1", "LINT", "msg1" }, { "name2", "LINT", "msg2" } }; List<GadgetsHandlerApi.Message> goldenMessages = Lists.newArrayList(); for (String[] goldenEntry : goldenEntries) { GadgetsHandlerApi.Message m = mock(GadgetsHandlerApi.Message.class); expect(m.getName()).andReturn(goldenEntry[0]); expect(m.getLevel()).andReturn(GadgetsHandlerApi.MessageLevel.valueOf(goldenEntry[1])); expect(m.getMessage()).andReturn(goldenEntry[2]); goldenMessages.add(m); } replay(); Uri jsUri = Uri.parse("http: GadgetsHandlerApi.CajaResponse jsResponse = gadgetHandler.createCajaResponse(jsUri, "html", "js", goldenMessages, ImmutableSet.of("*"), null); BeanDelegator.validateDelegator(jsResponse); assertEquals("html", jsResponse.getHtml()); assertEquals("js", jsResponse.getJs()); List<GadgetsHandlerApi.Message> response = jsResponse.getMessages(); assertEquals(goldenMessages.size(), response.size()); for (int i = 0; i < response.size(); i++) { assertEquals(goldenEntries[i][0], response.get(i).getName()); assertEquals(goldenEntries[i][1], response.get(i).getLevel().name()); assertEquals(goldenEntries[i][2], response.get(i).getMessage()); } }