@@ -46,13 +46,22 @@ public abstract class AbstractRowMapperTests extends TestCase {
46
46
47
47
protected MockControl conControl ;
48
48
protected Connection con ;
49
+ protected MockControl conControl2 ;
50
+ protected Connection con2 ;
49
51
protected MockControl rsmdControl ;
50
52
protected ResultSetMetaData rsmd ;
51
53
protected MockControl rsControl ;
52
54
protected ResultSet rs ;
53
55
protected MockControl stmtControl ;
54
56
protected Statement stmt ;
55
57
protected JdbcTemplate jdbcTemplate ;
58
+ protected MockControl rsmdControl2 ;
59
+ protected ResultSetMetaData rsmd2 ;
60
+ protected MockControl rsControl2 ;
61
+ protected ResultSet rs2 ;
62
+ protected MockControl stmtControl2 ;
63
+ protected Statement stmt2 ;
64
+ protected JdbcTemplate jdbcTemplate2 ;
56
65
57
66
protected void setUp () throws SQLException {
58
67
conControl = MockControl .createControl (Connection .class );
@@ -110,13 +119,75 @@ protected void setUp() throws SQLException {
110
119
stmt .close ();
111
120
stmtControl .setVoidCallable (1 );
112
121
122
+ conControl2 = MockControl .createControl (Connection .class );
123
+ con2 = (Connection ) conControl2 .getMock ();
124
+ con2 .isClosed ();
125
+ conControl2 .setDefaultReturnValue (false );
126
+
127
+ rsmdControl2 = MockControl .createControl (ResultSetMetaData .class );
128
+ rsmd2 = (ResultSetMetaData )rsmdControl2 .getMock ();
129
+ rsmd2 .getColumnCount ();
130
+ rsmdControl2 .setReturnValue (4 , 2 );
131
+ rsmd2 .getColumnLabel (1 );
132
+ rsmdControl2 .setReturnValue ("name" , 2 );
133
+ rsmd2 .getColumnLabel (2 );
134
+ rsmdControl2 .setReturnValue ("age" , 2 );
135
+ rsmd2 .getColumnLabel (3 );
136
+ rsmdControl2 .setReturnValue ("birth_date" , 1 );
137
+ rsmd2 .getColumnLabel (4 );
138
+ rsmdControl2 .setReturnValue ("balance" , 1 );
139
+ rsmdControl2 .replay ();
140
+
141
+ rsControl2 = MockControl .createControl (ResultSet .class );
142
+ rs2 = (ResultSet ) rsControl2 .getMock ();
143
+ rs2 .getMetaData ();
144
+ rsControl2 .setReturnValue (rsmd2 , 2 );
145
+ rs2 .next ();
146
+ rsControl2 .setReturnValue (true , 2 );
147
+ rs2 .getString (1 );
148
+ rsControl2 .setReturnValue ("Bubba" , 2 );
149
+ rs2 .wasNull ();
150
+ rsControl2 .setReturnValue (true , 2 );
151
+ rs2 .getLong (2 );
152
+ rsControl2 .setReturnValue (0 , 2 );
153
+ rs2 .getTimestamp (3 );
154
+ rsControl2 .setReturnValue (new Timestamp (1221222L ), 1 );
155
+ rs2 .getBigDecimal (4 );
156
+ rsControl2 .setReturnValue (new BigDecimal ("1234.56" ), 1 );
157
+ rs2 .next ();
158
+ rsControl2 .setReturnValue (false , 1 );
159
+ rs2 .close ();
160
+ rsControl2 .setVoidCallable (2 );
161
+ rsControl2 .replay ();
162
+
163
+ stmtControl2 = MockControl .createControl (Statement .class );
164
+ stmt2 = (Statement ) stmtControl2 .getMock ();
165
+
166
+ con2 .createStatement ();
167
+ conControl2 .setReturnValue (stmt2 , 2 );
168
+ stmt2 .executeQuery ("select name, null as age, birth_date, balance from people" );
169
+ stmtControl2 .setReturnValue (rs2 , 2 );
170
+ if (debugEnabled ) {
171
+ stmt2 .getWarnings ();
172
+ stmtControl2 .setReturnValue (null , 2 );
173
+ }
174
+ stmt2 .close ();
175
+ stmtControl2 .setVoidCallable (2 );
176
+
113
177
conControl .replay ();
114
178
stmtControl .replay ();
179
+ conControl2 .replay ();
180
+ stmtControl2 .replay ();
115
181
116
182
jdbcTemplate = new JdbcTemplate ();
117
183
jdbcTemplate .setDataSource (new SingleConnectionDataSource (con , false ));
118
184
jdbcTemplate .setExceptionTranslator (new SQLStateSQLExceptionTranslator ());
119
185
jdbcTemplate .afterPropertiesSet ();
186
+
187
+ jdbcTemplate2 = new JdbcTemplate ();
188
+ jdbcTemplate2 .setDataSource (new SingleConnectionDataSource (con2 , false ));
189
+ jdbcTemplate2 .setExceptionTranslator (new SQLStateSQLExceptionTranslator ());
190
+ jdbcTemplate2 .afterPropertiesSet ();
120
191
}
121
192
122
193
protected void verifyPerson (Person bean ) {
@@ -127,6 +198,17 @@ protected void verifyPerson(Person bean) {
127
198
assertEquals (new BigDecimal ("1234.56" ), bean .getBalance ());
128
199
}
129
200
201
+ protected void verifyPersonWithZeroAge (Person bean ) {
202
+ conControl2 .verify ();
203
+ rsControl2 .verify ();
204
+ rsmdControl2 .verify ();
205
+ stmtControl2 .verify ();
206
+ assertEquals ("Bubba" , bean .getName ());
207
+ assertEquals (0L , bean .getAge ());
208
+ assertEquals (new java .util .Date (1221222L ), bean .getBirth_date ());
209
+ assertEquals (new BigDecimal ("1234.56" ), bean .getBalance ());
210
+ }
211
+
130
212
protected void verifyConcretePerson (ConcretePerson bean ) {
131
213
verify ();
132
214
assertEquals ("Bubba" , bean .getName ());
0 commit comments