@Before public void setUp() { control = createControl(); processor = new SeparatorCommentingProcessor(); }
public boolean process(JsRequest jsRequest, JsResponseBuilder builder) { ImmutableList.Builder<JsContent> jsBuilder = ImmutableList.builder(); FeatureBundle lastFeature = null; for (JsContent js : builder.build().getAllJsContent()) { FeatureBundle feature = js.getFeatureBundle(); // Entering a new feature, from none/text. if (lastFeature == null && feature != null) { jsBuilder.add(newComment(feature, true)); // Entering a new feature, from another feature. } else if (lastFeature != null && feature != null && lastFeature != feature) { jsBuilder.add(newComment(lastFeature, false)); jsBuilder.add(newComment(feature, true)); // Entering a text, from a feature } else if (lastFeature != null && feature == null) { jsBuilder.add(newComment(lastFeature, false)); } jsBuilder.add(js); lastFeature = feature; } // If there is a last feature. if (lastFeature != null) { jsBuilder.add(newComment(lastFeature, false)); } builder.clearJs().appendAllJs(jsBuilder.build()); return true; }
@Test public void testNoFeature() throws Exception { JsResponseBuilder builder = newBuilder(); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("", actualResponse.toJsString()); }
@Test public void testNoFeature() throws Exception { JsResponseBuilder builder = newBuilder(); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("", actualResponse.toJsString()); }
@Test public void testOneText() throws Exception { JsContent text1 = JsContent.fromText("text1", "source"); JsResponseBuilder builder = newBuilder(text1); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("text1", actualResponse.toJsString()); }
@Before public void setUp() { control = createControl(); processor = new SeparatorCommentingProcessor(); }
@Test public void testOneText() throws Exception { JsContent text1 = JsContent.fromText("text1", "source"); JsResponseBuilder builder = newBuilder(text1); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals("text1", actualResponse.toJsString()); }
@Test public void testOneFeature() throws Exception { JsContent js = JsContent.fromFeature("content", "source", mockBundle("bundle"), null); JsResponseBuilder builder = newBuilder(js); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testOneFeature() throws Exception { JsContent js = JsContent.fromFeature("content", "source", mockBundle("bundle"), null); JsResponseBuilder builder = newBuilder(js); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testNeighboringSameFeatures() throws Exception { FeatureBundle bundle = mockBundle("bundle"); JsContent js1 = JsContent.fromFeature("content1", "source1", bundle, null); JsContent js2 = JsContent.fromFeature("content2", "source2", bundle, null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content1" + "content2" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testNeighboringSameFeatures() throws Exception { FeatureBundle bundle = mockBundle("bundle"); JsContent js1 = JsContent.fromFeature("content1", "source1", bundle, null); JsContent js2 = JsContent.fromFeature("content2", "source2", bundle, null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content1" + "content2" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithoutInBetweenTexts() throws Exception { JsContent js1 = JsContent.fromFeature("content1", "source1", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source2", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithoutInBetweenTexts() throws Exception { JsContent js1 = JsContent.fromFeature("content1", "source1", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source2", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithInBetweenTexts() throws Exception { JsContent text1 = JsContent.fromText("text1", "source1"); JsContent text2 = JsContent.fromText("text2", "source2"); JsContent text3 = JsContent.fromText("text3", "source3"); JsContent js1 = JsContent.fromFeature("content1", "source4", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source5", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(text1, js1, text2, js2, text3); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "text1" + "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "text2" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n" + "text3", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithInBetweenTexts() throws Exception { JsContent text1 = JsContent.fromText("text1", "source1"); JsContent text2 = JsContent.fromText("text2", "source2"); JsContent text3 = JsContent.fromText("text3", "source3"); JsContent js1 = JsContent.fromFeature("content1", "source4", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source5", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(text1, js1, text2, js2, text3); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "text1" + "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "text2" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n" + "text3", actualResponse.toJsString()); }