1 16 17 package org.springframework.beans.factory; 18 19 import org.springframework.beans.TestBean; 20 21 24 public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFactoryTests { 25 26 27 protected ListableBeanFactory getListableBeanFactory() { 28 BeanFactory bf = getBeanFactory(); 29 if (!(bf instanceof ListableBeanFactory)) { 30 throw new IllegalStateException ("ListableBeanFactory required"); 31 } 32 return (ListableBeanFactory) bf; 33 } 34 35 38 public void testCount() { 39 assertCount(13); 40 } 41 42 protected final void assertCount(int count) { 43 String [] defnames = getListableBeanFactory().getBeanDefinitionNames(); 44 assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count); 45 } 46 47 public void testTestBeanCount() { 48 assertTestBeanCount(7); 49 } 50 51 public void assertTestBeanCount(int count) { 52 String [] defNames = getListableBeanFactory().getBeanDefinitionNames(TestBean.class); 53 assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " + 54 defNames.length, defNames.length == count); 55 56 int countIncludingFactoryBeans = count + 2; 57 String [] names = getListableBeanFactory().getBeanNamesForType(TestBean.class); 58 assertTrue("We should have " + countIncludingFactoryBeans + 59 " beans for class org.springframework.beans.TestBean, not " + names.length, 60 names.length == countIncludingFactoryBeans); 61 } 62 63 public void testGetDefinitionsForNoSuchClass() { 64 String [] defnames = getListableBeanFactory().getBeanDefinitionNames(String .class); 65 assertTrue("No string definitions", defnames.length == 0); 66 } 67 68 72 public void testGetCountForFactoryClass() { 73 assertTrue("Should have 2 factories, not " + 74 getListableBeanFactory().getBeanDefinitionNames(FactoryBean.class).length, 75 getListableBeanFactory().getBeanDefinitionNames(FactoryBean.class).length == 2); 76 77 assertTrue("Should have 2 factories, not " + 78 getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length, 79 getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2); 80 } 81 82 public void testContainsBeanDefinition() { 83 assertTrue(getListableBeanFactory().containsBeanDefinition("rod")); 84 assertTrue(getListableBeanFactory().containsBeanDefinition("roderick")); 85 } 86 87 } 88 | Popular Tags |