### Question:
GroovyChange extends Change { public static Map<String, Object> createShellContext(ApplicationContext applicationContext, Log4JPrintStream output) { final Map<String, Object> shellContext = new HashMap<>(); shellContext.put("ctx", applicationContext); shellContext.put("spring", applicationContext); bindSpringBeans(applicationContext, shellContext); shellContext.put("out", output); return shellContext; } GroovyChange(ChangeBasic changeBasic, ChangeDependency changeDependency); static Map<String, Object> createShellContext(ApplicationContext applicationContext,
                                                         Log4JPrintStream output);  }### Answer:
@Test public void shouldBindApplicationContextForVersionsUpTo5() { Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertEquals(shellContext.get("ctx"), applicationContext); }
@Test public void shouldBindApplicationContextForVersions6() { Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertEquals(shellContext.get("spring"), applicationContext); }
@Test public void shouldBindSpringBeans() { TestBean bean1 = prepareBean("bean1"); TestBean bean2 = prepareBean("bean2"); given(applicationContext.getBeanDefinitionNames()).willReturn(new String[]{ bean1.name(), bean2.name() }); Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertEquals(shellContext.get(bean1.name()), bean1); assertEquals(shellContext.get(bean2.name()), bean2); }
@Test public void shouldNotBindAbstractSpringBeans() { TestBean bean = prepareBean("bean1"); TestBean abstractBean = prepareBean("abstractBean", true); given(applicationContext.getBeanDefinitionNames()).willReturn(new String[]{ bean.name(), abstractBean.name() }); Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertFalse(shellContext.containsKey("abstractBean")); }
@Test public void shouldNotBindSpringBeansWithQualifiedName() { TestBean bean = prepareBean("bean"); TestBean qualified = prepareBean("package.bean"); given(applicationContext.getBeanDefinitionNames()).willReturn(new String[]{ bean.name(), qualified.name() }); Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertFalse(shellContext.containsKey("abstractBean")); }
@Test public void shouldNotBindSpringBeansUnderAlias() { TestBean bean = prepareBean("bean"); TestBean beanWithAlias = prepareBean("beanWithAlias"); given(applicationContext.getBeanDefinitionNames()).willReturn(new String[]{ bean.name(), beanWithAlias.name() }); given(applicationContext.getAliases(beanWithAlias.name())).willReturn(new String[] {"beanAlias" }); Map<String, Object> shellContext = GroovyChange.createShellContext(applicationContext, out); assertFalse(shellContext.containsKey("beanWithAlias")); assertTrue(shellContext.containsKey("bean")); assertTrue(shellContext.containsKey("beanAlias")); }