Support for functional instance supplier callback at BeanDefinition level
Issue: SPR-14832
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,7 @@ public class GenericApplicationContextTests {
|
||||
ac.registerBeanDefinition("testBean", new RootBeanDefinition(String.class));
|
||||
ac.refresh();
|
||||
|
||||
assertEquals("", ac.getBean("testBean"));
|
||||
assertSame(ac.getBean("testBean"), ac.getBean(String.class));
|
||||
assertSame(ac.getBean("testBean"), ac.getBean(CharSequence.class));
|
||||
|
||||
@@ -55,6 +56,31 @@ public class GenericApplicationContextTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSingletonSupplier() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
ac.registerBeanDefinition("testBean", new RootBeanDefinition(String.class, ac::toString));
|
||||
ac.refresh();
|
||||
|
||||
assertSame(ac.getBean("testBean"), ac.getBean("testBean"));
|
||||
assertSame(ac.getBean("testBean"), ac.getBean(String.class));
|
||||
assertSame(ac.getBean("testBean"), ac.getBean(CharSequence.class));
|
||||
assertEquals(ac.toString(), ac.getBean("testBean"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withScopedSupplier() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
ac.registerBeanDefinition("testBean",
|
||||
new RootBeanDefinition(String.class, RootBeanDefinition.SCOPE_PROTOTYPE, ac::toString));
|
||||
ac.refresh();
|
||||
|
||||
assertNotSame(ac.getBean("testBean"), ac.getBean("testBean"));
|
||||
assertEquals(ac.getBean("testBean"), ac.getBean(String.class));
|
||||
assertEquals(ac.getBean("testBean"), ac.getBean(CharSequence.class));
|
||||
assertEquals(ac.toString(), ac.getBean("testBean"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessAfterClosing() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
|
||||
Reference in New Issue
Block a user