KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > test > jdbcstub > ResultSetImplTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.test.jdbcstub;
21
22 import java.sql.ResultSet JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.List JavaDoc;
27 import junit.framework.TestCase;
28
29 /**
30  *
31  * @author Andrei Badea
32  */

33 public class ResultSetImplTest extends TestCase {
34     
35     public ResultSetImplTest(String JavaDoc name) {
36         super(name);
37     }
38     
39     public void testEmpty() throws Exception JavaDoc {
40         ResultSet JavaDoc rs = JDBCStubUtil.createResultSet(Collections.EMPTY_LIST);
41         assertFalse(rs.next());
42     }
43     
44     public void testNextAndGetObject() throws Exception JavaDoc {
45         
46         List JavaDoc col1 = Arrays.asList(new String JavaDoc[] { "FOO", "foo1", "foo2"});
47         List JavaDoc col2 = Arrays.asList(new String JavaDoc[] { "BAR", "bar1", "bar2"});
48         
49         ResultSet JavaDoc rs = JDBCStubUtil.createResultSet(Arrays.asList(new List JavaDoc[] { col1, col2 }));
50         
51         try {
52             rs.getObject("foo1");
53             fail("SQLException thrown if next() not previously called");
54         } catch (SQLException JavaDoc e) { }
55         
56         assertTrue(rs.next());
57         
58         assertEquals("foo1", rs.getObject("FOO"));
59         assertEquals("bar1", rs.getObject("BAR"));
60         
61         try {
62             rs.getObject("inexistent");
63             fail("SQLException thrown if unkown column name");
64         } catch (SQLException JavaDoc e) { }
65         
66         assertTrue(rs.next());
67         assertEquals("bar2", rs.getObject("BAR"));
68         assertEquals("foo2", rs.getObject("FOO"));
69         
70         assertFalse(rs.next());
71         assertFalse(rs.next());
72     }
73 }
74
Popular Tags