Object createSpyIfNecessary(Object bean, String beanName)
    throws BeansException {
    SpyDefinition definition = this.spies.get(beanName);
    if (definition != null) {
      bean = definition.createSpy(beanName, bean);
    }
    return bean;
  }
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