### Question:
BeanFactoryHelper { public <T> Map<String, T> collectToOrderedMap(ListableBeanFactory beanFactory, Class<T> clazz, List<T> orderedBeans) { Map<String, T> beansOfType = beanFactory.getBeansOfType(clazz); return orderedBeans.stream() .collect(toMap( bean -> buildKey(beansOfType, bean), identity(), this::mergeBeans, LinkedHashMap::new )); }  static BeanFactoryHelper getInstance(); Map<String, T> collectToOrderedMap(ListableBeanFactory beanFactory, Class<T> clazz, List<T> orderedBeans); Map<String, String> getAliases(ListableBeanFactory beanFactory, Class<T> clazz);  }### Answer:
@Test public void collectToOrderedMap() { Map<String, Printer> printers = beanFactoryHelper.collectToOrderedMap(applicationContext, Printer.class, orderedPrinters); Set<Map.Entry<String, Printer>> entries = printers.entrySet(); assertThat(entries, hasSize(3)); Iterator<Map.Entry<String, Printer>> iterator = entries.iterator(); Map.Entry<String, Printer> entry = iterator.next(); assertThat(entry.getKey(), is("one")); assertThat(entry.getValue(), is(applicationContext.getBean("one"))); Map.Entry<String, Printer> entry1 = iterator.next(); assertThat(entry1.getKey(), is("zero")); assertThat(entry1.getValue(), is(applicationContext.getBean("zero"))); Map.Entry<String, Printer> entry2 = iterator.next(); assertThat(entry2.getKey(), is("two")); assertThat(entry2.getValue(), is(applicationContext.getBean("two"))); }