20
20
import static org .junit .jupiter .api .Assertions .assertNull ;
21
21
import static org .junit .jupiter .api .Assertions .assertThrows ;
22
22
import static org .junit .jupiter .api .Assertions .assertTrue ;
23
+
23
24
import java .io .Reader ;
25
+ import java .text .MessageFormat ;
24
26
import java .util .List ;
27
+
25
28
import org .apache .ibatis .BaseDataTest ;
26
29
import org .apache .ibatis .exceptions .PersistenceException ;
27
30
import org .apache .ibatis .io .Resources ;
@@ -39,14 +42,14 @@ class ColumnOrderBasedConstructorAutomappingTest {
39
42
static void setUp () throws Exception {
40
43
// create an SqlSessionFactory
41
44
try (Reader reader = Resources .getResourceAsReader (
42
- "org/apache/ibatis/submitted/column_order_based_constructor_automapping/mybatis-config.xml" )) {
45
+ "org/apache/ibatis/submitted/column_order_based_constructor_automapping/mybatis-config.xml" )) {
43
46
sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
44
47
sqlSessionFactory .getConfiguration ().setArgNameBasedConstructorAutoMapping (false );
45
48
}
46
49
47
50
// populate in-memory database
48
51
BaseDataTest .runScript (sqlSessionFactory .getConfiguration ().getEnvironment ().getDataSource (),
49
- "org/apache/ibatis/submitted/column_order_based_constructor_automapping/CreateDB.sql" );
52
+ "org/apache/ibatis/submitted/column_order_based_constructor_automapping/CreateDB.sql" );
50
53
}
51
54
52
55
@ Test
@@ -120,10 +123,14 @@ void shouldNotHandleConstructorGreaterThanResultSet() {
120
123
try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
121
124
Mapper mapper = sqlSession .getMapper (Mapper .class );
122
125
123
- PersistenceException persistenceException = assertThrows (PersistenceException .class , mapper ::finaAllByConstructorGreaterThanResultSet );
126
+ PersistenceException persistenceException = assertThrows (PersistenceException .class ,
127
+ mapper ::finaAllByConstructorGreaterThanResultSet );
124
128
assertNotNull (persistenceException );
125
- assertNotNull (persistenceException .getMessage ());
126
- assertTrue (persistenceException .getMessage ().contains ("Column order based constructor auto-mapping of" ));
129
+ String message = persistenceException .getMessage ();
130
+ assertNotNull (message );
131
+ assertTrue (message .contains (MessageFormat .format (
132
+ "Constructor auto-mapping of ''{0}'' failed. The constructor takes ''{1}'' arguments, but there are only ''{2}'' columns in the result set." ,
133
+ UserConstructorGreaterThanResultSet .class .getConstructors ()[0 ], 4 , 3 )));
127
134
}
128
135
}
129
136
}
0 commit comments