1 61 62 package org.apache.commons.dbutils; 63 64 import java.sql.SQLException ; 65 import java.util.List ; 66 import java.util.Map ; 67 68 73 public class BasicRowProcessorTest extends BaseTestCase { 74 75 private static final RowProcessor processor = BasicRowProcessor.instance(); 76 77 81 public BasicRowProcessorTest(String name) { 82 super(name); 83 } 84 85 public void testToArray() throws SQLException { 86 87 int rowCount = 0; 88 Object [] a = null; 89 while (this.rs.next()) { 90 a = processor.toArray(this.rs); 91 assertEquals(COLS, a.length); 92 rowCount++; 93 } 94 95 assertEquals(ROWS, rowCount); 96 assertEquals("4", a[0]); 97 assertEquals("5", a[1]); 98 assertEquals("6", a[2]); 99 } 100 101 public void testToBean() throws SQLException { 102 103 int rowCount = 0; 104 TestBean b = null; 105 while (this.rs.next()) { 106 b = (TestBean) processor.toBean(this.rs, TestBean.class); 107 assertNotNull(b); 108 rowCount++; 109 } 110 111 assertEquals(ROWS, rowCount); 112 assertEquals("4", b.getOne()); 113 assertEquals("5", b.getTwo()); 114 assertEquals("6", b.getThree()); 115 assertEquals("not set", b.getDoNotSet()); 116 assertEquals(3, b.getIntTest()); 117 assertEquals(new Integer (4), b.getIntegerTest()); 118 assertEquals(null, b.getNullObjectTest()); 119 assertEquals(0, b.getNullPrimitiveTest()); 120 assertEquals("not a date", b.getNotDate()); 121 } 122 123 public void testToBeanList() throws SQLException { 124 125 List list = processor.toBeanList(this.rs, TestBean.class); 126 assertNotNull(list); 127 assertEquals(ROWS, list.size()); 128 129 TestBean b = (TestBean) list.get(1); 130 131 assertEquals("4", b.getOne()); 132 assertEquals("5", b.getTwo()); 133 assertEquals("6", b.getThree()); 134 assertEquals("not set", b.getDoNotSet()); 135 assertEquals(3, b.getIntTest()); 136 assertEquals(new Integer (4), b.getIntegerTest()); 137 assertEquals(null, b.getNullObjectTest()); 138 assertEquals(0, b.getNullPrimitiveTest()); 139 assertEquals("not a date", b.getNotDate()); 140 } 141 142 public void testToMap() throws SQLException { 143 144 int rowCount = 0; 145 Map m = null; 146 while (this.rs.next()) { 147 m = processor.toMap(this.rs); 148 assertNotNull(m); 149 assertEquals(COLS, m.keySet().size()); 150 rowCount++; 151 } 152 153 assertEquals(ROWS, rowCount); 154 assertEquals("4", m.get("One")); assertEquals("5", m.get("two")); 156 assertEquals("6", m.get("THREE")); 157 } 158 159 } 160 | Popular Tags |