21
21
22
22
import org .apache .ibatis .BaseDataTest ;
23
23
import org .apache .ibatis .io .Resources ;
24
+ import org .apache .ibatis .session .LocalCacheScope ;
24
25
import org .apache .ibatis .session .SqlSession ;
25
26
import org .apache .ibatis .session .SqlSessionFactory ;
26
27
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
27
28
import org .junit .jupiter .api .Assertions ;
28
29
import 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 ;
30
32
31
33
class AssociationTypeTest {
32
34
@@ -45,14 +47,22 @@ static void setUp() throws Exception {
45
47
"org/apache/ibatis/submitted/associationtype/CreateDB.sql" );
46
48
}
47
49
48
- @ Test
49
- void shouldGetAUser () {
50
+ @ ParameterizedTest
51
+ @ EnumSource
52
+ void shouldGetAUser (LocalCacheScope localCacheScope ) {
53
+ sqlSessionFactory .getConfiguration ().setLocalCacheScope (localCacheScope );
50
54
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." );
55
62
}
63
+ } finally {
64
+ // Reset the scope for other tests
65
+ sqlSessionFactory .getConfiguration ().setLocalCacheScope (LocalCacheScope .SESSION );
56
66
}
57
67
}
58
68
0 commit comments