123124125126127128129130131132133
{ target = LazyInitProxyFactory.createProxy(field.getType(), locator); } else { target = locator.locateProxyTarget(); } // only put the proxy into the cache if the bean is a singleton if (locator.isSingletonBean()) {
124125126127128129130131132133134
5859606162636465666768
Bean bean = new Bean(); ctx.putBean("bean", bean); SpringBeanLocator locator = new SpringBeanLocator(Bean.class, ctxLocator); assertTrue(locator.locateProxyTarget() == bean); } /** * tests if lookup by class is still working after deserialization */
7374757677787980818283
ctx.putBean("bean", bean); SpringBeanLocator locator = (SpringBeanLocator) Objects .cloneObject(new SpringBeanLocator(Bean.class, ctxLocator)); assertNotNull(locator.locateProxyTarget()); } /** * tests error if bean with class is not in the context */
8485868788899091929394
public void testLookupByClassNotFound() { SpringBeanLocator locator = new SpringBeanLocator(Bean.class, ctxLocator); try { locator.locateProxyTarget(); fail(); } catch (IllegalStateException e) { // noop
105106107108109110111112113114115
ctx.putBean("somebean2", bean); SpringBeanLocator locator = new SpringBeanLocator(Bean.class, ctxLocator); try { locator.locateProxyTarget(); fail(); } catch (IllegalStateException e) { // noop
{ Bean bean = new Bean(); ctx.putBean("bean", bean); SpringBeanLocator locator = new SpringBeanLocator("bean", Bean.class, ctxLocator); assertTrue(locator.locateProxyTarget() == bean); } /** * tests lookup by name after locator has been deserialized
139140141142143144145146147148149
ctx.putBean("bean", bean); SpringBeanLocator locator = (SpringBeanLocator) Objects .cloneObject(new SpringBeanLocator("bean", Bean.class, ctxLocator)); assertNotNull(locator.locateProxyTarget()); } /** * tests error if no bean with name found */
150151152153154155156157158159160
public void testLookupByNameNotFound() { SpringBeanLocator locator = new SpringBeanLocator("bean", Bean.class, ctxLocator); try { locator.locateProxyTarget(); fail(); } catch (IllegalStateException e) { // noop
194195196197198199200201202203204
{ SpringContextLocatorMock ctxLocator = new SpringContextLocatorMock(null); SpringBeanLocator locator = new SpringBeanLocator(Bean.class, ctxLocator); try { locator.locateProxyTarget(); } catch (IllegalStateException e) { // noop }