### Question:
JenkinsWordCompletion extends AbstractWordCodeCompletition { @Override public Set<ProposalProvider> calculate(String source, int offset) { if (source.trim().length()==0){ return Collections.singleton(new JenkinsDSLTypeProposalProvider(JenkinsDefaultClosureKeyWords.PIPELINE)); } String parentAsText = ""; JenkinsModelBuilder builder = new JenkinsModelBuilder(new ByteArrayInputStream(source.getBytes())); BuildContext builderContext = new BuildContext(); Item item = null; try { Model model = builder.build(builderContext); item = model.getParentItemOf(offset); } catch (ModelBuilderException e) { EclipseUtil.logError("Cannot build proposal model", e, JenkinsEditorActivator.getDefault()); return Collections.emptySet(); } if (item.isRoot()){ Set<ProposalProvider> set = Collections.singleton(new JenkinsDSLTypeProposalProvider(JenkinsDefaultClosureKeyWords.PIPELINE)); return set; } parentAsText=item.getIdentifier(); List<Node> foundParents = model.findByKeyword(parentAsText); if (foundParents.isEmpty()){ return Collections.emptySet(); } return fetchChildrenProposalsForParents(source, offset, foundParents); } JenkinsWordCompletion(); @Override Set<ProposalProvider> calculate(String source, int offset); @Override void reset();  }### Answer:
@Test public void an_empty_source_will_result_in_pipeline() { Set<ProposalProvider> result = completion.calculate(source0, 0); assertFalse(result.isEmpty()); assertEquals(1,result.size()); ProposalProvider provider = result.iterator().next(); assertTrue(provider.getLabel().equals("pipeline")); List<String> template = provider.getCodeTemplate(); assertEquals(3, template.size()); Iterator<String> it = template.iterator(); assertEquals(it.next(), "pipeline {"); assertEquals(it.next(), " "+SourceCodeBuilder.CURSOR_TAG); assertEquals(it.next(), "}"); }
@Test public void an_pip_source_will_result_in_pipeline() { Set<ProposalProvider> result = completion.calculate("pip", 0); assertFalse(result.isEmpty()); assertEquals(1,result.size()); ProposalProvider provider = result.iterator().next(); assertTrue(provider.getLabel().equals("pipeline")); List<String> template = provider.getCodeTemplate(); assertEquals(3, template.size()); Iterator<String> it = template.iterator(); assertEquals(it.next(), "pipeline {"); assertEquals(it.next(), " "+SourceCodeBuilder.CURSOR_TAG); assertEquals(it.next(), "}"); }
@Test public void after_pipeline_agent_is_suggested() { Set<ProposalProvider> result = completion.calculate(source1, source1_pipeline_block_index); assertLabelFound("agent",result); }
@Test public void after_pipeline_stage_is_suggested() { Set<ProposalProvider> result = completion.calculate(source1, source1_pipeline_block_index); assertLabelFound("stages",result); }
@Test public void after_pipeline_pipeline_is_NOT_suggested() { Set<ProposalProvider> result = completion.calculate(source1, source1_pipeline_block_index); assertNOLabelFound("pipeline",result); }