private Set<String> getExistingBeans(ConfigurableListableBeanFactory beanFactory,
                                       MockDefinition mockDefinition) {
    QualifierDefinition qualifier = mockDefinition.getQualifier();
    Set<String> candidates = new TreeSet<>();
    for (String candidate : getExistingBeans(beanFactory,
      mockDefinition.getTypeToMock())) {
      if (qualifier == null || qualifier.matches(beanFactory, candidate)) {
        candidates.add(candidate);
      }
    }
    return candidates;
  }
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