private String determineBeanName(Collection<String> existingBeans, SpyDefinition definition,
                                   BeanDefinitionRegistry registry) {
    if (StringUtils.hasText(definition.getName())) {
      return definition.getName();
    }
    if (existingBeans.size() == 1) {
      return existingBeans.iterator().next();
    }
    return determinePrimaryCandidate(registry, existingBeans, definition.getTypeToSpy());
  }
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