### Question:
BeanFactoryUtils { public static <T> List<T> getBeans(ListableBeanFactory beanFactory, String[] beanNames, Class<T> beanType) { String[] allBeanNames = beanNamesForTypeIncludingAncestors(beanFactory, beanType); List<T> beans = new ArrayList<T>(beanNames.length); for (String beanName : beanNames) { if (StringUtils.isContains(allBeanNames, beanName)) { beans.add(beanFactory.getBean(beanName, beanType)); } } return Collections.unmodifiableList(beans); }  static T getOptionalBean(ListableBeanFactory beanFactory, String beanName, Class<T> beanType); static List<T> getBeans(ListableBeanFactory beanFactory, String[] beanNames, Class<T> beanType); static boolean addApplicationListener(ApplicationContext applicationContext, ApplicationListener listener);  }### Answer:
@Test public void testGetBeans() { applicationContext.register(TestBean.class, TestBean2.class); applicationContext.refresh(); List<TestBean> testBeans = BeanFactoryUtils.getBeans(applicationContext, new String[]{"testBean"}, TestBean.class); Assertions.assertEquals(1, testBeans.size()); Assertions.assertEquals("Hello,World", testBeans.get(0).getName()); }
@Test public void testGetBeansIfAbsent() { applicationContext.refresh(); List<TestBean> testBeans = BeanFactoryUtils.getBeans(applicationContext, new String[]{"testBean"}, TestBean.class); Assertions.assertTrue(testBeans.isEmpty()); }