Restored isTypeMatch null behavior and refined typeToMatch parameter name

Issue: SPR-12147
This commit is contained in:
Juergen Hoeller
2015-03-23 21:57:03 +01:00
parent 44e8f7b333
commit b2308926bc
8 changed files with 63 additions and 28 deletions

View File

@@ -1666,6 +1666,36 @@ public class DefaultListableBeanFactoryTests {
assertNull(lbf.getType("factoryBean"));
}
@Test
public void testGetBeanNamesForTypeBeforeFactoryBeanCreation() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("factoryBean", new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class.getName()));
assertFalse(lbf.containsSingleton("factoryBean"));
String[] beanNames = lbf.getBeanNamesForType(Runnable.class, false, false);
assertEquals(1, beanNames.length);
assertEquals("&factoryBean", beanNames[0]);
beanNames = lbf.getBeanNamesForType(FactoryBean.class, false, false);
assertEquals(1, beanNames.length);
assertEquals("&factoryBean", beanNames[0]);
}
@Test
public void testGetBeanNamesForTypeAfterFactoryBeanCreation() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("factoryBean", new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class.getName()));
lbf.getBean("&factoryBean");
String[] beanNames = lbf.getBeanNamesForType(Runnable.class, false, false);
assertEquals(1, beanNames.length);
assertEquals("&factoryBean", beanNames[0]);
beanNames = lbf.getBeanNamesForType(FactoryBean.class, false, false);
assertEquals(1, beanNames.length);
assertEquals("&factoryBean", beanNames[0]);
}
/**
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
* be autowired <em>by name</em>, as &amp; is an illegal character in
@@ -2862,7 +2892,7 @@ public class DefaultListableBeanFactoryTests {
}
public static class FactoryBeanThatShouldntBeCalled implements FactoryBean<Object> {
public static class FactoryBeanThatShouldntBeCalled implements FactoryBean<Object>, Runnable {
@Override
public Object getObject() {
@@ -2878,6 +2908,11 @@ public class DefaultListableBeanFactoryTests {
public boolean isSingleton() {
return false;
}
@Override
public void run() {
throw new IllegalStateException();
}
}
@@ -2993,7 +3028,6 @@ public class DefaultListableBeanFactoryTests {
private FactoryBean<?> factoryBean;
public final FactoryBean<?> getFactoryBean() {
return this.factoryBean;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -47,6 +46,7 @@ public final class FactoryBeanTests {
private static final Resource ABSTRACT_CONTEXT = qualifiedResource(CLASS, "abstract.xml");
private static final Resource CIRCULAR_CONTEXT = qualifiedResource(CLASS, "circular.xml");
@Test
public void testFactoryBeanReturnsNull() throws Exception {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
@@ -238,12 +238,12 @@ public final class FactoryBeanTests {
public void setInstanceName(String instanceName) {
this.instanceName = instanceName;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
public T getObject() {
if (instance == null) {