Skip to content

Commit

Permalink
Set attribute that helps MockitoPostProcessor replace a MyBatis mappe…
Browse files Browse the repository at this point in the history
  • Loading branch information
harawata committed Jul 11, 2020
1 parent 2af8093 commit b1a7a5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.aop.scope.ScopedProxyFactoryBean;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
Expand Down Expand Up @@ -57,6 +58,9 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {

private static final Logger LOGGER = LoggerFactory.getLogger(ClassPathMapperScanner.class);

// Copy of FactoryBean#OBJECT_TYPE_ATTRIBUTE which was added in Spring 5.2
static final String FACTORY_BEAN_OBJECT_TYPE = "factoryBeanObjectType";

private boolean addToConfig = true;

private boolean lazyInitialization;
Expand Down Expand Up @@ -234,6 +238,10 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {

definition.getPropertyValues().add("addToConfig", this.addToConfig);

// Attribute for MockitoPostProcessor
// https://github.com/mybatis/spring-boot-starter/issues/475
definition.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, beanClassName);

boolean explicitFactoryUsed = false;
if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) {
definition.getPropertyValues().add("sqlSessionFactory",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ void testScanWithMapperFactoryBeanClass() {
assertTrue(DummyMapperFactoryBean.getMapperCount() > 0);
}

@Test
void testMapperBeanAttribute() {
startContext();

assertThat(applicationContext.getBeanDefinition("annotatedMapper").getAttribute(ClassPathMapperScanner.FACTORY_BEAN_OBJECT_TYPE))
.isEqualTo(AnnotatedMapper.class.getName());
}

private void setupSqlSessionFactory(String name) {
GenericBeanDefinition definition = new GenericBeanDefinition();
definition.setBeanClass(SqlSessionFactoryBean.class);
Expand Down

0 comments on commit b1a7a5b

Please sign in to comment.