### Question:
BeanDefinitionFinder { public Optional<BeanDefinition> tryToFindSingleBeanDefinition(Class<?> doubleClass) { final String[] beanNamesForType = definitionRegistry.getBeanNamesForType(doubleClass); if (beanNamesForType.length == 1) { final String beanName = getBeanDefinitionName(beanNamesForType[0]); if(doubleRegistryContainsDouble(beanName, doubleClass)) { return Optional.empty(); } return Optional.of(definitionRegistry.getBeanDefinition(beanName)); } return Optional.empty(); } BeanDefinitionFinder(ConfigurableListableBeanFactory definitionRegistry, DoubleRegistry doubleRegistry);  BeanDefinitionFinder(ApplicationContext applicationContext, DoubleRegistry doubleRegistry); Optional<BeanDefinition> tryToFindBeanDefinition(String beanName); Optional<BeanDefinition> tryToFindBeanDefinition(String beanName, Class<?> doubleClass); Optional<BeanDefinition> tryToFindSingleBeanDefinition(Class<?> doubleClass);  }### Answer:
@Test public void should_definition_by_class_only_when_single_definition_present() { final ApplicationContext appContext = buildAppContext(Stream.of(bean("string", "any bean"))); final BeanDefinitionFinder definitionFinder = new BeanDefinitionFinder(appContext, emptyDoubleRegistry()); final Optional<BeanDefinition> definition = definitionFinder.tryToFindSingleBeanDefinition(String.class); assertTrue(definition.isPresent()); }
@Test public void should_find_nothing_when_more_then_one_definition_of_class_present() { final ApplicationContext appContext = buildAppContext(Stream.of( bean("object1", new Object()), bean("object2", new Object()))); final BeanDefinitionFinder definitionFinder = new BeanDefinitionFinder(appContext, emptyDoubleRegistry()); final Optional<BeanDefinition> definition = definitionFinder.tryToFindSingleBeanDefinition(Object.class); assertFalse(definition.isPresent()); }