1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils;
18
19 import java.sql.SQLException;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.LinkedList;
23 import java.util.Map;
24
25 import org.junit.Test;
26
27 public final class BaseResultSetHandlerTest extends BaseTestCase {
28
29 private static final class ToMapCollectionHandler
30 extends BaseResultSetHandler<Collection<Map<String, Object>>> {
31
32 @Override
33 protected Collection<Map<String, Object>> handle() throws SQLException {
34 final Collection<Map<String, Object>> result = new LinkedList<>();
35
36 while (next()) {
37 final Map<String, Object> current = new HashMap<>();
38
39 for (int i = 1; i <= getMetaData().getColumnCount(); i++) {
40 current.put(getMetaData().getColumnName(i), getObject(i));
41 }
42
43 result.add(current);
44 }
45
46 return result;
47 }
48
49 }
50
51 @Test
52 public void handleWithoutExplicitResultSetInvocation() throws Exception {
53 final Collection<Map<String, Object>> result = new ToMapCollectionHandler().handle(createMockResultSet());
54
55 assertFalse(result.isEmpty());
56
57 for (final Map<String, Object> current : result) {
58 assertTrue(current.containsKey("one"));
59 assertTrue(current.containsKey("two"));
60 assertTrue(current.containsKey("three"));
61 assertTrue(current.containsKey("notInBean"));
62 assertTrue(current.containsKey("intTest"));
63 assertTrue(current.containsKey("integerTest"));
64 assertTrue(current.containsKey("nullObjectTest"));
65 assertTrue(current.containsKey("nullPrimitiveTest"));
66 assertTrue(current.containsKey("notDate"));
67 assertTrue(current.containsKey("columnProcessorDoubleTest"));
68 }
69 }
70
71 }