### Question:
MapperFactoryBean extends SqlSessionDaoSupport implements FactoryBean<T> { @Override public T getObject() throws Exception { return getSqlSession().getMapper(this.mapperInterface); } MapperFactoryBean();  MapperFactoryBean(Class<T> mapperInterface); @Override T getObject(); @Override Class<T> getObjectType(); @Override boolean isSingleton(); void setMapperInterface(Class<T> mapperInterface); Class<T> getMapperInterface(); void setAddToConfig(boolean addToConfig); boolean isAddToConfig();  }### Answer:
@Test void testAddToConfigTrue() throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDatabaseIdProvider(null); factoryBean.setDataSource(dataSource); factoryBean.setPlugins(new Interceptor[] { executorInterceptor }); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); find(new SqlSessionTemplate(sqlSessionFactory), true); assertCommit(); assertSingleConnection(); assertExecuteCount(1); }
@Test void testAddToConfigFalse() throws Throwable { try { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); assertThrows(org.apache.ibatis.binding.BindingException.class, () -> find(new SqlSessionTemplate(sqlSessionFactory), false) ); } catch (MyBatisSystemException mbse) { throw mbse.getCause(); } finally { connection.close(); } }
@Test public void testAddToConfigTrue() throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDatabaseIdProvider(null); factoryBean.setDataSource(dataSource); factoryBean.setPlugins(new Interceptor[] { executorInterceptor }); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); find(new SqlSessionTemplate(sqlSessionFactory), true); assertCommit(); assertSingleConnection(); assertExecuteCount(1); }
@Test(expected = org.apache.ibatis.binding.BindingException.class) public void testAddToConfigFalse() throws Throwable { try { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); find(new SqlSessionTemplate(sqlSessionFactory), false); fail("TestDao's mapper xml should not be loaded"); } catch (MyBatisSystemException mbse) { throw mbse.getCause(); } finally { connection.close(); } }