private Set<String> getExistingBeans(ConfigurableListableBeanFactory beanFactory,
                                    ResolvableType type) {
    Set<String> beans = new LinkedHashSet<>(
      asList(beanFactory.getBeanNamesForType(type)));
    String resolvedTypeName = type.resolve(Object.class).getName();
    for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class)) {
      beanName = BeanFactoryUtils.transformedBeanName(beanName);
      BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
      if (resolvedTypeName.equals(beanDefinition.getAttribute(FACTORY_BEAN_OBJECT_TYPE))) {
        beans.add(beanName);
      }
    }

    beans.removeIf(this::isScopedTarget);
    return beans;
  }
Factory method used by defined beans to actually create the mock.

@param mockDefinition the mock definition
@param name the bean name
@return the mock instance
spock-spring/src/main/java/org/spockframework/spring/mock/SpockMockPostprocessor.java