File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
src/test/java/org/apache/ibatis/submitted/foreach Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 18
18
import java .io .Reader ;
19
19
import java .sql .Connection ;
20
20
import java .util .ArrayList ;
21
+ import java .util .Arrays ;
21
22
import java .util .List ;
22
23
24
+ import org .apache .ibatis .exceptions .PersistenceException ;
23
25
import org .apache .ibatis .io .Resources ;
24
26
import org .apache .ibatis .jdbc .ScriptRunner ;
25
27
import org .apache .ibatis .session .SqlSession ;
26
28
import org .apache .ibatis .session .SqlSessionFactory ;
27
29
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
28
30
import org .junit .Assert ;
29
31
import org .junit .BeforeClass ;
32
+ import org .junit .Rule ;
30
33
import org .junit .Test ;
34
+ import org .junit .rules .ExpectedException ;
31
35
32
36
public class ForEachTest {
33
37
34
38
private static SqlSessionFactory sqlSessionFactory ;
35
39
40
+ @ Rule
41
+ public ExpectedException ex = ExpectedException .none ();
42
+
36
43
@ BeforeClass
37
44
public static void setUp () throws Exception {
38
45
// create a SqlSessionFactory
@@ -124,4 +131,18 @@ public void nullItemInContext() {
124
131
}
125
132
}
126
133
134
+ @ Test
135
+ public void shouldReportMissingPropertyName () {
136
+ ex .expect (PersistenceException .class );
137
+ ex .expectMessage ("There is no getter for property named 'idd' in 'class org.apache.ibatis.submitted.foreach.User'" );
138
+
139
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
140
+ try {
141
+ Mapper mapper = sqlSession .getMapper (Mapper .class );
142
+ mapper .typoInItemProperty (Arrays .asList (new User ()));
143
+ } finally {
144
+ sqlSession .close ();
145
+ }
146
+ }
147
+
127
148
}
Original file line number Diff line number Diff line change @@ -27,4 +27,5 @@ public interface Mapper {
27
27
28
28
String selectWithNullItemCheck (List <User > users );
29
29
30
+ int typoInItemProperty (List <User > users );
30
31
}
Original file line number Diff line number Diff line change 62
62
</where >
63
63
</select >
64
64
65
+ <insert id =" typoInItemProperty" >
66
+ insert into users (id, name) values
67
+ <foreach item =" item" collection =" list" separator =" ," >
68
+ (#{item.idd}, #{item.name})
69
+ </foreach >
70
+ </insert >
71
+
65
72
</mapper >
You can’t perform that action at this time.
0 commit comments