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    
026    /**
027     * ArrayListHandlerTest
028     */
029    public class ArrayListHandlerTest extends BaseTestCase {
030    
031            public void testHandle() throws SQLException {
032                    ResultSetHandler h = new ArrayListHandler();
033                    List results = (List) h.handle(this.rs);
034    
035                    assertNotNull(results);
036                    assertEquals(ROWS, results.size());
037    
038                    Iterator iter = results.iterator();
039                Object[] row = null;
040                assertTrue(iter.hasNext());
041                row = (Object[]) iter.next();
042                assertEquals(COLS, row.length);
043                assertEquals("1", row[0]);
044                assertEquals("2", row[1]);
045                assertEquals("3", row[2]);
046                    
047                assertTrue(iter.hasNext());
048                row = (Object[]) iter.next();
049                assertEquals(COLS, row.length);
050    
051                assertEquals("4", row[0]);
052                assertEquals("5", row[1]);
053                assertEquals("6", row[2]);
054                    
055                assertFalse(iter.hasNext());
056            }
057    
058            public void testEmptyResultSetHandle() throws SQLException {
059                    ResultSetHandler h = new ArrayListHandler();
060                    List results = (List) h.handle(this.emptyResultSet);
061    
062                    assertNotNull(results);
063                    assertTrue(results.isEmpty());
064            }
065    
066    }