|
18 | 18 | import static org.hamcrest.core.Is.is; |
19 | 19 | import static org.junit.Assert.assertEquals; |
20 | 20 | import static org.junit.Assert.assertNotNull; |
| 21 | +import static org.junit.Assert.assertNull; |
21 | 22 |
|
22 | 23 | import java.io.Reader; |
23 | 24 | import java.sql.Connection; |
|
36 | 37 | import org.apache.ibatis.session.SqlSessionFactory; |
37 | 38 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; |
38 | 39 | import org.junit.BeforeClass; |
39 | | -import org.junit.Ignore; |
40 | 40 | import org.junit.Rule; |
41 | 41 | import org.junit.Test; |
42 | 42 | import org.junit.rules.ExpectedException; |
@@ -86,15 +86,21 @@ public void shouldGetTwoUsers() { |
86 | 86 | } |
87 | 87 | } |
88 | 88 |
|
89 | | - // Test for simple value |
| 89 | + // Test for simple value without @Param |
90 | 90 | @Test |
91 | 91 | public void shouldGetOneUser() { |
92 | 92 | SqlSession sqlSession = sqlSessionFactory.openSession(); |
93 | 93 | try { |
94 | 94 | Mapper mapper = sqlSession.getMapper(Mapper.class); |
95 | | - User user = mapper.getUser(4); |
96 | | - assertNotNull(user); |
97 | | - assertEquals("User4", user.getName()); |
| 95 | + { |
| 96 | + User user = mapper.getUser(4); |
| 97 | + assertNotNull(user); |
| 98 | + assertEquals("User4", user.getName()); |
| 99 | + } |
| 100 | + { |
| 101 | + User user = mapper.getUser(null); |
| 102 | + assertNull(user); |
| 103 | + } |
98 | 104 | } finally { |
99 | 105 | sqlSession.close(); |
100 | 106 | } |
@@ -241,18 +247,28 @@ public void shouldGetUsersByNameWithParamNameUsingMap() { |
241 | 247 | } |
242 | 248 | } |
243 | 249 |
|
244 | | - // Test for map with @Param |
245 | | - @Ignore("TODO failing case") |
| 250 | + // Test for simple value with @Param |
| 251 | + @Test |
246 | 252 | public void shouldGetUsersByNameWithParamName() { |
247 | 253 | SqlSession sqlSession = sqlSessionFactory.openSession(); |
248 | 254 | try { |
249 | 255 | Mapper mapper = sqlSession.getMapper(Mapper.class); |
250 | | - List<User> users = mapper.getUsersByNameWithParamName("User"); |
251 | | - assertEquals(4, users.size()); |
252 | | - assertEquals("User4", users.get(0).getName()); |
253 | | - assertEquals("User3", users.get(1).getName()); |
254 | | - assertEquals("User2", users.get(2).getName()); |
255 | | - assertEquals("User1", users.get(3).getName()); |
| 256 | + { |
| 257 | + List<User> users = mapper.getUsersByNameWithParamName("User"); |
| 258 | + assertEquals(4, users.size()); |
| 259 | + assertEquals("User4", users.get(0).getName()); |
| 260 | + assertEquals("User3", users.get(1).getName()); |
| 261 | + assertEquals("User2", users.get(2).getName()); |
| 262 | + assertEquals("User1", users.get(3).getName()); |
| 263 | + } |
| 264 | + { |
| 265 | + List<User> users = mapper.getUsersByNameWithParamName(null); |
| 266 | + assertEquals(4, users.size()); |
| 267 | + assertEquals("User4", users.get(0).getName()); |
| 268 | + assertEquals("User3", users.get(1).getName()); |
| 269 | + assertEquals("User2", users.get(2).getName()); |
| 270 | + assertEquals("User1", users.get(3).getName()); |
| 271 | + } |
256 | 272 | } finally { |
257 | 273 | sqlSession.close(); |
258 | 274 | } |
@@ -282,14 +298,23 @@ public void notSqlProvider() throws NoSuchMethodException { |
282 | 298 | } |
283 | 299 |
|
284 | 300 | @Test |
285 | | - public void notSupportParameterObject() throws NoSuchMethodException { |
| 301 | + public void notSupportParameterObjectOnMultipleArguments() throws NoSuchMethodException { |
286 | 302 | expectedException.expect(BuilderException.class); |
287 | 303 | expectedException.expectMessage(is("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameQuery). Cannot invoke a method that holds multiple arguments using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.")); |
288 | 304 | new ProviderSqlSource(new Configuration(), |
289 | 305 | Mapper.class.getMethod("getUsersByName", String.class, String.class).getAnnotation(SelectProvider.class)) |
290 | 306 | .getBoundSql(new Object()); |
291 | 307 | } |
292 | 308 |
|
| 309 | + @Test |
| 310 | + public void notSupportParameterObjectOnNamedArgument() throws NoSuchMethodException { |
| 311 | + expectedException.expect(BuilderException.class); |
| 312 | + expectedException.expectMessage(is("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameWithParamNameQuery). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.")); |
| 313 | + new ProviderSqlSource(new Configuration(), |
| 314 | + Mapper.class.getMethod("getUsersByNameWithParamName", String.class).getAnnotation(SelectProvider.class)) |
| 315 | + .getBoundSql(new Object()); |
| 316 | + } |
| 317 | + |
293 | 318 | @Test |
294 | 319 | public void invokeError() throws NoSuchMethodException { |
295 | 320 | expectedException.expect(BuilderException.class); |
|
0 commit comments