2121
2222import org .apache .ibatis .BaseDataTest ;
2323import org .apache .ibatis .io .Resources ;
24+ import org .apache .ibatis .session .LocalCacheScope ;
2425import org .apache .ibatis .session .SqlSession ;
2526import org .apache .ibatis .session .SqlSessionFactory ;
2627import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
2728import org .junit .jupiter .api .Assertions ;
2829import org .junit .jupiter .api .BeforeAll ;
29- import org .junit .jupiter .api .Test ;
30+ import org .junit .jupiter .params .ParameterizedTest ;
31+ import org .junit .jupiter .params .provider .EnumSource ;
3032
3133class AssociationTypeTest {
3234
@@ -45,14 +47,22 @@ static void setUp() throws Exception {
4547 "org/apache/ibatis/submitted/associationtype/CreateDB.sql" );
4648 }
4749
48- @ Test
49- void shouldGetAUser () {
50+ @ ParameterizedTest
51+ @ EnumSource
52+ void shouldGetAUser (LocalCacheScope localCacheScope ) {
53+ sqlSessionFactory .getConfiguration ().setLocalCacheScope (localCacheScope );
5054 try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
51- List <Map > results = sqlSession .selectList ("getUser" );
52- for (Map r : results ) {
53- Assertions .assertEquals (String .class , r .get ("a1" ).getClass ());
54- Assertions .assertEquals (String .class , r .get ("a2" ).getClass ());
55+ List <Map <String , ?>> results = sqlSession .selectList ("getUser" );
56+ for (Map <String , ?> r : results ) {
57+ Object a1 = r .get ("a1" );
58+ Object a2 = r .get ("a2" );
59+ Assertions .assertEquals (String .class , a1 .getClass ());
60+ Assertions .assertEquals (String .class , a2 .getClass ());
61+ Assertions .assertSame (a1 , a2 , "The result should be put into local cache regardless of localCacheScope setting." );
5562 }
63+ } finally {
64+ // Reset the scope for other tests
65+ sqlSessionFactory .getConfiguration ().setLocalCacheScope (LocalCacheScope .SESSION );
5666 }
5767 }
5868
0 commit comments