### Question:
BeanDefinitions { public static Class<?> extractClass(AbstractBeanDefinition beanDefinition) { AbstractBeanDefinition abd = beanDefinition; try { Class<?> beanClazz = abd.resolveBeanClass(BEAN_CLASS_LOADER); MethodMetadata factoryMetadata = getMethodMetadata(beanDefinition); if (beanClazz != null) { return beanClazz; } else if (factoryMetadata != null) { return Class.forName(factoryMetadata.getReturnTypeName()); } else { throw new IllegalStateException( "Unable to resolve target class for BeanDefinition [" + beanDefinition + "]"); } } catch (ClassNotFoundException ex) { throw new IllegalStateException("Cannot load class: " + ex.getMessage(), ex); } } private  BeanDefinitions(); static Class<?> extractClass(AbstractBeanDefinition beanDefinition); static Map<String, Object> extractQualifiers(BeanDefinition beanDefinition);  }### Answer:
@Test void extract_class_from_java_config_bean_definition() { ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class); BeanDefinition beanDefinition = ((AnnotationConfigApplicationContext) context).getBeanDefinition("testBean"); assertThat(BeanDefinitions.extractClass((AbstractBeanDefinition) beanDefinition)).isEqualTo(Stream.class); }
@Test void extract_class_from_custom_bean_definition() { RootBeanDefinition beanDefinition = new RootBeanDefinition(); beanDefinition.setBeanClass(Stream.class); assertThat(BeanDefinitions.extractClass(beanDefinition)).isEqualTo(Stream.class); }
@Test void extract_class_throws_when_beanclass_is_not_set() { RootBeanDefinition beanDefinition = new RootBeanDefinition(); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> BeanDefinitions.extractClass(beanDefinition)) .withMessageContaining("Unable to resolve target class for BeanDefinition"); }
@Test void extract_class_throws_when_beanclass_is_not_in_classpath() { RootBeanDefinition beanDefinition = new RootBeanDefinition(); beanDefinition.setBeanClassName("missing.Someclass"); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> BeanDefinitions.extractClass(beanDefinition)) .withMessage("Cannot load class: missing.Someclass"); }