15
15
*/
16
16
package org .apache .ibatis .builder ;
17
17
18
- import java .io .Reader ;
19
- import org .apache .ibatis .builder .xml .XMLConfigBuilder ;
20
- import org .apache .ibatis .io .Resources ;
21
18
import org .apache .ibatis .mapping .BoundSql ;
22
19
import org .apache .ibatis .mapping .SqlSource ;
23
20
import org .apache .ibatis .session .Configuration ;
24
21
import org .junit .jupiter .api .Assertions ;
25
- import org .junit .jupiter .api .BeforeAll ;
22
+ import org .junit .jupiter .api .BeforeEach ;
26
23
import org .junit .jupiter .api .Test ;
27
24
28
25
public class SqlSourceBuilderTest {
29
26
30
27
private static Configuration configuration ;
31
28
private static SqlSourceBuilder sqlSourceBuilder ;
32
- String sqlFromXml = "SELECT * \n FROM user\n WHERE user_id = 1" ;
29
+ String sqlFromXml = "\\ t \\ n \\ n SELECT * \\ n FROM user\\ n \\ t WHERE user_id = 1\\ n \\ t " ;
33
30
34
- @ BeforeAll
35
- static void setUp () throws Exception {
36
- // create an SqlSessionFactory
37
- try (Reader reader = Resources
38
- .getResourceAsReader ("org/apache/ibatis/submitted/empty_row/mybatis-config.xml" )) {
39
- XMLConfigBuilder parser = new XMLConfigBuilder (reader , null , null );
40
- configuration = parser .parse ();
41
- }
31
+ @ BeforeEach
32
+ void setUp () {
33
+ configuration = new Configuration ();
42
34
43
35
sqlSourceBuilder = new SqlSourceBuilder (configuration );
44
36
}
@@ -53,10 +45,13 @@ void testMinifySqlEnabledIsFalse() {
53
45
54
46
@ Test
55
47
void testMinifySqlEnabledIsTrue () {
48
+ String expected = "\\ t\\ n\\ n SELECT * \\ n FROM user\\ n \\ t WHERE user_id = 1\\ n\\ t" ;
49
+
56
50
configuration .setShrinkWhitespacesInSql (true );
57
51
SqlSource sqlSource = sqlSourceBuilder .parse (sqlFromXml , null , null );
58
52
BoundSql boundSql = sqlSource .getBoundSql (null );
59
53
String actual = boundSql .getSql ();
60
- Assertions .assertNotEquals (sqlFromXml , actual );
54
+
55
+ Assertions .assertEquals (expected , actual );
61
56
}
62
57
}
0 commit comments