|
20 | 20 | import static org.mockito.Mockito.doThrow;
|
21 | 21 | import static org.mockito.Mockito.mock;
|
22 | 22 | import static org.mockito.Mockito.when;
|
| 23 | +import static org.mockito.Mockito.verify; |
| 24 | +import static org.mockito.Mockito.times; |
23 | 25 |
|
24 | 26 | import java.sql.PreparedStatement;
|
25 | 27 | import java.sql.SQLException;
|
|
29 | 31 | import java.util.List;
|
30 | 32 |
|
31 | 33 | import org.apache.ibatis.builder.StaticSqlSource;
|
| 34 | +import org.apache.ibatis.domain.blog.Author; |
| 35 | +import org.apache.ibatis.domain.blog.Section; |
32 | 36 | import org.apache.ibatis.mapping.BoundSql;
|
33 | 37 | import org.apache.ibatis.mapping.MappedStatement;
|
34 | 38 | import org.apache.ibatis.mapping.ParameterMapping;
|
@@ -98,4 +102,35 @@ MappedStatement getMappedStatement() {
|
98 | 102 | }).build();
|
99 | 103 | }
|
100 | 104 |
|
| 105 | + @Test |
| 106 | + void testParameterObjectMetaObjectGetValue() { |
| 107 | + Configuration config = new Configuration(); |
| 108 | + TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); |
| 109 | + |
| 110 | + MappedStatement mappedStatement = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).build(); |
| 111 | + |
| 112 | + Author parameterObject = mock(Author.class); |
| 113 | + |
| 114 | + BoundSql boundSql = new BoundSql(config, "some select statement", new ArrayList<ParameterMapping>() { |
| 115 | + { |
| 116 | + add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); |
| 117 | + add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); |
| 118 | + add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); |
| 119 | + add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build()); |
| 120 | + add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build()); |
| 121 | + } |
| 122 | + }, parameterObject); |
| 123 | + |
| 124 | + DefaultParameterHandler defaultParameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql); |
| 125 | + |
| 126 | + PreparedStatement ps = mock(PreparedStatement.class); |
| 127 | + |
| 128 | + defaultParameterHandler.setParameters(ps); |
| 129 | + |
| 130 | + verify(parameterObject, times(1)).getUsername(); |
| 131 | + verify(parameterObject, times(1)).getPassword(); |
| 132 | + verify(parameterObject, times(1)).getEmail(); |
| 133 | + verify(parameterObject, times(1)).getBio(); |
| 134 | + verify(parameterObject, times(1)).getFavouriteSection(); |
| 135 | + } |
101 | 136 | }
|
0 commit comments