### Question:
ExportJsProcessor extends BaseSurfaceJsProcessor implements JsProcessor { public boolean process(JsRequest jsRequest, JsResponseBuilder builder) throws JsException { JsUri jsUri = jsRequest.getJsUri(); ImmutableList.Builder<JsContent> resp = ImmutableList.builder(); FeatureRegistry featureRegistry = getFeatureRegistry(jsUri); boolean needExports = false; FeatureBundle last = null; if (!jsUri.isJsload()) { for (JsContent jsc : builder.build().getAllJsContent()) { FeatureBundle current = jsc.getFeatureBundle(); if (last != null && current != last) { needExports |= appendExportJsStatements(resp, jsUri, last); } resp.add(jsc); last = current; } if (last != null) { needExports |= appendExportJsStatements(resp, jsUri, last); } } builder.clearJs(); if (needExports) { builder.appendAllJs(getSurfaceJsContents(featureRegistry, FEATURE_NAME)); } builder.appendAllJs(resp.build()); return true; } @Inject  ExportJsProcessor(FeatureRegistryProvider featureRegistryProvider,
      Provider<GadgetContext> context); boolean process(JsRequest jsRequest, JsResponseBuilder builder);  }### Answer:
@Test public void processEmpty() throws Exception { JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL); JsRequest jsRequest = new JsRequest(jsUri, null, false, null); JsResponseBuilder jsBuilder = new JsResponseBuilder(); boolean actualReturnCode = processor.process(jsRequest, jsBuilder); assertTrue(actualReturnCode); assertEquals("", jsBuilder.build().toJsString()); }
@Test public void processWithOneText() throws Exception { JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL); JsRequest jsRequest = new JsRequest(jsUri, null, false, null); JsResponseBuilder jsBuilder = new JsResponseBuilder(); jsBuilder.appendJs(textJsContent1); boolean actualReturnCode = processor.process(jsRequest, jsBuilder); assertTrue(actualReturnCode); assertEquals( TEXT_CONTENT_1, jsBuilder.build().toJsString()); }
@Test public void processWithOneNonEmptyFeature() throws Exception { JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL); JsRequest jsRequest = new JsRequest(jsUri, null, false, null); JsResponseBuilder jsBuilder = new JsResponseBuilder(); jsBuilder.appendJs(featureJsContent1); boolean actualReturnCode = processor.process(jsRequest, jsBuilder); assertTrue(actualReturnCode); assertEquals( EXPORT_JS_DEB + FEATURE_CONTENT_1 + EXPORT_STRING_1, jsBuilder.build().toJsString()); }
@Test public void processWithOneEmptyFeature() throws Exception { JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL); JsRequest jsRequest = new JsRequest(jsUri, null, false, null); JsResponseBuilder jsBuilder = new JsResponseBuilder(); jsBuilder.appendJs(featureJsContent3); boolean actualReturnCode = processor.process(jsRequest, jsBuilder); assertTrue(actualReturnCode); assertEquals( FEATURE_CONTENT_3 + EXPORT_STRING_3, jsBuilder.build().toJsString()); }
@Test public void processWithFeaturesAndTexts() throws Exception { JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL); JsRequest jsRequest = new JsRequest(jsUri, null, false, null); JsResponseBuilder jsBuilder = new JsResponseBuilder(); jsBuilder.appendJs(textJsContent1); jsBuilder.appendJs(featureJsContent1); jsBuilder.appendJs(featureJsContent2); jsBuilder.appendJs(textJsContent2); jsBuilder.appendJs(featureJsContent3); boolean actualReturnCode = processor.process(jsRequest, jsBuilder); assertTrue(actualReturnCode); assertEquals(EXPORT_JS_DEB + TEXT_CONTENT_1 + FEATURE_CONTENT_1 + EXPORT_STRING_1 + FEATURE_CONTENT_2 + EXPORT_STRING_2 + TEXT_CONTENT_2 + FEATURE_CONTENT_3 + EXPORT_STRING_3, jsBuilder.build().toJsString()); }