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 import java.util.Map; 023 024 import org.apache.commons.dbutils.BaseTestCase; 025 import org.apache.commons.dbutils.ResultSetHandler; 026 027 /** 028 * MapListHandlerTest 029 */ 030 public class MapListHandlerTest extends BaseTestCase { 031 032 public void testHandle() throws SQLException { 033 ResultSetHandler h = new MapListHandler(); 034 List results = (List) h.handle(this.rs); 035 036 assertNotNull(results); 037 assertEquals(ROWS, results.size()); 038 039 Iterator iter = results.iterator(); 040 Map row = null; 041 assertTrue(iter.hasNext()); 042 row = (Map) iter.next(); 043 assertEquals(COLS, row.keySet().size()); 044 assertEquals("1", row.get("one")); 045 assertEquals("2", row.get("TWO")); 046 assertEquals("3", row.get("Three")); 047 048 assertTrue(iter.hasNext()); 049 row = (Map) iter.next(); 050 assertEquals(COLS, row.keySet().size()); 051 052 assertEquals("4", row.get("one")); 053 assertEquals("5", row.get("TWO")); 054 assertEquals("6", row.get("Three")); 055 056 assertFalse(iter.hasNext()); 057 } 058 059 public void testEmptyResultSetHandle() throws SQLException { 060 ResultSetHandler h = new MapListHandler(); 061 List results = (List) h.handle(this.emptyResultSet); 062 063 assertNotNull(results); 064 assertTrue(results.isEmpty()); 065 } 066 067 }