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.List; 021 022 import org.apache.commons.dbutils.BaseTestCase; 023 import org.apache.commons.dbutils.ResultSetHandler; 024 025 /** 026 * ColumnListHandlerTest 027 */ 028 public class ColumnListHandlerTest extends BaseTestCase { 029 030 public void testHandle() throws SQLException { 031 ResultSetHandler h = new ColumnListHandler(); 032 033 List results = (List) h.handle(this.rs); 034 035 assertNotNull(results); 036 assertEquals(ROWS, results.size()); 037 038 assertEquals("1", results.get(0)); 039 assertEquals("4", results.get(1)); 040 } 041 042 public void testColumnIndexHandle() throws SQLException { 043 ResultSetHandler h = new ColumnListHandler(2); 044 List results = (List) h.handle(this.rs); 045 046 assertNotNull(results); 047 assertEquals(ROWS, results.size()); 048 049 assertEquals("2", results.get(0)); 050 assertEquals("5", results.get(1)); 051 } 052 053 public void testColumnNameHandle() throws SQLException { 054 ResultSetHandler h = new ColumnListHandler("Three"); 055 List results = (List) h.handle(this.rs); 056 057 assertNotNull(results); 058 assertEquals(ROWS, results.size()); 059 060 assertEquals("3", results.get(0)); 061 assertEquals("6", results.get(1)); 062 } 063 064 public void testEmptyResultSetHandle() throws SQLException { 065 ResultSetHandler h = new ColumnListHandler(); 066 List results = (List) h.handle(this.emptyResultSet); 067 068 assertNotNull(results); 069 assertTrue(results.isEmpty()); 070 } 071 072 }