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 d007089
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -234,6 +235,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 @@ -37,6 +37,7 @@
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.mapper.child.MapperChildInterface;
import org.mybatis.spring.type.DummyMapperFactoryBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
Expand Down Expand Up @@ -385,6 +386,14 @@ void testScanWithMapperFactoryBeanClass() {
assertTrue(DummyMapperFactoryBean.getMapperCount() > 0);
}

@Test
void testMapperBeanAttribute() {
startContext();

assertThat(applicationContext.getBeanDefinition("annotatedMapper").getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE))
.isEqualTo(AnnotatedMapper.class.getName());
}

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

0 comments on commit d007089

Please sign in to comment.