001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.dbutils.handlers; 018 019 import java.sql.SQLException; 020 import java.util.Iterator; 021 import java.util.List; 022 023 import org.apache.commons.dbutils.BaseTestCase; 024 import org.apache.commons.dbutils.ResultSetHandler; 025 import org.apache.commons.dbutils.TestBean; 026 027 /** 028 * BeanListHandlerTest 029 */ 030 public class BeanListHandlerTest extends BaseTestCase { 031 032 public void testHandle() throws SQLException { 033 ResultSetHandler h = new BeanListHandler(TestBean.class); 034 List results = (List) h.handle(this.rs); 035 036 assertNotNull(results); 037 assertEquals(ROWS, results.size()); 038 039 Iterator iter = results.iterator(); 040 TestBean row = null; 041 assertTrue(iter.hasNext()); 042 row = (TestBean) iter.next(); 043 assertEquals("1", row.getOne()); 044 assertEquals("2", row.getTwo()); 045 assertEquals("3", row.getThree()); 046 assertEquals("not set", row.getDoNotSet()); 047 048 assertTrue(iter.hasNext()); 049 row = (TestBean) iter.next(); 050 051 assertEquals("4", row.getOne()); 052 assertEquals("5", row.getTwo()); 053 assertEquals("6", row.getThree()); 054 assertEquals("not set", row.getDoNotSet()); 055 056 assertFalse(iter.hasNext()); 057 } 058 059 public void testEmptyResultSetHandle() throws SQLException { 060 ResultSetHandler h = new BeanListHandler(TestBean.class); 061 List results = (List) h.handle(this.emptyResultSet); 062 063 assertNotNull(results); 064 assertTrue(results.isEmpty()); 065 } 066 067 }